Skip to content

Commit bb727f2

Browse files
committed
fmt
1 parent 5b2151b commit bb727f2

11 files changed

Lines changed: 158 additions & 148 deletions

File tree

generator/prewarm.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,78 +10,78 @@ import (
1010

1111
// PrewarmGenerator generates self-transfer transactions to prewarm account nonces
1212
type PrewarmGenerator struct {
13-
accountPools []types.AccountPool
14-
evmScenario scenarios.TxGenerator
15-
currentPoolIdx int
16-
finished bool
17-
mu sync.RWMutex
13+
accountPools []types.AccountPool
14+
evmScenario scenarios.TxGenerator
15+
currentPoolIdx int
16+
finished bool
17+
mu sync.RWMutex
1818
}
1919

2020
// NewPrewarmGenerator creates a new prewarm generator using all account pools from the main generator
2121
func NewPrewarmGenerator(config *config.LoadConfig, mainGenerator Generator) *PrewarmGenerator {
2222
// Get all account pools from the main generator
2323
accountPools := mainGenerator.GetAccountPools()
24-
24+
2525
// Create EVMTransfer scenario for prewarming
2626
evmScenario := scenarios.NewEVMTransferScenario()
27-
27+
2828
// Deploy/initialize the scenario (EVMTransfer doesn't need actual deployment)
2929
deployerAccounts := types.GenerateAccounts(1)
3030
deployer := deployerAccounts[0]
3131
evmScenario.Deploy(config, deployer)
32-
32+
3333
return &PrewarmGenerator{
34-
accountPools: accountPools,
35-
evmScenario: evmScenario,
34+
accountPools: accountPools,
35+
evmScenario: evmScenario,
3636
currentPoolIdx: 0,
37-
finished: false,
37+
finished: false,
3838
}
3939
}
4040

4141
// Generate generates self-transfer transactions until all accounts are prewarmed
4242
func (pg *PrewarmGenerator) Generate() (*types.LoadTx, bool) {
4343
pg.mu.Lock()
4444
defer pg.mu.Unlock()
45-
45+
4646
// Check if we're already finished
4747
if pg.finished || pg.currentPoolIdx >= len(pg.accountPools) {
4848
return nil, false
4949
}
50-
50+
5151
// Get current pool
5252
currentPool := pg.accountPools[pg.currentPoolIdx]
5353
account := currentPool.NextAccount()
54-
54+
5555
// If this account has nonce > 0, we've already prewarmed it (round-robin means we're done with this pool)
5656
if account.Nonce > 0 {
5757
// Move to next pool
5858
pg.currentPoolIdx++
59-
59+
6060
// Check if we've finished all pools
6161
if pg.currentPoolIdx >= len(pg.accountPools) {
6262
pg.finished = true
6363
return nil, false
6464
}
65-
65+
6666
// Get account from next pool
6767
currentPool = pg.accountPools[pg.currentPoolIdx]
6868
account = currentPool.NextAccount()
69-
69+
7070
// If this account also has nonce > 0, we're completely done
7171
if account.Nonce > 0 {
7272
pg.finished = true
7373
return nil, false
7474
}
7575
}
76-
76+
7777
// Create self-transfer transaction
7878
scenario := &types.TxScenario{
7979
Name: "EVMTransfer",
8080
Sender: account,
8181
Receiver: account.Address, // Send to self
8282
Nonce: account.GetAndIncrementNonce(),
8383
}
84-
84+
8585
// Generate the transaction using EVMTransfer scenario
8686
return pg.evmScenario.Generate(scenario), true
8787
}
@@ -103,7 +103,7 @@ func (pg *PrewarmGenerator) GenerateN(n int) []*types.LoadTx {
103103
func (pg *PrewarmGenerator) GetAccountPools() []types.AccountPool {
104104
pg.mu.RLock()
105105
defer pg.mu.RUnlock()
106-
106+
107107
// Return a copy to prevent external modification
108108
pools := make([]types.AccountPool, len(pg.accountPools))
109109
copy(pools, pg.accountPools)

generator/scenarios/factory.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ var scenarioFactories = map[string]ScenarioFactory{
1111
// Auto-generated entries will be added below this line by make generate
1212
// DO NOT EDIT BELOW THIS LINE - AUTO-GENERATED CONTENT
1313
ERC20Conflict: NewERC20ConflictScenario,
14-
ERC20Noop: NewERC20NoopScenario,
15-
ERC20: NewERC20Scenario,
16-
ERC721: NewERC721Scenario,
14+
ERC20Noop: NewERC20NoopScenario,
15+
ERC20: NewERC20Scenario,
16+
ERC721: NewERC721Scenario,
1717

1818
// DO NOT EDIT ABOVE THIS LINE - AUTO-GENERATED CONTENT
1919
}

generator/weighted.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package generator
22

33
import (
44
"context"
5-
"math/rand"
65
"github.com/sei-protocol/sei-load/types"
6+
"math/rand"
77
"sync"
88
)
99

sender/dispatcher.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package sender
33
import (
44
"context"
55
"fmt"
6+
"golang.org/x/time/rate"
7+
"log"
68
"sync"
79
"time"
8-
"log"
9-
"golang.org/x/time/rate"
1010

11-
"github.com/sei-protocol/sei-load/utils"
1211
"github.com/sei-protocol/sei-load/generator"
1312
"github.com/sei-protocol/sei-load/stats"
13+
"github.com/sei-protocol/sei-load/utils"
1414
)
1515

1616
// Dispatcher continuously generates transactions and dispatches them to the sender
@@ -20,7 +20,7 @@ type Dispatcher struct {
2020
sender TxSender
2121

2222
// Configuration
23-
limiter *rate.Limiter
23+
limiter *rate.Limiter
2424

2525
// Statistics
2626
totalSent uint64
@@ -33,15 +33,15 @@ func NewDispatcher(gen generator.Generator, sender TxSender) *Dispatcher {
3333
return &Dispatcher{
3434
generator: gen,
3535
sender: sender,
36-
limiter: rate.NewLimiter(rate.Inf, 1), // No rate limiting by default
36+
limiter: rate.NewLimiter(rate.Inf, 1), // No rate limiting by default
3737
}
3838
}
3939

4040
// SetRateLimit sets the minimum time between transaction generations
4141
func (d *Dispatcher) SetRateLimit(duration time.Duration) {
4242
d.mu.Lock()
4343
defer d.mu.Unlock()
44-
d.limiter = rate.NewLimiter(rate.Every(duration),1)
44+
d.limiter = rate.NewLimiter(rate.Every(duration), 1)
4545
}
4646

4747
// SetStatsCollector sets the statistics collector for this dispatcher
@@ -65,7 +65,9 @@ func (d *Dispatcher) Prewarm(ctx context.Context) error {
6565
d.mu.RUnlock()
6666

6767
gen, ok := prewarmGen.Get()
68-
if !ok { return nil } // No prewarming configured
68+
if !ok {
69+
return nil
70+
} // No prewarming configured
6971

7072
log.Print("🔥 Starting account prewarming...")
7173
processedAccounts := 0
@@ -103,7 +105,7 @@ func (d *Dispatcher) Run(ctx context.Context) error {
103105
d.mu.RUnlock()
104106

105107
for {
106-
if err:=limiter.Wait(ctx); err!=nil {
108+
if err := limiter.Wait(ctx); err != nil {
107109
return err
108110
}
109111
// Generate a transaction from main generator
@@ -116,7 +118,7 @@ func (d *Dispatcher) Run(ctx context.Context) error {
116118
// Send the transaction
117119
if err := d.sender.Send(ctx, tx); err != nil {
118120
return err
119-
}
121+
}
120122
d.mu.Lock()
121123
d.totalSent++
122124
d.mu.Unlock()
@@ -132,7 +134,7 @@ func (d *Dispatcher) RunBatch(ctx context.Context, count int) error {
132134
limiter := d.limiter
133135
d.mu.RUnlock()
134136
for i := range count {
135-
if err:=limiter.Wait(ctx); err!=nil {
137+
if err := limiter.Wait(ctx); err != nil {
136138
return err
137139
}
138140
// Generate a transaction

sender/sender_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func TestShardDistributionVerification(t *testing.T) {
110110
mockAccount := &types.Account{
111111
Address: common.HexToAddress("0x1234567890123456789012345678901234567890"),
112112
}
113-
113+
114114
mockTx := &types.LoadTx{
115115
EthTx: ethtypes.NewTransaction(0, common.Address{}, big.NewInt(0), 21000, big.NewInt(1000000000), nil),
116116
Scenario: &types.TxScenario{

sender/sharded_sender.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package sender
22

33
import (
4+
"context"
45
"fmt"
56
"sync"
6-
"context"
77

88
"github.com/sei-protocol/sei-load/config"
99
"github.com/sei-protocol/sei-load/stats"

sender/worker.go

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,34 @@ import (
66
"fmt"
77
"github.com/ethereum/go-ethereum/ethclient"
88
"io"
9-
"net"
109
"log"
10+
"net"
1111
"net/http"
1212
"time"
1313

1414
"github.com/sei-protocol/sei-load/stats"
1515
"github.com/sei-protocol/sei-load/types"
16-
"github.com/sei-protocol/sei-load/utils/service"
1716
"github.com/sei-protocol/sei-load/utils"
17+
"github.com/sei-protocol/sei-load/utils/service"
1818
)
1919

2020
// Worker handles sending transactions to a specific endpoint
2121
type Worker struct {
22-
id int
23-
endpoint string
24-
txChan chan *types.LoadTx
25-
sentTxs chan *types.LoadTx
26-
dryRun bool
27-
debug bool
28-
collector *stats.Collector
29-
logger *stats.Logger
30-
workers int
22+
id int
23+
endpoint string
24+
txChan chan *types.LoadTx
25+
sentTxs chan *types.LoadTx
26+
dryRun bool
27+
debug bool
28+
collector *stats.Collector
29+
logger *stats.Logger
30+
workers int
3131
trackReceipts bool
3232
}
3333

3434
func newHttpClient() *http.Client {
3535
return &http.Client{
36-
Timeout: 30 * time.Second,
36+
Timeout: 30 * time.Second,
3737
Transport: &http.Transport{
3838
DialContext: (&net.Dialer{
3939
Timeout: 10 * time.Second,
@@ -52,11 +52,11 @@ func newHttpClient() *http.Client {
5252
// NewWorker creates a new worker for a specific endpoint
5353
func NewWorker(id int, endpoint string, bufferSize int, workers int) *Worker {
5454
return &Worker{
55-
id: id,
56-
endpoint: endpoint,
57-
txChan: make(chan *types.LoadTx, bufferSize),
58-
sentTxs: make(chan *types.LoadTx, bufferSize),
59-
workers: workers,
55+
id: id,
56+
endpoint: endpoint,
57+
txChan: make(chan *types.LoadTx, bufferSize),
58+
sentTxs: make(chan *types.LoadTx, bufferSize),
59+
workers: workers,
6060
trackReceipts: true,
6161
}
6262
}
@@ -73,7 +73,7 @@ func (w *Worker) Run(ctx context.Context) error {
7373
// Start multiple worker goroutines that share the same channel
7474
client := newHttpClient()
7575
for range w.workers {
76-
s.Spawn(func() error { return w.processTransactions(ctx,client) })
76+
s.Spawn(func() error { return w.processTransactions(ctx, client) })
7777
}
7878
return w.watchTransactions(ctx)
7979
})
@@ -109,19 +109,21 @@ func (w *Worker) watchTransactions(ctx context.Context) error {
109109
}
110110
for {
111111
tx, err := utils.Recv(ctx, w.sentTxs)
112-
if err!=nil { return err }
113-
ctx,cancel := context.WithTimeout(ctx, 10*time.Second)
112+
if err != nil {
113+
return err
114+
}
115+
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
114116
defer cancel()
115117
if err := w.waitForReceipt(ctx, eth, tx); err != nil {
116-
log.Printf("❌ %v",err)
118+
log.Printf("❌ %v", err)
117119
}
118120
}
119121
}
120122

121123
func (w *Worker) waitForReceipt(ctx context.Context, eth *ethclient.Client, tx *types.LoadTx) error {
122124
ticker := time.NewTicker(100 * time.Millisecond)
123125
for {
124-
if _,err := utils.Recv(ctx, ticker.C); err != nil {
126+
if _, err := utils.Recv(ctx, ticker.C); err != nil {
125127
return fmt.Errorf("timeout waiting for receipt for tx %s", tx.EthTx.Hash().Hex())
126128
}
127129
receipt, err := eth.TransactionReceipt(context.Background(), tx.EthTx.Hash())
@@ -146,16 +148,18 @@ func (w *Worker) waitForReceipt(ctx context.Context, eth *ethclient.Client, tx *
146148
// processTransactions is the main worker loop that processes transactions
147149
func (w *Worker) processTransactions(ctx context.Context, client *http.Client) error {
148150
for {
149-
tx,err := utils.Recv(ctx, w.txChan)
150-
if err != nil { return err }
151+
tx, err := utils.Recv(ctx, w.txChan)
152+
if err != nil {
153+
return err
154+
}
151155
startTime := time.Now()
152156
err = w.sendTransaction(ctx, client, tx)
153157
// Record statistics if collector is available
154158
if w.collector != nil {
155-
w.collector.RecordTransaction(tx.Scenario.Name, w.endpoint, time.Since(startTime), err==nil)
159+
w.collector.RecordTransaction(tx.Scenario.Name, w.endpoint, time.Since(startTime), err == nil)
156160
}
157-
if err!=nil {
158-
log.Printf("%v",err)
161+
if err != nil {
162+
log.Printf("%v", err)
159163
}
160164
}
161165
}
@@ -165,7 +169,7 @@ func (w *Worker) sendTransaction(ctx context.Context, client *http.Client, tx *t
165169
if w.dryRun {
166170
// In dry-run mode, simulate processing time and mark as successful
167171
// Use very minimal delay to avoid channel overflow
168-
return utils.Sleep(ctx, 10 * time.Microsecond) // Much faster simulation
172+
return utils.Sleep(ctx, 10*time.Microsecond) // Much faster simulation
169173
}
170174

171175
// Create HTTP request with JSON-RPC payload

stats/block_collector.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,18 @@ func (bc *BlockCollector) Run(ctx context.Context, firstEndpoint string) error {
6262
}
6363
defer sub.Unsubscribe()
6464
s.SpawnBg(func() error {
65-
subErr,err := utils.Recv(ctx, sub.Err())
66-
if err != nil { return err }
65+
subErr, err := utils.Recv(ctx, sub.Err())
66+
if err != nil {
67+
return err
68+
}
6769
return subErr
6870
})
6971
log.Printf("📡 Subscribed to new blocks on %s", wsEndpoint)
7072
for {
71-
header,err := utils.Recv(ctx, headers)
72-
if err != nil { return err }
73+
header, err := utils.Recv(ctx, headers)
74+
if err != nil {
75+
return err
76+
}
7377
bc.processNewBlock(header)
7478
}
7579
})

0 commit comments

Comments
 (0)