@@ -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
2121type 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
3434func 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
5353func 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
121123func (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
147149func (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
0 commit comments