Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zjg555543 committed Dec 18, 2024
1 parent beb7f7f commit 2ec4b7e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions sequencesender/sequencesender.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
)

const ten = 10
const multipleBatchSize = 5

// EthTxManager represents the eth tx manager interface
type EthTxManager interface {
Expand Down Expand Up @@ -176,6 +177,11 @@ func (s *SequenceSender) batchRetrieval(ctx context.Context) error {
s.logger.Info("context cancelled, stopping batch retrieval")
return ctx.Err()
default:
if s.checkWait() {
<-ticker.C
continue
}

// Try to retrieve batch from RPC
rpcBatch, err := s.rpcClient.GetBatch(currentBatchNumber)
if err != nil {
Expand Down Expand Up @@ -206,6 +212,17 @@ func (s *SequenceSender) batchRetrieval(ctx context.Context) error {
}
}

func (s *SequenceSender) checkWait() bool {
s.mutexSequence.Lock()
defer s.mutexSequence.Unlock()

if uint64(len(s.sequenceList)) >= s.cfg.MaxBatchesForL1*multipleBatchSize {
s.logger.Infof("Sequence list is full: %d, waiting to sync batch from rpc.", len(s.sequenceList))
return true
}
return false
}

func (s *SequenceSender) populateSequenceData(rpcBatch *types.RPCBatch, batchNumber uint64) error {
s.mutexSequence.Lock()
defer s.mutexSequence.Unlock()
Expand Down

0 comments on commit 2ec4b7e

Please sign in to comment.