From b50c03b23f5e0499666189b1799b836ee3ffc45b Mon Sep 17 00:00:00 2001 From: adirola Date: Fri, 26 May 2023 05:34:05 +0400 Subject: [PATCH 1/7] modified txRelayer to fetch gasprice from current eth client instead of hardcoded one --- txrelayer/txrelayer.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/txrelayer/txrelayer.go b/txrelayer/txrelayer.go index 95e0671da0..1f51705aaf 100644 --- a/txrelayer/txrelayer.go +++ b/txrelayer/txrelayer.go @@ -102,6 +102,11 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo. txn.Nonce = nonce + gasPrice, err := t.Client().Eth().GasPrice() + if err != nil { + return ethgo.ZeroHash, err + } + if txn.GasPrice == 0 { txn.GasPrice = DefaultGasPrice } From 856662dc66965453327ce96ea7b91b455591fbcb Mon Sep 17 00:00:00 2001 From: adirola Date: Fri, 26 May 2023 05:55:09 +0400 Subject: [PATCH 2/7] fixed typo --- txrelayer/txrelayer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/txrelayer/txrelayer.go b/txrelayer/txrelayer.go index 1f51705aaf..2599fdccc1 100644 --- a/txrelayer/txrelayer.go +++ b/txrelayer/txrelayer.go @@ -108,7 +108,7 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo. } if txn.GasPrice == 0 { - txn.GasPrice = DefaultGasPrice + txn.GasPrice = gasPrice } if txn.Gas == 0 { From ab989a70ef58332f6baa7f40d6b8ff21e50803fd Mon Sep 17 00:00:00 2001 From: adirola Date: Fri, 26 May 2023 14:41:32 +0400 Subject: [PATCH 3/7] fetch gas price only if default is 0 --- txrelayer/txrelayer.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/txrelayer/txrelayer.go b/txrelayer/txrelayer.go index 2599fdccc1..ad678e624d 100644 --- a/txrelayer/txrelayer.go +++ b/txrelayer/txrelayer.go @@ -102,12 +102,11 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo. txn.Nonce = nonce - gasPrice, err := t.Client().Eth().GasPrice() - if err != nil { - return ethgo.ZeroHash, err - } - if txn.GasPrice == 0 { + gasPrice, err := t.Client().Eth().GasPrice() + if err != nil { + return ethgo.ZeroHash, err + } txn.GasPrice = gasPrice } From 4bae144bb0219e5cb3573eea2189c132d9e22923 Mon Sep 17 00:00:00 2001 From: adirola Date: Fri, 26 May 2023 14:43:00 +0400 Subject: [PATCH 4/7] fixed indentation --- txrelayer/txrelayer.go | 1 + 1 file changed, 1 insertion(+) diff --git a/txrelayer/txrelayer.go b/txrelayer/txrelayer.go index ad678e624d..73bb9d5335 100644 --- a/txrelayer/txrelayer.go +++ b/txrelayer/txrelayer.go @@ -107,6 +107,7 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo. if err != nil { return ethgo.ZeroHash, err } + txn.GasPrice = gasPrice } From 91bd50bc435669e351c70b65da8c9ce5fc44d98f Mon Sep 17 00:00:00 2001 From: adirola Date: Fri, 26 May 2023 15:28:51 +0000 Subject: [PATCH 5/7] \Fixed linting issue in txrelayer.go --- txrelayer/txrelayer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/txrelayer/txrelayer.go b/txrelayer/txrelayer.go index 73bb9d5335..619da0448d 100644 --- a/txrelayer/txrelayer.go +++ b/txrelayer/txrelayer.go @@ -107,7 +107,7 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo. if err != nil { return ethgo.ZeroHash, err } - + txn.GasPrice = gasPrice } From d3bdac27cb1114d4f3ecefca24fea4933ba46472 Mon Sep 17 00:00:00 2001 From: dusan-maksimovic Date: Tue, 6 Jun 2023 16:10:43 +0200 Subject: [PATCH 6/7] Don't set gas price explicitly when using tx relayer --- command/rootchain/staking/stake.go | 12 +++--------- command/rootchain/supernet/supernet.go | 19 ++++++------------- .../whitelist/whitelist_validators.go | 12 +++--------- command/rootchain/withdraw/withdraw.go | 12 +++--------- command/sidechain/helper.go | 2 -- command/sidechain/rewards/rewards.go | 7 +++---- command/sidechain/unstaking/unstake.go | 7 +++---- command/sidechain/withdraw/withdraw.go | 7 +++---- .../statesyncrelayer/state_sync_relayer.go | 9 ++++----- e2e-polybft/e2e/jsonrpc_test.go | 14 ++++++-------- e2e-polybft/e2e/migration_test.go | 16 +++++++--------- e2e-polybft/framework/test-cluster.go | 5 ++++- e2e/framework/testserver.go | 13 ++++++------- e2e/jsonrpc_test.go | 1 - 14 files changed, 51 insertions(+), 85 deletions(-) diff --git a/command/rootchain/staking/stake.go b/command/rootchain/staking/stake.go index c5f6b35197..8a6a6753d4 100644 --- a/command/rootchain/staking/stake.go +++ b/command/rootchain/staking/stake.go @@ -102,11 +102,6 @@ func runCommand(cmd *cobra.Command, _ []string) error { return err } - gasPrice, err := txRelayer.Client().Eth().GasPrice() - if err != nil { - return err - } - approveTxn, err := rootHelper.CreateApproveERC20Txn(params.amountValue, types.StringToAddress(params.stakeManagerAddr), types.StringToAddress(params.stakeTokenAddr)) if err != nil { @@ -134,10 +129,9 @@ func runCommand(cmd *cobra.Command, _ []string) error { stakeManagerAddr := ethgo.Address(types.StringToAddress(params.stakeManagerAddr)) txn := ðgo.Transaction{ - From: validatorAccount.Ecdsa.Address(), - Input: encoded, - To: &stakeManagerAddr, - GasPrice: gasPrice, + From: validatorAccount.Ecdsa.Address(), + Input: encoded, + To: &stakeManagerAddr, } receipt, err = txRelayer.SendTransaction(txn, validatorAccount.Ecdsa) diff --git a/command/rootchain/supernet/supernet.go b/command/rootchain/supernet/supernet.go index 9d37b32c2c..aaaa33af7f 100644 --- a/command/rootchain/supernet/supernet.go +++ b/command/rootchain/supernet/supernet.go @@ -117,11 +117,6 @@ func runCommand(cmd *cobra.Command, _ []string) error { return fmt.Errorf("enlist validator failed: %w", err) } - gasPrice, err := txRelayer.Client().Eth().GasPrice() - if err != nil { - return err - } - supernetAddr := ethgo.Address(types.StringToAddress(params.supernetManagerAddress)) if params.finalizeGenesisSet { @@ -131,10 +126,9 @@ func runCommand(cmd *cobra.Command, _ []string) error { } txn := ðgo.Transaction{ - From: ownerKey.Address(), - Input: encoded, - To: &supernetAddr, - GasPrice: gasPrice, + From: ownerKey.Address(), + Input: encoded, + To: &supernetAddr, } if _, err = txRelayer.Call(ownerKey.Address(), supernetAddr, encoded); err == nil { @@ -185,10 +179,9 @@ func runCommand(cmd *cobra.Command, _ []string) error { } txn := ðgo.Transaction{ - From: ownerKey.Address(), - Input: encoded, - To: &supernetAddr, - GasPrice: gasPrice, + From: ownerKey.Address(), + Input: encoded, + To: &supernetAddr, } receipt, err := txRelayer.SendTransaction(txn, ownerKey) diff --git a/command/rootchain/whitelist/whitelist_validators.go b/command/rootchain/whitelist/whitelist_validators.go index 72a02c4d12..6b6fbc1638 100644 --- a/command/rootchain/whitelist/whitelist_validators.go +++ b/command/rootchain/whitelist/whitelist_validators.go @@ -94,11 +94,6 @@ func runCommand(cmd *cobra.Command, _ []string) error { return fmt.Errorf("whitelist validator failed. Could not create tx relayer: %w", err) } - gasPrice, err := txRelayer.Client().Eth().GasPrice() - if err != nil { - return err - } - whitelistFn := &contractsapi.WhitelistValidatorsCustomSupernetManagerFn{ Validators_: stringSliceToAddressSlice(params.newValidatorAddresses), } @@ -110,10 +105,9 @@ func runCommand(cmd *cobra.Command, _ []string) error { supernetAddr := ethgo.Address(types.StringToAddress(params.supernetManagerAddress)) txn := ðgo.Transaction{ - From: ecdsaKey.Address(), - Input: encoded, - To: &supernetAddr, - GasPrice: gasPrice, + From: ecdsaKey.Address(), + Input: encoded, + To: &supernetAddr, } receipt, err := txRelayer.SendTransaction(txn, ecdsaKey) diff --git a/command/rootchain/withdraw/withdraw.go b/command/rootchain/withdraw/withdraw.go index 3b32597d5a..d64478eeaf 100644 --- a/command/rootchain/withdraw/withdraw.go +++ b/command/rootchain/withdraw/withdraw.go @@ -102,17 +102,11 @@ func runCommand(cmd *cobra.Command, _ []string) error { return err } - gasPrice, err := txRelayer.Client().Eth().GasPrice() - if err != nil { - return err - } - stakeManagerAddr := ethgo.Address(types.StringToAddress(params.stakeManagerAddr)) txn := ðgo.Transaction{ - From: validatorAccount.Ecdsa.Address(), - Input: encoded, - To: &stakeManagerAddr, - GasPrice: gasPrice, + From: validatorAccount.Ecdsa.Address(), + Input: encoded, + To: &stakeManagerAddr, } receipt, err := txRelayer.SendTransaction(txn, validatorAccount.Ecdsa) diff --git a/command/sidechain/helper.go b/command/sidechain/helper.go index 8930dc515f..969489c7f4 100644 --- a/command/sidechain/helper.go +++ b/command/sidechain/helper.go @@ -18,8 +18,6 @@ import ( const ( AmountFlag = "amount" - - DefaultGasPrice = 1879048192 // 0x70000000 ) func CheckIfDirectoryExist(dir string) error { diff --git a/command/sidechain/rewards/rewards.go b/command/sidechain/rewards/rewards.go index aa243bd03a..b46c1fd45d 100644 --- a/command/sidechain/rewards/rewards.go +++ b/command/sidechain/rewards/rewards.go @@ -95,10 +95,9 @@ func runCommand(cmd *cobra.Command, _ []string) error { } txn := ðgo.Transaction{ - From: validatorAddr, - Input: encoded, - To: &rewardPoolAddr, - GasPrice: sidechainHelper.DefaultGasPrice, + From: validatorAddr, + Input: encoded, + To: &rewardPoolAddr, } receipt, err := txRelayer.SendTransaction(txn, validatorAccount.Ecdsa) diff --git a/command/sidechain/unstaking/unstake.go b/command/sidechain/unstaking/unstake.go index 1de0aa43e5..f62fab1c80 100644 --- a/command/sidechain/unstaking/unstake.go +++ b/command/sidechain/unstaking/unstake.go @@ -88,10 +88,9 @@ func runCommand(cmd *cobra.Command, _ []string) error { } txn := ðgo.Transaction{ - From: validatorAccount.Ecdsa.Address(), - Input: encoded, - To: (*ethgo.Address)(&contracts.ValidatorSetContract), - GasPrice: sidechainHelper.DefaultGasPrice, + From: validatorAccount.Ecdsa.Address(), + Input: encoded, + To: (*ethgo.Address)(&contracts.ValidatorSetContract), } receipt, err := txRelayer.SendTransaction(txn, validatorAccount.Ecdsa) diff --git a/command/sidechain/withdraw/withdraw.go b/command/sidechain/withdraw/withdraw.go index 791e16540f..7ee8c9ddc0 100644 --- a/command/sidechain/withdraw/withdraw.go +++ b/command/sidechain/withdraw/withdraw.go @@ -77,10 +77,9 @@ func runCommand(cmd *cobra.Command, _ []string) error { } txn := ðgo.Transaction{ - From: validatorAccount.Ecdsa.Address(), - Input: encoded, - To: (*ethgo.Address)(&contracts.ValidatorSetContract), - GasPrice: sidechainHelper.DefaultGasPrice, + From: validatorAccount.Ecdsa.Address(), + Input: encoded, + To: (*ethgo.Address)(&contracts.ValidatorSetContract), } receipt, err := txRelayer.SendTransaction(txn, validatorAccount.Ecdsa) diff --git a/consensus/polybft/statesyncrelayer/state_sync_relayer.go b/consensus/polybft/statesyncrelayer/state_sync_relayer.go index b9f15764a0..26ca56bce2 100644 --- a/consensus/polybft/statesyncrelayer/state_sync_relayer.go +++ b/consensus/polybft/statesyncrelayer/state_sync_relayer.go @@ -196,11 +196,10 @@ func (r *StateSyncRelayer) executeStateSync(proof *types.Proof) error { // execute the state sync txn := ðgo.Transaction{ - From: r.key.Address(), - To: (*ethgo.Address)(&contracts.StateReceiverContract), - GasPrice: 0, - Gas: types.StateTransactionGasLimit, - Input: input, + From: r.key.Address(), + To: (*ethgo.Address)(&contracts.StateReceiverContract), + Gas: types.StateTransactionGasLimit, + Input: input, } receipt, err := r.txRelayer.SendTransaction(txn, r.key) diff --git a/e2e-polybft/e2e/jsonrpc_test.go b/e2e-polybft/e2e/jsonrpc_test.go index 9dc68fa1cd..54035ea727 100644 --- a/e2e-polybft/e2e/jsonrpc_test.go +++ b/e2e-polybft/e2e/jsonrpc_test.go @@ -85,10 +85,9 @@ func TestE2E_JsonRPC(t *testing.T) { toAddr := key1.Address() msg := ðgo.CallMsg{ - From: acct.Address(), - To: &toAddr, - Value: newBalance, - GasPrice: gasPrice, + From: acct.Address(), + To: &toAddr, + Value: newBalance, } estimatedGas, err := client.EstimateGas(msg) @@ -99,10 +98,9 @@ func TestE2E_JsonRPC(t *testing.T) { amountToSend := new(big.Int).Sub(newBalance, big.NewInt(int64(txPrice))) targetAddr := acct.Address() txn = cluster.SendTxn(t, key1, ðgo.Transaction{ - To: &targetAddr, - Value: amountToSend, - GasPrice: gasPrice, - Gas: estimatedGas, + To: &targetAddr, + Value: amountToSend, + Gas: estimatedGas, }) require.NoError(t, txn.Wait()) require.True(t, txn.Succeed()) diff --git a/e2e-polybft/e2e/migration_test.go b/e2e-polybft/e2e/migration_test.go index 27ea17ddf1..50b91f7d32 100644 --- a/e2e-polybft/e2e/migration_test.go +++ b/e2e-polybft/e2e/migration_test.go @@ -60,20 +60,18 @@ func TestE2E_Migration(t *testing.T) { //send transaction to user2 sendAmount := ethgo.Gwei(10000) receipt, err := relayer.SendTransaction(ðgo.Transaction{ - From: userAddr, - To: &userAddr2, - GasPrice: 1048576, - Gas: 1000000, - Value: sendAmount, + From: userAddr, + To: &userAddr2, + Gas: 1000000, + Value: sendAmount, }, userKey) assert.NoError(t, err) assert.NotNil(t, receipt) receipt, err = relayer.SendTransaction(ðgo.Transaction{ - From: userAddr, - GasPrice: 1048576, - Gas: 1000000, - Input: contractsapi.TestWriteBlockMetadata.Bytecode, + From: userAddr, + Gas: 1000000, + Input: contractsapi.TestWriteBlockMetadata.Bytecode, }, userKey) require.NoError(t, err) require.NotNil(t, receipt) diff --git a/e2e-polybft/framework/test-cluster.go b/e2e-polybft/framework/test-cluster.go index 47526249e1..d5a0f97ae5 100644 --- a/e2e-polybft/framework/test-cluster.go +++ b/e2e-polybft/framework/test-cluster.go @@ -910,7 +910,10 @@ func (c *TestCluster) SendTxn(t *testing.T, sender ethgo.Key, txn *ethgo.Transac } if txn.GasPrice == 0 { - txn.GasPrice = txrelayer.DefaultGasPrice + gasPrice, err := client.Eth().GasPrice() + require.NoError(t, err) + + txn.GasPrice = gasPrice } if txn.Gas == 0 { diff --git a/e2e/framework/testserver.go b/e2e/framework/testserver.go index b62853ffac..442cc41bf9 100644 --- a/e2e/framework/testserver.go +++ b/e2e/framework/testserver.go @@ -626,12 +626,6 @@ func (t *Txn) GasLimit(gas uint64) *Txn { return t } -func (t *Txn) GasPrice(price uint64) *Txn { - t.raw.GasPrice = price - - return t -} - func (t *Txn) Nonce(nonce uint64) *Txn { t.raw.Nonce = nonce @@ -645,7 +639,12 @@ func (t *Txn) sendImpl() error { } if t.raw.GasPrice == 0 { - t.raw.GasPrice = 1048576 + gasPrice, err := t.client.GasPrice() + if err != nil { + return fmt.Errorf("failed to get gas price: %w", err) + } + + t.raw.GasPrice = gasPrice } if t.raw.Nonce == 0 { diff --git a/e2e/jsonrpc_test.go b/e2e/jsonrpc_test.go index fbd655a2dc..f74eddd52a 100644 --- a/e2e/jsonrpc_test.go +++ b/e2e/jsonrpc_test.go @@ -81,7 +81,6 @@ func TestJsonRPC(t *testing.T) { amountToSend := new(big.Int).Sub(newBalance, big.NewInt(int64(txPrice))) txn, err = srv.Txn(key1).Transfer(fund.Address(), amountToSend). GasLimit(estimatedGas). - GasPrice(gasPrice). Send() require.NoError(t, err) txn.NoFail(t) From 58d5209259a11db03ea57d53f86a0c8c872dff77 Mon Sep 17 00:00:00 2001 From: dusan-maksimovic Date: Wed, 7 Jun 2023 11:50:38 +0200 Subject: [PATCH 7/7] unexposed defaultGasPrice constant --- txrelayer/txrelayer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/txrelayer/txrelayer.go b/txrelayer/txrelayer.go index 619da0448d..e64c7bd4a7 100644 --- a/txrelayer/txrelayer.go +++ b/txrelayer/txrelayer.go @@ -12,7 +12,7 @@ import ( ) const ( - DefaultGasPrice = 1879048192 // 0x70000000 + defaultGasPrice = 1879048192 // 0x70000000 DefaultGasLimit = 5242880 // 0x500000 DefaultRPCAddress = "http://127.0.0.1:8545" numRetries = 1000 @@ -147,7 +147,7 @@ func (t *TxRelayerImpl) SendTransactionLocal(txn *ethgo.Transaction) (*ethgo.Rec txn.From = accounts[0] txn.Gas = DefaultGasLimit - txn.GasPrice = DefaultGasPrice + txn.GasPrice = defaultGasPrice txnHash, err := t.client.Eth().SendTransaction(txn) if err != nil {