@@ -135,7 +135,6 @@ func (s *Spammer) Spam(ctx context.Context, sh SpamHelper, terminate bool, symbo
135
135
return err
136
136
}
137
137
138
- var fundsL sync.Mutex
139
138
// distribute funds
140
139
accounts , funds , factories , err := s .distributeFunds (ctx , cli , parser , feePerTx , sh )
141
140
if err != nil {
@@ -148,23 +147,47 @@ func (s *Spammer) Spam(ctx context.Context, sh SpamHelper, terminate bool, symbo
148
147
return err
149
148
}
150
149
151
- // make sure we can exit gracefully & return funds
152
- signals := make (chan os.Signal , 2 )
153
- signal .Notify (signals , syscall .SIGINT , syscall .SIGTERM )
154
-
155
150
cctx , cancel := context .WithCancel (ctx )
156
151
defer cancel ()
152
+
157
153
for _ , issuer := range issuers {
158
154
issuer .Start (cctx )
159
155
}
160
156
161
157
// set logging
162
158
issuers [0 ].logStats (cctx )
163
159
164
- // Broadcast txs
160
+ // broadcast transactions
161
+ s .broadcast (cctx , cancel , sh , accounts , funds , factories , issuers , feePerTx , terminate )
162
+
163
+ maxUnits , err = chain .EstimateUnits (parser .Rules (time .Now ().UnixMilli ()), actions , factory )
164
+ if err != nil {
165
+ return err
166
+ }
167
+ return s .returnFunds (ctx , cli , parser , maxUnits , sh , accounts , factories , funds , symbol )
168
+ }
169
+
170
+ func (s Spammer ) broadcast (
171
+ ctx context.Context ,
172
+ cancel context.CancelFunc ,
173
+ sh SpamHelper ,
174
+ accounts []* auth.PrivateKey ,
175
+
176
+ funds map [codec.Address ]uint64 ,
177
+ factories []chain.AuthFactory ,
178
+ issuers []* issuer ,
179
+
180
+ feePerTx uint64 ,
181
+ terminate bool ,
182
+ ) {
183
+ // make sure we can exit gracefully & return funds
184
+ signals := make (chan os.Signal , 2 )
185
+ signal .Notify (signals , syscall .SIGINT , syscall .SIGTERM )
186
+
165
187
var (
166
188
// Do not call this function concurrently (math.Rand is not safe for concurrent use)
167
- z = rand .NewZipf (s .zipfSeed , s .sZipf , s .vZipf , uint64 (s .numAccounts )- 1 )
189
+ z = rand .NewZipf (s .zipfSeed , s .sZipf , s .vZipf , uint64 (s .numAccounts )- 1 )
190
+ fundsL = sync.Mutex {}
168
191
169
192
it = time .NewTimer (0 )
170
193
currentTarget = min (s .txsPerSecond , s .minTxsPerSecond )
@@ -226,7 +249,7 @@ func (s *Spammer) Spam(ctx context.Context, sh SpamHelper, terminate bool, symbo
226
249
227
250
// Send transaction
228
251
actions := sh .GetTransfer (recipient , amountToTransfer , uniqueBytes ())
229
- return issuer .Send (cctx , actions , factory , feePerTx )
252
+ return issuer .Send (ctx , actions , factory , feePerTx )
230
253
})
231
254
}
232
255
@@ -256,7 +279,7 @@ func (s *Spammer) Spam(ctx context.Context, sh SpamHelper, terminate bool, symbo
256
279
utils .Outf ("{{cyan}}increasing target tps:{{/}} %d\n " , currentTarget )
257
280
consecutiveUnderBacklog = 0
258
281
}
259
- case <- cctx .Done ():
282
+ case <- ctx .Done ():
260
283
stop = true
261
284
utils .Outf ("{{yellow}}context canceled{{/}}\n " )
262
285
case <- signals :
@@ -265,14 +288,10 @@ func (s *Spammer) Spam(ctx context.Context, sh SpamHelper, terminate bool, symbo
265
288
cancel ()
266
289
}
267
290
}
291
+
268
292
// Wait for all issuers to finish
269
293
utils .Outf ("{{yellow}}waiting for issuers to return{{/}}\n " )
270
294
issuerWg .Wait ()
271
- maxUnits , err = chain .EstimateUnits (parser .Rules (time .Now ().UnixMilli ()), actions , factory )
272
- if err != nil {
273
- return err
274
- }
275
- return s .returnFunds (ctx , cli , parser , maxUnits , sh , accounts , factories , funds , symbol )
276
295
}
277
296
278
297
func (s * Spammer ) logZipf (zipfSeed * rand.Rand ) {
0 commit comments