diff --git a/.changeset/lazy-toes-teach.md b/.changeset/lazy-toes-teach.md new file mode 100644 index 0000000000000..3c482f92504d1 --- /dev/null +++ b/.changeset/lazy-toes-teach.md @@ -0,0 +1,5 @@ +--- +'@eth-optimism/l2geth': patch +--- + +Fixes an off-by-one error that would sometimes break replica syncing when stopping and restarting geth. diff --git a/l2geth/miner/worker.go b/l2geth/miner/worker.go index 2c9a0a177997f..e8da4757e1489 100644 --- a/l2geth/miner/worker.go +++ b/l2geth/miner/worker.go @@ -196,7 +196,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus unconfirmed: newUnconfirmedBlocks(eth.BlockChain(), miningLogAtDepth), pendingTasks: make(map[common.Hash]*task), txsCh: make(chan core.NewTxsEvent, txChanSize), - rollupCh: make(chan core.NewTxsEvent, txChanSize), + rollupCh: make(chan core.NewTxsEvent, 1), chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize), chainSideCh: make(chan core.ChainSideEvent, chainSideChanSize), newWorkCh: make(chan *newWorkReq), diff --git a/l2geth/rollup/sync_service.go b/l2geth/rollup/sync_service.go index b3bcfa952853b..0b71d20193eea 100644 --- a/l2geth/rollup/sync_service.go +++ b/l2geth/rollup/sync_service.go @@ -243,21 +243,22 @@ func (s *SyncService) initializeLatestL1(ctcDeployHeight *big.Int) error { s.SetLatestL1Timestamp(context.Timestamp) s.SetLatestL1BlockNumber(context.BlockNumber) } else { - // Prevent underflows - if *index != 0 { - *index = *index - 1 - } log.Info("Found latest index", "index", *index) - block := s.bc.GetBlockByNumber(*index) + block := s.bc.GetBlockByNumber(*index + 1) if block == nil { block = s.bc.CurrentBlock() - idx := block.Number().Uint64() - if idx > *index { + blockNum := block.Number().Uint64() + if blockNum > *index { // This is recoverable with a reorg but should never happen return fmt.Errorf("Current block height greater than index") } - s.SetLatestIndex(&idx) - log.Info("Block not found, resetting index", "new", idx, "old", *index) + var idx *uint64 + if blockNum > 0 { + num := blockNum - 1 + idx = &num + } + s.SetLatestIndex(idx) + log.Info("Block not found, resetting index", "new", stringify(idx), "old", *index) } txs := block.Transactions() if len(txs) != 1 {