Commit 5e4eaea1 authored by Georgios Konstantopoulos's avatar Georgios Konstantopoulos Committed by GitHub

fix(sync-service): prevent underflows (#1015)

* fix(sync-service): prevent underflows

* chore: add changeset

* chore: remove dead confirmation depth

* chore: remove eth1conf depth from rollup config
parent b355be0b
---
'@eth-optimism/l2geth': patch
---
fix potential underflow when launching the chain when the last verified index is 0
......@@ -10,8 +10,6 @@ import (
type Config struct {
// Maximum calldata size for a Queue Origin Sequencer Tx
MaxCallDataSize int
// Number of confs before applying a L1 to L2 tx
Eth1ConfirmationDepth uint64
// Verifier mode
IsVerifier bool
// Enable the sync service
......
......@@ -53,7 +53,6 @@ type SyncService struct {
syncing atomic.Value
chainHeadSub event.Subscription
OVMContext OVMContext
confirmationDepth uint64
pollInterval time.Duration
timestampRefreshThreshold time.Duration
chainHeadCh chan core.ChainHeadEvent
......@@ -103,7 +102,6 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co
cancel: cancel,
verifier: cfg.IsVerifier,
enable: cfg.Eth1SyncServiceEnable,
confirmationDepth: cfg.Eth1ConfirmationDepth,
syncing: atomic.Value{},
bc: bc,
txpool: txpool,
......@@ -244,8 +242,12 @@ 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 - 1)
block := s.bc.GetBlockByNumber(*index)
if block == nil {
block = s.bc.CurrentBlock()
idx := block.Number().Uint64()
......@@ -254,11 +256,12 @@ func (s *SyncService) initializeLatestL1(ctcDeployHeight *big.Int) error {
return fmt.Errorf("Current block height greater than index")
}
s.SetLatestIndex(&idx)
log.Info("Block not found, resetting index", "new", idx, "old", *index-1)
log.Info("Block not found, resetting index", "new", idx, "old", *index)
}
txs := block.Transactions()
if len(txs) != 1 {
log.Error("Unexpected number of transactions in block: %d", len(txs))
log.Error("Unexpected number of transactions in block", "count", len(txs))
panic("Cannot recover OVM Context")
}
tx := txs[0]
s.SetLatestL1Timestamp(tx.L1Timestamp())
......
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