@@ -574,14 +574,22 @@ func (t *simulatorPayloadWorker) waitForReceipt(ctx context.Context, txHash comm
574574 })
575575}
576576
577- func (t * simulatorPayloadWorker ) sendTxs (ctx context.Context ) error {
577+ func (t * simulatorPayloadWorker ) sendTxs (ctx context.Context , pendingTxs int ) ( int , error ) {
578578 txs := make ([]* types.Transaction , 0 , t .numCallers )
579579
580580 gas := t .params .GasLimit - 100_000
581581
582582 sendTxsStartTime := time .Now ()
583583
584- for i := uint64 (0 ); i < uint64 (math .Ceil (float64 (t .numCallsPerBlock )* t .scaleFactor )); i ++ {
584+ targetCalls := uint64 (math .Ceil (float64 (t .numCallsPerBlock ) * t .scaleFactor ))
585+ callsToSend := targetCalls
586+ if uint64 (pendingTxs ) >= targetCalls {
587+ callsToSend = 0
588+ } else {
589+ callsToSend = targetCalls - uint64 (pendingTxs )
590+ }
591+
592+ for i := uint64 (0 ); i < callsToSend ; i ++ {
585593 actual := t .actualNumConfig
586594 expected := t .payloadParams .Mul (float64 (t .numCalls + 1 ) * t .scaleFactor )
587595
@@ -600,7 +608,7 @@ func (t *simulatorPayloadWorker) sendTxs(ctx context.Context) error {
600608 transferTx , err := t .createCallTx (t .transactors [callerIdx ], t .callerKeys [callerIdx ], blockCounts )
601609 if err != nil {
602610 t .log .Error ("Failed to create transfer transaction" , "err" , err )
603- return err
611+ return 0 , err
604612 }
605613
606614 t .gasUsedCache [blockCounts .Hash ()] = transferTx .Gas ()
@@ -625,8 +633,8 @@ func (t *simulatorPayloadWorker) sendTxs(ctx context.Context) error {
625633
626634 t .mempool .AddTransactions (txs )
627635 sendTxsDuration := time .Since (sendTxsStartTime )
628- log .Info ("Send transactions duration" , "duration" , sendTxsDuration , "numCalls " , uint64 ( math . Ceil ( float64 ( t . numCallsPerBlock ) * t . scaleFactor )) )
629- return nil
636+ log .Info ("Send transactions duration" , "duration" , sendTxsDuration , "targetCalls " , targetCalls , "callsSent" , len ( txs ), "pendingTxs" , pendingTxs )
637+ return len ( txs ), nil
630638}
631639
632640func (t * simulatorPayloadWorker ) createCallTx (transactor * bind.TransactOpts , fromPriv * ecdsa.PrivateKey , config * simulatorstats.Stats ) (* types.Transaction , error ) {
@@ -663,10 +671,11 @@ func (t *simulatorPayloadWorker) createDeployTx(fromPriv *ecdsa.PrivateKey) (*co
663671 return & deployAddr , deployTx , nil
664672}
665673
666- func (t * simulatorPayloadWorker ) SendTxs (ctx context.Context ) error {
667- if err := t .sendTxs (ctx ); err != nil {
674+ func (t * simulatorPayloadWorker ) SendTxs (ctx context.Context , pendingTxs int ) (int , error ) {
675+ n , err := t .sendTxs (ctx , pendingTxs )
676+ if err != nil {
668677 t .log .Error ("Failed to send transactions" , "err" , err )
669- return err
678+ return 0 , err
670679 }
671- return nil
680+ return n , nil
672681}
0 commit comments