Skip to content

Commit

Permalink
feat: Add gas limit adjustment flag (#105)
Browse files Browse the repository at this point in the history
* added gaslimit adjustment flag

* fix tests and added changelog

* Update CHANGELOG.md

Co-authored-by: Aleksandr Bezobchuk <[email protected]>
  • Loading branch information
facundomedica and alexanderbez authored Dec 22, 2021
1 parent 8f12d6e commit e24a6a4
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

- [#104] Changed timeout for broadcasting TXs to Umee to 60s to match that of the official Gravity Bridge.
- [#105] Added a gas limit adjustment flag for Ethereum transactions.

## [v0.1.0](https://github.com/umee-network/peggo/releases/tag/v0.1.0) - 2021-12-18

### Features

- Initial release!!!
2 changes: 2 additions & 0 deletions cmd/peggo/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
flagEthUseLedger = "eth-use-ledger"
flagEthRPC = "eth-rpc"
flagEthGasAdjustment = "eth-gas-price-adjustment"
flagEthGasLimitAdjustment = "eth-gas-limit-adjustment"
flagEthAlchemyWS = "eth-alchemy-ws"
flagRelayValsets = "relay-valsets"
flagRelayBatches = "relay-batches"
Expand Down Expand Up @@ -89,6 +90,7 @@ func ethereumOptsFlagSet() *pflag.FlagSet {

fs.String(flagEthRPC, "https://localhost:8545", "Specify the RPC address of an Ethereum node")
fs.Float64(flagEthGasAdjustment, float64(1.3), "Specify a gas price adjustment for Ethereum transactions")
fs.Float64(flagEthGasLimitAdjustment, float64(1.2), "Specify a gas limit adjustment for Ethereum transactions")

return fs
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/peggo/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ func getOrchestratorCmd() *cobra.Command {
ethProvider := provider.NewEVMProvider(ethRPC)

ethGasPriceAdjustment := konfig.Float64(flagEthGasAdjustment)
ethGasLimitAdjustment := konfig.Float64(flagEthGasLimitAdjustment)
ethCommitter, err := committer.NewEthCommitter(
logger,
ethKeyFromAddress,
ethGasPriceAdjustment,
ethGasLimitAdjustment,
signerFn,
ethProvider,
)
Expand Down
5 changes: 5 additions & 0 deletions orchestrator/eth_event_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func TestCheckForEvents(t *testing.T) {
logger,
fromAddress,
ethGasPriceAdjustment,
1.0,
nil,
ethProvider,
)
Expand Down Expand Up @@ -208,6 +209,7 @@ func TestCheckForEvents(t *testing.T) {
logger,
fromAddress,
1.0,
1.0,
nil,
ethProvider,
)
Expand Down Expand Up @@ -313,6 +315,7 @@ func TestCheckForEvents(t *testing.T) {
logger,
fromAddress,
ethGasPriceAdjustment,
1.0,
nil,
ethProvider,
)
Expand Down Expand Up @@ -431,6 +434,7 @@ func TestCheckForEvents(t *testing.T) {
logger,
fromAddress,
ethGasPriceAdjustment,
1.0,
nil,
ethProvider,
)
Expand Down Expand Up @@ -563,6 +567,7 @@ func TestCheckForEvents(t *testing.T) {
logger,
fromAddress,
ethGasPriceAdjustment,
1.0,
nil,
ethProvider,
)
Expand Down
6 changes: 6 additions & 0 deletions orchestrator/ethereum/committer/eth_committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func NewEthCommitter(
logger zerolog.Logger,
fromAddress common.Address,
ethGasPriceAdjustment float64,
ethGasLimitAdjustment float64,
fromSigner bind.SignerFn,
evmProvider provider.EVMProviderWithRet,
committerOpts ...EVMCommitterOption,
Expand All @@ -29,6 +30,7 @@ func NewEthCommitter(
logger: logger.With().Str("module", "ethCommiter").Logger(),
committerOpts: defaultOptions(),
ethGasPriceAdjustment: ethGasPriceAdjustment,
ethGasLimitAdjustment: ethGasLimitAdjustment,
fromAddress: fromAddress,
fromSigner: fromSigner,
evmProvider: evmProvider,
Expand All @@ -55,6 +57,7 @@ type ethCommitter struct {
fromSigner bind.SignerFn

ethGasPriceAdjustment float64
ethGasLimitAdjustment float64
evmProvider provider.EVMProviderWithRet
nonceCache util.NonceCache
}
Expand Down Expand Up @@ -100,6 +103,9 @@ func (e *ethCommitter) EstimateGas(

gasCost, err = e.evmProvider.EstimateGas(ctx, msg)

// Estimated gas cost may not be accurate, so we multiply the result by the gas limit adjustment factor.
gasCost = uint64(float64(gasCost) * e.ethGasLimitAdjustment)

return gasCost, gasPrice, err
}

Expand Down
6 changes: 6 additions & 0 deletions orchestrator/ethereum/peggy/peggy_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestGetTxBatchNonce(t *testing.T) {
logger,
common.Address{},
1.0,
1.0,
nil,
mockEvmProvider,
)
Expand Down Expand Up @@ -86,6 +87,7 @@ func TestGetValsetNonce(t *testing.T) {
logger,
common.Address{},
1.0,
1.0,
nil,
mockEvmProvider,
)
Expand Down Expand Up @@ -123,6 +125,7 @@ func TestGetGetPeggyID(t *testing.T) {
logger,
common.Address{},
1.0,
1.0,
nil,
mockEvmProvider,
)
Expand Down Expand Up @@ -167,6 +170,7 @@ func TestGetERC20Symbol(t *testing.T) {
logger,
common.Address{},
1.0,
1.0,
nil,
mockEvmProvider,
)
Expand Down Expand Up @@ -210,6 +214,7 @@ func TestGetERC20Decimals(t *testing.T) {
logger,
common.Address{},
1.0,
1.0,
nil,
mockEvmProvider,
)
Expand All @@ -235,6 +240,7 @@ func TestAddress(t *testing.T) {
logger,
common.Address{},
1.0,
1.0,
nil,
mockEvmProvider,
)
Expand Down
1 change: 1 addition & 0 deletions orchestrator/ethereum/peggy/pending_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestIsPendingTxInput(t *testing.T) {
logger,
common.Address{},
1.0,
1.0,
nil,
mockEvmProvider,
)
Expand Down
1 change: 1 addition & 0 deletions orchestrator/ethereum/peggy/submit_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestEncodeTransactionBatch(t *testing.T) {
logger,
common.Address{},
1.0,
1.0,
nil,
mockEvmProvider,
)
Expand Down
1 change: 1 addition & 0 deletions orchestrator/ethereum/peggy/valset_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestEncodeValsetUpdate(t *testing.T) {
logger,
common.Address{},
1.0,
1.0,
nil,
mockEvmProvider,
)
Expand Down
1 change: 1 addition & 0 deletions orchestrator/oracle_resync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestGetLastCheckedBlock(t *testing.T) {
logger,
fromAddress,
ethGasPriceAdjustment,
1.0,
nil,
ethProvider,
)
Expand Down
1 change: 1 addition & 0 deletions orchestrator/relayer/batch_relaying_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func TestIsBatchProfitable(t *testing.T) {
logger,
fromAddress,
1.0,
1.0,
nil,
ethProvider,
)
Expand Down

0 comments on commit e24a6a4

Please sign in to comment.