Skip to content

Commit

Permalink
epoch cache clean (#101)
Browse files Browse the repository at this point in the history
* l2geth: p2p seq check

* chore: modify description and add comments

* feat: add l1fee from IsShanghai fork

* l2geth: l1fee fork disable mgval to balance if insufficient

* fix: block ts0 fixed

* chore: add info log to worker

* feat: split peer block seqset check

* fix: add lock to worker

* feat: clean cachedSeqEpoch when p2p got respan tx

* fix: worker timer reset when non-sequencer model
  • Loading branch information
aiden069 authored Aug 6, 2024
1 parent 97ec4fc commit 4250a8b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions l2geth/miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,20 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
expectSeq, err := w.eth.SyncService().GetTxSequencer(nil, nextBN)
if err != nil {
log.Warn("GetTxSequencer error in worker timer", "err", err)
timer.Reset(recommit)
continue
}
if !w.eth.SyncService().IsSelfSeqAddress(expectSeq) {
log.Warn("Current sequencer incorrect in worker timer, clear pending", "current sequencer", expectSeq.String())
clearPending(w.chain.CurrentBlock().NumberU64())
timer.Reset(recommit)
continue
}
// check startup sync height of L2 RPC
if !w.eth.SyncService().IsAboveStartHeight(nextBN) {
log.Warn("Block number below sync start height in worker timer, clear pending", "block number", nextBN)
clearPending(w.chain.CurrentBlock().NumberU64())
timer.Reset(recommit)
continue
}
}
Expand Down
8 changes: 8 additions & 0 deletions l2geth/rollup/rollup_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type RollupAdapter interface {
SetPreRespan(oldAddress common.Address, newAddress common.Address, number uint64) error
IsPreRespanSequencer(seqAddress string, number uint64) bool
IsNotNextRespanSequencer(seqAddress string, number uint64) bool
RemoveCachedSeqEpoch()
}

// Cached seq epoch, if recommit or block number < start | > end, clear cache with status false
Expand Down Expand Up @@ -416,6 +417,13 @@ func (s *SeqAdapter) GetTxSequencer(tx *types.Transaction, expectIndex uint64) (
return address, err
}

func (s *SeqAdapter) RemoveCachedSeqEpoch() {
s.cachedSeqMux.Lock()
defer s.cachedSeqMux.Unlock()
s.cachedSeqEpoch.Status = false
log.Info("Removed cachedSeqEpoch")
}

func (s *SeqAdapter) CheckPosLayerSynced() (bool, error) {
// get pos layer synced
if s == nil {
Expand Down
18 changes: 18 additions & 0 deletions l2geth/rollup/sync_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,15 @@ func (s *SyncService) applyTransactionToPool(tx *types.Transaction, fromLocal bo
return err
}
}

// clean sequencer epoch cache when respan
if blockNumber >= s.seqAdapter.GetSeqValidHeight() && tx.QueueOrigin() != types.QueueOriginL1ToL2 {
isRespan := s.RollupAdapter().IsRespanCall(tx)
if isRespan {
s.RollupAdapter().RemoveCachedSeqEpoch()
}
}

log.Info("sync from other node applyTransactionToPool finish", "current latest", *s.GetLatestIndex())
return nil
}
Expand Down Expand Up @@ -1578,6 +1587,15 @@ func (s *SyncService) applyTransactionToTip(tx *types.Transaction, fromLocal boo
return err
}
}

// clean sequencer epoch cache when respan
if blockNumber >= s.seqAdapter.GetSeqValidHeight() && tx.QueueOrigin() != types.QueueOriginL1ToL2 {
isRespan := s.RollupAdapter().IsRespanCall(tx)
if isRespan {
s.RollupAdapter().RemoveCachedSeqEpoch()
}
}

log.Info("sync from other node applyTransactionToTip finish", "current latest", *s.GetLatestIndex())
return nil
}
Expand Down

0 comments on commit 4250a8b

Please sign in to comment.