Skip to content

Commit 7d4e054

Browse files
authored
Add EvmTransferFast scenario (#27)
Add a new scenarios that would result in fewer writes per transaction: - transfer value is multiple of 10^12 so there will not be wei writes - tip cap is set to 0 so there will not be fee payment to validator (if base fee is set to 0 on the chain being benchmarked)
1 parent 571cdb7 commit 7d4e054

4 files changed

Lines changed: 94 additions & 3 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package scenarios
2+
3+
import (
4+
"math/big"
5+
6+
"github.com/ethereum/go-ethereum/common"
7+
ethtypes "github.com/ethereum/go-ethereum/core/types"
8+
9+
"github.com/sei-protocol/sei-load/config"
10+
types2 "github.com/sei-protocol/sei-load/types"
11+
)
12+
13+
const EVMTransferFast = "evmtransferfast"
14+
15+
// EVMTransferFastScenario implements the TxGenerator interface for simple ETH transfers
16+
// that only involve values that are multiples of 10^12 and no tipping.
17+
type EVMTransferFastScenario struct {
18+
*ScenarioBase
19+
}
20+
21+
// NewEVMTransferScenario creates a new ETH transfer scenario
22+
func NewEVMTransferFastScenario(cfg config.Scenario) TxGenerator {
23+
scenario := &EVMTransferFastScenario{}
24+
scenario.ScenarioBase = NewScenarioBase(scenario, cfg)
25+
return scenario
26+
}
27+
28+
// Name returns the name of the scenario.
29+
func (s *EVMTransferFastScenario) Name() string {
30+
return EVMTransfer
31+
}
32+
33+
// DeployScenario implements ScenarioDeployer interface - no deployment needed for ETH transfers
34+
func (s *EVMTransferFastScenario) DeployScenario(config *config.LoadConfig, deployer *types2.Account) common.Address {
35+
// No deployment needed for simple ETH transfers
36+
// Return zero address to indicate no contract deployment
37+
return common.Address{}
38+
}
39+
40+
// AttachScenario implements ScenarioDeployer interface - no attachment needed for ETH transfers.
41+
func (s *EVMTransferFastScenario) AttachScenario(config *config.LoadConfig, address common.Address) common.Address {
42+
// No attachment needed for simple ETH transfers
43+
// Return zero address to indicate no contract deployment
44+
return common.Address{}
45+
}
46+
47+
// CreateTransaction EVMTransferFastScenario ScenarioDeployer interface - creates ETH transfer transaction
48+
func (s *EVMTransferFastScenario) CreateTransaction(config *config.LoadConfig, scenario *types2.TxScenario) (*ethtypes.Transaction, error) {
49+
// Create transaction with value transfer
50+
tx := &ethtypes.DynamicFeeTx{
51+
Nonce: scenario.Sender.GetAndIncrementNonce(),
52+
To: &scenario.Receiver,
53+
Value: big.NewInt(1_000_000_000_000),
54+
Gas: 21000, // Standard gas limit for ETH transfer
55+
GasTipCap: big.NewInt(0), // 2 gwei
56+
GasFeeCap: big.NewInt(200000000000), // 200 gwei
57+
Data: nil, // No data for simple transfer
58+
}
59+
60+
if s.scenarioConfig.GasPicker != nil {
61+
var err error
62+
tx.Gas, err = s.scenarioConfig.GasPicker.GenerateGas()
63+
if err != nil {
64+
return nil, err
65+
}
66+
}
67+
if s.scenarioConfig.GasTipCapPicker != nil {
68+
gasTipCap, err := s.scenarioConfig.GasTipCapPicker.GenerateGas()
69+
if err != nil {
70+
return nil, err
71+
}
72+
tx.GasTipCap = big.NewInt(int64(gasTipCap))
73+
}
74+
if s.scenarioConfig.GasFeeCapPicker != nil {
75+
gasFeeCap, err := s.scenarioConfig.GasFeeCapPicker.GenerateGas()
76+
if err != nil {
77+
return nil, err
78+
}
79+
tx.GasFeeCap = big.NewInt(int64(gasFeeCap))
80+
}
81+
82+
// Sign the transaction
83+
signer := ethtypes.NewCancunSigner(config.GetChainID())
84+
signedTx, err := ethtypes.SignTx(ethtypes.NewTx(tx), signer, scenario.Sender.PrivKey)
85+
if err != nil {
86+
return nil, err
87+
}
88+
89+
return signedTx, nil
90+
}

generator/scenarios/factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type ScenarioFactory func(s config.Scenario) TxGenerator
1313
var scenarioFactories = map[string]ScenarioFactory{
1414
// Manual entries for non-contract scenarios
1515
EVMTransfer: NewEVMTransferScenario,
16+
EVMTransferFast: NewEVMTransferFastScenario,
1617
EVMTransferNoop: NewEVMTransferNoopScenario,
1718

1819
// Auto-generated entries will be added below this line by make generate

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require (
3131
github.com/davecgh/go-spew v1.1.1 // indirect
3232
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
3333
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
34-
github.com/ethereum/c-kzg-4844/v2 v2.1.1 // indirect
34+
github.com/ethereum/c-kzg-4844/v2 v2.1.0 // indirect
3535
github.com/ethereum/go-verkle v0.2.2 // indirect
3636
github.com/fsnotify/fsnotify v1.8.0 // indirect
3737
github.com/go-logr/logr v1.4.3 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvw
4545
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
4646
github.com/deepmap/oapi-codegen v1.6.0 h1:w/d1ntwh91XI0b/8ja7+u5SvA4IFfM0UNNLmiDR1gg0=
4747
github.com/deepmap/oapi-codegen v1.6.0/go.mod h1:ryDa9AgbELGeB+YEXE1dR53yAjHwFvE9iAUlWl9Al3M=
48-
github.com/ethereum/c-kzg-4844/v2 v2.1.1 h1:KhzBVjmURsfr1+S3k/VE35T02+AW2qU9t9gr4R6YpSo=
49-
github.com/ethereum/c-kzg-4844/v2 v2.1.1/go.mod h1:TC48kOKjJKPbN7C++qIgt0TJzZ70QznYR7Ob+WXl57E=
48+
github.com/ethereum/c-kzg-4844/v2 v2.1.0 h1:gQropX9YFBhl3g4HYhwE70zq3IHFRgbbNPw0Shwzf5w=
49+
github.com/ethereum/c-kzg-4844/v2 v2.1.0/go.mod h1:TC48kOKjJKPbN7C++qIgt0TJzZ70QznYR7Ob+WXl57E=
5050
github.com/ethereum/go-ethereum v1.16.1 h1:7684NfKCb1+IChudzdKyZJ12l1Tq4ybPZOITiCDXqCk=
5151
github.com/ethereum/go-ethereum v1.16.1/go.mod h1:ngYIvmMAYdo4sGW9cGzLvSsPGhDOOzL0jK5S5iXpj0g=
5252
github.com/ethereum/go-verkle v0.2.2 h1:I2W0WjnrFUIzzVPwm8ykY+7pL2d4VhlsePn4j7cnFk8=

0 commit comments

Comments
 (0)