Skip to content

Commit 052ec99

Browse files
authored
[CON-92] Fix contract deployment and contract txs (#23)
We don't use the deployer account for anything else outside of deployments, and it is randomly generated anyways, so we can instead use a new deployer for each contract to prevent nonce or account related issues causing timeouts on deployments.
1 parent 693699a commit 052ec99

10 files changed

Lines changed: 20 additions & 29 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Edit `my-config.json`:
2121
```json
2222
{
2323
"endpoints": ["http://localhost:8545"],
24-
"chainId": 1329,
24+
"chainId": 713714,
2525
"scenarios": [
2626
{"name": "EVMTransfer", "weight": 100}
2727
],
@@ -94,7 +94,7 @@ Edit `my-config.json`:
9494
```json
9595
{
9696
"endpoints": ["http://localhost:8545"],
97-
"chainId": 1329,
97+
"chainId": 713714,
9898
"scenarios": [...],
9999
"accounts": {...},
100100
"settings": {...}

generator/generator.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,13 @@ func (g *configBasedGenerator) deployAll() error {
134134
// Deploy sequentially to ensure proper nonce management
135135
for _, instance := range g.instances {
136136
// Deploy the scenario
137+
log.Printf("Deploying scenario %s", instance.Name)
137138
address := instance.Scenario.Deploy(g.config, g.deployer)
138139
instance.Deployed = true
139140

140141
if address.Cmp(common.Address{}) != 0 {
141142
log.Printf("🚀 Deployed %s at address: %s\n", instance.Name, address.Hex())
142143
}
143-
144-
// Increment deployer nonce for next deployment
145-
g.deployer.GetAndIncrementNonce()
146144
}
147145

148146
return nil

generator/prewarm.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ func (pg *PrewarmGenerator) Generate() (*types.LoadTx, bool) {
7979
Name: "EVMTransfer",
8080
Sender: account,
8181
Receiver: account.Address, // Send to self
82-
Nonce: account.GetAndIncrementNonce(),
8382
}
8483

8584
// Generate the transaction using EVMTransfer scenario

generator/scenario.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func (g *scenarioGenerator) Generate() (*types.LoadTx, bool) {
4040
Name: g.scenario.Name(),
4141
Sender: sender,
4242
Receiver: receiver.Address,
43-
Nonce: sender.GetAndIncrementNonce(),
4443
}), true
4544
}
4645

generator/scenarios/EVMTransfer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (s *EVMTransferScenario) AttachScenario(config *config.LoadConfig, address
4848
func (s *EVMTransferScenario) CreateTransaction(config *config.LoadConfig, scenario *types2.TxScenario) (*ethtypes.Transaction, error) {
4949
// Create transaction with value transfer
5050
tx := &ethtypes.DynamicFeeTx{
51-
Nonce: scenario.Nonce,
51+
Nonce: scenario.Sender.GetAndIncrementNonce(),
5252
To: &scenario.Receiver,
5353
Value: big.NewInt(time.Now().Unix()),
5454
Gas: 21000, // Standard gas limit for ETH transfer

generator/scenarios/EVMTransferNoop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (s *EVMTransferNoopScenario) AttachScenario(config *config.LoadConfig, addr
4747
func (s *EVMTransferNoopScenario) CreateTransaction(config *config.LoadConfig, scenario *types2.TxScenario) (*ethtypes.Transaction, error) {
4848
// Create transaction with value transfer
4949
tx := &ethtypes.DynamicFeeTx{
50-
Nonce: scenario.Nonce,
50+
Nonce: scenario.Sender.GetAndIncrementNonce(),
5151
To: &scenario.Sender.Address,
5252
Value: big.NewInt(0),
5353
Gas: 21000, // Standard gas limit for ETH transfer

generator/scenarios/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (c *ContractScenarioBase[T]) DeployScenario(config *config.LoadConfig, depl
186186
log.Printf("📤 Deployment transaction sent: %s", tx.Hash().Hex())
187187

188188
// Wait for the deployment transaction to be mined
189-
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
189+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
190190
defer cancel()
191191

192192
receipt, err := bind.WaitMined(ctx, client, tx)

generator/utils/utils.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package utils
22

33
import (
44
"math/big"
5-
"time"
65

76
"github.com/ethereum/go-ethereum/accounts/abi/bind"
87
"github.com/ethereum/go-ethereum/common"
@@ -46,9 +45,8 @@ func createTransactOpts(chainID *big.Int, account *loadtypes.Account, gasLimit u
4645
}
4746

4847
// Set transaction parameters
49-
auth.Nonce = big.NewInt(int64(account.Nonce))
48+
auth.Nonce = big.NewInt(int64(account.GetAndIncrementNonce()))
5049
auth.NoSend = noSend
51-
auth.Value = big.NewInt(time.Now().Unix())
5250

5351
auth.GasLimit = gasLimit
5452
auth.GasTipCap = big.NewInt(2000000000) // 2 gwei tip (priority fee)
@@ -70,6 +68,5 @@ func CreateTransactionOpts(chainID *big.Int, scenario *loadtypes.TxScenario) *bi
7068
if err != nil {
7169
panic("Failed to create transaction options: " + err.Error())
7270
}
73-
opts.Nonce.SetUint64(scenario.Nonce)
7471
return opts
7572
}

types/scenario.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func (tx *LoadTx) ShardID(n int) int {
4949
// TxScenario captures the scenario of this test transaction.
5050
type TxScenario struct {
5151
Name string
52-
Nonce uint64
5352
Sender *Account
5453
Receiver common.Address
5554
}

types/types_test.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,18 @@ func TestCreateTxFromEthTx(t *testing.T) {
250250
account, err := NewAccount()
251251
require.NoError(t, err)
252252

253+
account.Nonce = 42
253254
receiver := common.HexToAddress("0x1234567890123456789012345678901234567890")
254255
scenario := &TxScenario{
255256
Name: "TestScenario",
256-
Nonce: 42,
257257
Sender: account,
258258
Receiver: receiver,
259259
}
260260

261261
// Create a test transaction using DynamicFeeTx (EIP-1559)
262262
tx := types.NewTx(&types.DynamicFeeTx{
263-
ChainID: big.NewInt(1329), // Sei testnet chain ID
264-
Nonce: scenario.Nonce,
263+
ChainID: big.NewInt(713714), // Sei testnet chain ID
264+
Nonce: scenario.Sender.Nonce,
265265
GasTipCap: big.NewInt(2000000000), // 2 Gwei tip
266266
GasFeeCap: big.NewInt(20000000000), // 20 Gwei max fee
267267
Gas: 21000, // Gas limit
@@ -314,15 +314,15 @@ func TestLoadTxShardID(t *testing.T) {
314314
account := accounts[i%len(accounts)]
315315
scenario := &TxScenario{
316316
Name: "TestScenario",
317-
Nonce: uint64(i),
318317
Sender: account,
319318
Receiver: common.Address{},
320319
}
321320

321+
scenario.Sender.Nonce = uint64(i)
322322
// Create a simple transaction
323323
tx := types.NewTx(&types.DynamicFeeTx{
324-
ChainID: big.NewInt(1329), // Sei testnet chain ID
325-
Nonce: scenario.Nonce,
324+
ChainID: big.NewInt(713714), // Sei testnet chain ID
325+
Nonce: scenario.Sender.Nonce,
326326
GasTipCap: big.NewInt(2000000000), // 2 Gwei tip
327327
GasFeeCap: big.NewInt(20000000000), // 20 Gwei max fee
328328
Gas: 21000, // Gas limit
@@ -374,14 +374,13 @@ func TestLoadTxShardIDConsistency(t *testing.T) {
374374

375375
scenario := &TxScenario{
376376
Name: "TestScenario",
377-
Nonce: 0,
378377
Sender: account,
379378
Receiver: common.Address{},
380379
}
381380

382381
tx := types.NewTx(&types.DynamicFeeTx{
383-
ChainID: big.NewInt(1329), // Sei testnet chain ID
384-
Nonce: scenario.Nonce,
382+
ChainID: big.NewInt(713714), // Sei testnet chain ID
383+
Nonce: scenario.Sender.Nonce,
385384
GasTipCap: big.NewInt(2000000000), // 2 Gwei tip
386385
GasFeeCap: big.NewInt(20000000000), // 20 Gwei max fee
387386
Gas: 21000, // Gas limit
@@ -408,16 +407,17 @@ func TestTxScenario(t *testing.T) {
408407

409408
receiver := common.HexToAddress("0xabcdefabcdefabcdefabcdefabcdefabcdefabcd")
410409

410+
account.Nonce = 123
411+
411412
scenario := &TxScenario{
412413
Name: "TestScenario",
413-
Nonce: 123,
414414
Sender: account,
415415
Receiver: receiver,
416416
}
417417

418418
// Verify all fields are set correctly
419419
assert.Equal(t, "TestScenario", scenario.Name)
420-
assert.Equal(t, uint64(123), scenario.Nonce)
420+
assert.Equal(t, uint64(123), scenario.Sender.Nonce)
421421
assert.Equal(t, account, scenario.Sender)
422422
assert.Equal(t, receiver, scenario.Receiver)
423423
}
@@ -477,14 +477,13 @@ func BenchmarkCreateTxFromEthTx(b *testing.B) {
477477

478478
scenario := &TxScenario{
479479
Name: "BenchmarkScenario",
480-
Nonce: 0,
481480
Sender: account,
482481
Receiver: common.Address{},
483482
}
484483

485484
tx := types.NewTx(&types.DynamicFeeTx{
486-
ChainID: big.NewInt(1329), // Sei testnet chain ID
487-
Nonce: scenario.Nonce,
485+
ChainID: big.NewInt(713714), // Sei testnet chain ID
486+
Nonce: scenario.Sender.Nonce,
488487
GasTipCap: big.NewInt(2000000000), // 2 Gwei tip
489488
GasFeeCap: big.NewInt(20000000000), // 20 Gwei max fee
490489
Gas: 21000, // Gas limit

0 commit comments

Comments
 (0)