Skip to content

Commit 5b2151b

Browse files
committed
refactor done
1 parent 19b5e98 commit 5b2151b

13 files changed

Lines changed: 365 additions & 601 deletions

File tree

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ifeq ($(GOPATH),)
1515
endif
1616

1717
# Tools
18-
SOLC := solc
18+
SOLC := /tmp/solc
1919
ABIGEN := abigen
2020
NVM_DIR := $(HOME)/.nvm
2121
NODE_VERSION := 20
@@ -63,8 +63,8 @@ setup-node:
6363
nvm install $(NODE_VERSION) && \
6464
nvm use $(NODE_VERSION)
6565
@echo "📦 Installing native solc binary..."
66-
@curl -L https://github.com/ethereum/solidity/releases/download/v0.8.19/solc-static-linux -o /usr/local/bin/solc && \
67-
chmod +x /usr/local/bin/solc
66+
@curl -L https://github.com/ethereum/solidity/releases/download/v0.8.19/solc-static-linux -o /tmp/solc && \
67+
chmod +x /tmp/solc
6868
@echo "✅ Node.js environment setup complete"
6969
@echo "ℹ️ Note: You may need to restart your shell or run 'source ~/.bashrc' to use nvm in new sessions"
7070

generator/weighted.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (w *weightedGenerator) nextGenerator() Generator {
6969
// GenerateN generates n transactions.
7070
func (w *weightedGenerator) GenerateN(n int) []*types.LoadTx {
7171
txs := make([]*types.LoadTx, 0, n)
72-
for i := 0; i < n; i++ {
72+
for range n {
7373
if tx, ok := w.Generate(); ok {
7474
txs = append(txs, tx)
7575
} else {
@@ -108,7 +108,7 @@ func NewWeightedGenerator(cfgs ...*WeightedCfg) Generator {
108108
}
109109
var weighted []Generator
110110
for _, cfg := range cfgs {
111-
for i := 0; i < cfg.Weight; i++ {
111+
for range cfg.Weight {
112112
weighted = append(weighted, cfg.Generator)
113113
}
114114
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/spf13/cobra v1.9.1
1010
github.com/stretchr/testify v1.10.0
1111
golang.org/x/sync v0.16.0
12+
golang.org/x/time v0.9.0
1213
google.golang.org/protobuf v1.34.2
1314
)
1415

main.go

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"github.com/sei-protocol/sei-load/utils/service"
78
"log"
89
"os"
910
"os/signal"
1011
"strings"
1112
"syscall"
12-
"github.com/sei-protocol/sei-load/utils/service"
1313
"time"
1414

1515
"github.com/spf13/cobra"
@@ -18,6 +18,7 @@ import (
1818
"github.com/sei-protocol/sei-load/generator"
1919
"github.com/sei-protocol/sei-load/sender"
2020
"github.com/sei-protocol/sei-load/stats"
21+
"github.com/sei-protocol/sei-load/utils"
2122
)
2223

2324
var (
@@ -45,7 +46,7 @@ to multiple endpoints with account pooling management.
4546
Use --dry-run to test configuration and view transaction details
4647
without actually sending requests or deploying contracts.`,
4748
Run: func(cmd *cobra.Command, args []string) {
48-
if err:=runLoadTest(context.Background(),cmd,args); err != nil {
49+
if err := runLoadTest(context.Background(), cmd, args); err != nil {
4950
log.Fatal(err)
5051
}
5152
},
@@ -135,10 +136,10 @@ func runLoadTest(ctx context.Context, cmd *cobra.Command, args []string) error {
135136
// Create and start block collector if endpoints are available
136137
var blockCollector *stats.BlockCollector
137138
if len(cfg.Endpoints) > 0 && trackBlocks {
138-
blockCollector = stats.NewBlockCollector(cfg.Endpoints[0])
139+
blockCollector = stats.NewBlockCollector()
139140
collector.SetBlockCollector(blockCollector)
140141
s.SpawnBgNamed("block collector", func() error {
141-
return blockCollector.Run(ctx)
142+
return blockCollector.Run(ctx, cfg.Endpoints[0])
142143
})
143144
}
144145

@@ -168,29 +169,21 @@ func runLoadTest(ctx context.Context, cmd *cobra.Command, args []string) error {
168169
}
169170

170171
// Set statistics collector for dispatcher
171-
dispatcher.SetStatsCollector(collector, logger)
172+
dispatcher.SetStatsCollector(collector)
172173

173174
// Set up prewarming if enabled
174175
if prewarm {
175-
log.Println("🔥 Creating prewarm generator...")
176+
log.Printf("🔥 Creating prewarm generator...")
176177
prewarmGen := generator.NewPrewarmGenerator(cfg, gen)
177178
dispatcher.SetPrewarmGenerator(prewarmGen)
178-
log.Println("✅ Prewarm generator ready")
179+
log.Printf("✅ Prewarm generator ready")
179180
log.Printf("📝 Prewarm mode: Accounts will be prewarmed")
180181
}
181182

182183
// Start the sender (starts all workers)
183184
s.SpawnBgNamed("sender", func() error { return snd.Run(ctx) })
184185
log.Printf("✅ Connected to %d endpoints", snd.GetNumShards())
185186

186-
// Start block collector if enabled
187-
if trackBlocks {
188-
blockCollector = stats.NewBlockCollector(cfg.Endpoints[0])
189-
collector.SetBlockCollector(blockCollector)
190-
s.SpawnBgNamed("block collector", func() error { return blockCollector.Run(ctx) })
191-
log.Println("✅ Started block collector")
192-
}
193-
194187
// Perform prewarming if enabled (before starting logger to avoid logging prewarm transactions)
195188
if prewarm {
196189
if err := dispatcher.Prewarm(ctx); err != nil {
@@ -200,11 +193,11 @@ func runLoadTest(ctx context.Context, cmd *cobra.Command, args []string) error {
200193

201194
// Start logger (after prewarming to capture only main load test metrics)
202195
s.SpawnBgNamed("logger", func() error { return logger.Run(ctx) })
203-
log.Println("✅ Started statistics logger")
196+
log.Printf("✅ Started statistics logger")
204197

205198
// Start dispatcher for main load test
206199
s.SpawnBgNamed("dispatcher", func() error { return dispatcher.Run(ctx) })
207-
log.Println("✅ Started dispatcher")
200+
log.Printf("✅ Started dispatcher")
208201

209202
// Set up signal handling for graceful shutdown
210203
sigChan := make(chan os.Signal, 1)
@@ -223,10 +216,10 @@ func runLoadTest(ctx context.Context, cmd *cobra.Command, args []string) error {
223216
if trackBlocks {
224217
log.Printf("📝 Track blocks mode: Block data will be collected")
225218
}
226-
log.Println(strings.Repeat("=", 60))
219+
log.Print(strings.Repeat("=", 60))
227220

228221
// Main loop - wait for shutdown signal
229-
if _,err:=utils.Recv(ctx, sigChan); err!=nil {
222+
if _, err := utils.Recv(ctx, sigChan); err != nil {
230223
return err
231224
}
232225
log.Print("\n🛑 Received shutdown signal, stopping gracefully...")

0 commit comments

Comments
 (0)