Skip to content

Commit

Permalink
fix: seq sender oom while have large batch to sync (#15)
Browse files Browse the repository at this point in the history
* update

* update

* update

* update
  • Loading branch information
zjg555543 authored Dec 25, 2024
1 parent 276cbc1 commit bb1c057
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 batchMultiplier = 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*batchMultiplier {
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 bb1c057

Please sign in to comment.