Commit f409ce75 authored by smartcontracts's avatar smartcontracts Committed by GitHub

fix[l2geth]: off-by-one sometimes breaking replica sync (#1082)

* fix[l2geth]: off-by-one sometimes breaking replica sync

* chore: add changeset
parent 6d7b12b8
---
'@eth-optimism/l2geth': patch
---
Fixes an off-by-one error that would sometimes break replica syncing when stopping and restarting geth.
...@@ -196,7 +196,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus ...@@ -196,7 +196,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
unconfirmed: newUnconfirmedBlocks(eth.BlockChain(), miningLogAtDepth), unconfirmed: newUnconfirmedBlocks(eth.BlockChain(), miningLogAtDepth),
pendingTasks: make(map[common.Hash]*task), pendingTasks: make(map[common.Hash]*task),
txsCh: make(chan core.NewTxsEvent, txChanSize), txsCh: make(chan core.NewTxsEvent, txChanSize),
rollupCh: make(chan core.NewTxsEvent, txChanSize), rollupCh: make(chan core.NewTxsEvent, 1),
chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize), chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
chainSideCh: make(chan core.ChainSideEvent, chainSideChanSize), chainSideCh: make(chan core.ChainSideEvent, chainSideChanSize),
newWorkCh: make(chan *newWorkReq), newWorkCh: make(chan *newWorkReq),
......
...@@ -243,21 +243,22 @@ func (s *SyncService) initializeLatestL1(ctcDeployHeight *big.Int) error { ...@@ -243,21 +243,22 @@ func (s *SyncService) initializeLatestL1(ctcDeployHeight *big.Int) error {
s.SetLatestL1Timestamp(context.Timestamp) s.SetLatestL1Timestamp(context.Timestamp)
s.SetLatestL1BlockNumber(context.BlockNumber) s.SetLatestL1BlockNumber(context.BlockNumber)
} else { } else {
// Prevent underflows
if *index != 0 {
*index = *index - 1
}
log.Info("Found latest index", "index", *index) log.Info("Found latest index", "index", *index)
block := s.bc.GetBlockByNumber(*index) block := s.bc.GetBlockByNumber(*index + 1)
if block == nil { if block == nil {
block = s.bc.CurrentBlock() block = s.bc.CurrentBlock()
idx := block.Number().Uint64() blockNum := block.Number().Uint64()
if idx > *index { if blockNum > *index {
// This is recoverable with a reorg but should never happen // This is recoverable with a reorg but should never happen
return fmt.Errorf("Current block height greater than index") return fmt.Errorf("Current block height greater than index")
} }
s.SetLatestIndex(&idx) var idx *uint64
log.Info("Block not found, resetting index", "new", idx, "old", *index) 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() txs := block.Transactions()
if len(txs) != 1 { if len(txs) != 1 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment