Skip to content

Commit

Permalink
Allow eip1559 txs in loadtest (sei-protocol#1698)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jewei1997 authored Jun 3, 2024
1 parent 1702e4e commit 06ef75e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions loadtest/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"evm",
"univ2"
],
"evm_use_eip1559_txs": true,
"run_oracle": false,
"metrics_port": 9695,
"wasm_msg_types": {
Expand Down
46 changes: 37 additions & 9 deletions loadtest/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,6 +38,7 @@ type EvmTxClient struct {
mtx sync.RWMutex
privateKey *ecdsa.PrivateKey
evmAddresses *EVMAddresses
useEip1559 bool
}

func NewEvmTxClient(
Expand All @@ -41,6 +47,7 @@ func NewEvmTxClient(
gasPrice *big.Int,
ethClients []*ethclient.Client,
evmAddresses *EVMAddresses,
useEip1559 bool,
) *EvmTxClient {
if evmAddresses == nil {
evmAddresses = &EVMAddresses{}
Expand Down Expand Up @@ -73,6 +80,8 @@ func NewEvmTxClient(
}
txClient.nonce.Store(nextNonce)
txClient.accountAddress = fromAddress
txClient.useEip1559 = useEip1559

return txClient
}

Expand All @@ -99,13 +108,27 @@ func randomValue() *big.Int {
//
//nolint:staticcheck
func (txClient *EvmTxClient) GenerateSendFundsTx() *ethtypes.Transaction {
tx := ethtypes.NewTx(&ethtypes.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(&ethtypes.LegacyTx{
Nonce: txClient.nextNonce(),
GasPrice: txClient.gasPrice,
Gas: uint64(21000),
To: &txClient.accountAddress,
Value: randomValue(),
})
} else {
dynamicTx := &ethtypes.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)
}

Expand Down Expand Up @@ -162,18 +185,23 @@ 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
return auth
}

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)
Expand Down
2 changes: 1 addition & 1 deletion loadtest/loadtest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions loadtest/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 06ef75e

Please sign in to comment.