@@ -26,6 +26,7 @@ import (
2626 "github.com/ethereum/go-ethereum/log"
2727 "github.com/ethereum/go-ethereum/rpc"
2828 "github.com/pkg/errors"
29+ "golang.org/x/sync/errgroup"
2930)
3031
3132// SequencerConsensusClient is a fake consensus client that generates blocks on a timer.
@@ -208,28 +209,42 @@ func (f *SequencerConsensusClient) Propose(ctx context.Context, blockMetrics *me
208209 sendCallsPerBatch := 100
209210 batches := (len (sendTxs ) + sendCallsPerBatch - 1 ) / sendCallsPerBatch
210211
211- for i := 0 ; i < batches ; i ++ {
212- batch := sendTxs [i * sendCallsPerBatch : min ((i + 1 )* sendCallsPerBatch , len (sendTxs ))]
213- results := make ([]interface {}, len (batch ))
214-
215- batchCall := make ([]rpc.BatchElem , len (batch ))
216- for j , tx := range batch {
217- batchCall [j ] = rpc.BatchElem {
218- Method : "eth_sendRawTransaction" ,
219- Args : []interface {}{hexutil .Encode (tx )},
220- Result : & results [j ],
221- }
212+ // Process batches in parallel, 4 at a time
213+ parallelBatches := 4
214+ for i := 0 ; i < batches ; i += parallelBatches {
215+ g , gCtx := errgroup .WithContext (ctx )
216+
217+ for j := 0 ; j < parallelBatches && i + j < batches ; j ++ {
218+ batchIdx := i + j
219+ g .Go (func () error {
220+ batch := sendTxs [batchIdx * sendCallsPerBatch : min ((batchIdx + 1 )* sendCallsPerBatch , len (sendTxs ))]
221+ results := make ([]interface {}, len (batch ))
222+
223+ batchCall := make ([]rpc.BatchElem , len (batch ))
224+ for k , tx := range batch {
225+ batchCall [k ] = rpc.BatchElem {
226+ Method : "eth_sendRawTransaction" ,
227+ Args : []interface {}{hexutil .Encode (tx )},
228+ Result : & results [k ],
229+ }
230+ }
231+
232+ err := f .client .Client ().BatchCallContext (gCtx , batchCall )
233+ if err != nil {
234+ return errors .Wrap (err , "failed to send transactions" )
235+ }
236+
237+ for _ , tx := range batchCall {
238+ if tx .Error != nil {
239+ return errors .Wrapf (tx .Error , "failed to send transaction %#v" , tx .Args [0 ])
240+ }
241+ }
242+ return nil
243+ })
222244 }
223245
224- err := f .client .Client ().BatchCallContext (ctx , batchCall )
225- if err != nil {
226- return nil , errors .Wrap (err , "failed to send transactions" )
227- }
228-
229- for _ , tx := range batchCall {
230- if tx .Error != nil {
231- return nil , errors .Wrapf (tx .Error , "failed to send transaction %#v" , tx .Args [0 ])
232- }
246+ if err := g .Wait (); err != nil {
247+ return nil , err
233248 }
234249 }
235250
0 commit comments