From 06ef75ecca1ab42ddaa847011356ae4233ee0a7f Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Mon, 3 Jun 2024 11:00:45 -0400 Subject: [PATCH] Allow eip1559 txs in loadtest (#1698) * Use eip1559 txs in loadtest * added eip1559 txs to loadtest * add flag for eip1559 vs legacy * fix * fix * fix * no more runaway gas price * fix --- loadtest/config.json | 1 + loadtest/evm.go | 46 +++++++++++++++++++++++++++++-------- loadtest/loadtest_client.go | 2 +- loadtest/types.go | 1 + 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/loadtest/config.json b/loadtest/config.json index 2ae40cd6a1..3a9dfed479 100644 --- a/loadtest/config.json +++ b/loadtest/config.json @@ -63,6 +63,7 @@ "evm", "univ2" ], + "evm_use_eip1559_txs": true, "run_oracle": false, "metrics_port": 9695, "wasm_msg_types": { diff --git a/loadtest/evm.go b/loadtest/evm.go index de31e64d83..05c9fdeb4b 100644 --- a/loadtest/evm.go +++ b/loadtest/evm.go @@ -24,6 +24,11 @@ import ( "github.com/sei-protocol/sei-chain/loadtest/contracts/evm/bindings/univ2_swapper" ) +var ( + DefaultPriorityFee = big.NewInt(1000000000) // 1gwei + DefaultMaxFee = big.NewInt(1000000000) // 1gwei +) + type EvmTxClient struct { accountAddress common.Address nonce atomic.Uint64 @@ -33,6 +38,7 @@ type EvmTxClient struct { mtx sync.RWMutex privateKey *ecdsa.PrivateKey evmAddresses *EVMAddresses + useEip1559 bool } func NewEvmTxClient( @@ -41,6 +47,7 @@ func NewEvmTxClient( gasPrice *big.Int, ethClients []*ethclient.Client, evmAddresses *EVMAddresses, + useEip1559 bool, ) *EvmTxClient { if evmAddresses == nil { evmAddresses = &EVMAddresses{} @@ -73,6 +80,8 @@ func NewEvmTxClient( } txClient.nonce.Store(nextNonce) txClient.accountAddress = fromAddress + txClient.useEip1559 = useEip1559 + return txClient } @@ -99,13 +108,27 @@ func randomValue() *big.Int { // //nolint:staticcheck func (txClient *EvmTxClient) GenerateSendFundsTx() *ethtypes.Transaction { - tx := ethtypes.NewTx(ðtypes.LegacyTx{ - Nonce: txClient.nextNonce(), - GasPrice: txClient.gasPrice, - Gas: uint64(21000), - To: &txClient.accountAddress, - Value: randomValue(), - }) + var tx *ethtypes.Transaction + if !txClient.useEip1559 { + tx = ethtypes.NewTx(ðtypes.LegacyTx{ + Nonce: txClient.nextNonce(), + GasPrice: txClient.gasPrice, + Gas: uint64(21000), + To: &txClient.accountAddress, + Value: randomValue(), + }) + } else { + dynamicTx := ðtypes.DynamicFeeTx{ + ChainID: txClient.chainId, + Nonce: txClient.nextNonce(), + GasTipCap: DefaultPriorityFee, + GasFeeCap: DefaultMaxFee, + Gas: uint64(21000), + To: &txClient.accountAddress, + Value: randomValue(), + } + tx = ethtypes.NewTx(dynamicTx) + } return txClient.sign(tx) } @@ -162,10 +185,15 @@ func (txClient *EvmTxClient) getTransactOpts() *bind.TransactOpts { if err != nil { panic(fmt.Sprintf("Failed to create transactor: %v \n", err)) } + if !txClient.useEip1559 { + auth.GasPrice = txClient.gasPrice + } else { + auth.GasFeeCap = DefaultMaxFee + auth.GasTipCap = DefaultPriorityFee + } auth.Nonce = big.NewInt(int64(txClient.nextNonce())) auth.Value = big.NewInt(0) auth.GasLimit = uint64(21000) - auth.GasPrice = txClient.gasPrice auth.Context = context.Background() auth.From = txClient.accountAddress auth.NoSend = true @@ -173,7 +201,7 @@ func (txClient *EvmTxClient) getTransactOpts() *bind.TransactOpts { } func (txClient *EvmTxClient) sign(tx *ethtypes.Transaction) *ethtypes.Transaction { - signedTx, err := ethtypes.SignTx(tx, ethtypes.NewEIP155Signer(txClient.chainId), txClient.privateKey) + signedTx, err := ethtypes.SignTx(tx, ethtypes.NewLondonSigner(txClient.chainId), txClient.privateKey) if err != nil { // this should not happen panic(err) diff --git a/loadtest/loadtest_client.go b/loadtest/loadtest_client.go index 9c4ee79db2..945de4bc9a 100644 --- a/loadtest/loadtest_client.go +++ b/loadtest/loadtest_client.go @@ -164,7 +164,7 @@ func BuildEvmTxClients(config *Config, keys []cryptotypes.PrivKey) []*EvmTxClien } // Build one client per key for i, key := range keys { - clients[i] = NewEvmTxClient(key, chainID, gasPrice, ethClients, config.EVMAddresses) + clients[i] = NewEvmTxClient(key, chainID, gasPrice, ethClients, config.EVMAddresses, config.EvmUseEip1559Txs) } return clients } diff --git a/loadtest/types.go b/loadtest/types.go index a09d3c4000..bb511001f6 100644 --- a/loadtest/types.go +++ b/loadtest/types.go @@ -71,6 +71,7 @@ type Config struct { SeiTesterAddress string `json:"sei_tester_address"` PostTxEvmQueries PostTxEvmQueries `json:"post_tx_evm_queries"` Ticks uint64 `json:"ticks"` + EvmUseEip1559Txs bool `json:"evm_use_eip1559_txs"` // setting this to true could make gas go up to infinity // These are dynamically set at startup EVMAddresses *EVMAddresses