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 ( ...@@ -10,8 +10,6 @@ import (
type Config struct { type Config struct {
// Maximum calldata size for a Queue Origin Sequencer Tx // Maximum calldata size for a Queue Origin Sequencer Tx
MaxCallDataSize int MaxCallDataSize int
// Number of confs before applying a L1 to L2 tx
Eth1ConfirmationDepth uint64
// Verifier mode // Verifier mode
IsVerifier bool IsVerifier bool
// Enable the sync service // Enable the sync service
......
...@@ -53,7 +53,6 @@ type SyncService struct { ...@@ -53,7 +53,6 @@ type SyncService struct {
syncing atomic.Value syncing atomic.Value
chainHeadSub event.Subscription chainHeadSub event.Subscription
OVMContext OVMContext OVMContext OVMContext
confirmationDepth uint64
pollInterval time.Duration pollInterval time.Duration
timestampRefreshThreshold time.Duration timestampRefreshThreshold time.Duration
chainHeadCh chan core.ChainHeadEvent chainHeadCh chan core.ChainHeadEvent
...@@ -103,7 +102,6 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co ...@@ -103,7 +102,6 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co
cancel: cancel, cancel: cancel,
verifier: cfg.IsVerifier, verifier: cfg.IsVerifier,
enable: cfg.Eth1SyncServiceEnable, enable: cfg.Eth1SyncServiceEnable,
confirmationDepth: cfg.Eth1ConfirmationDepth,
syncing: atomic.Value{}, syncing: atomic.Value{},
bc: bc, bc: bc,
txpool: txpool, txpool: txpool,
...@@ -244,8 +242,12 @@ func (s *SyncService) initializeLatestL1(ctcDeployHeight *big.Int) error { ...@@ -244,8 +242,12 @@ 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 - 1) block := s.bc.GetBlockByNumber(*index)
if block == nil { if block == nil {
block = s.bc.CurrentBlock() block = s.bc.CurrentBlock()
idx := block.Number().Uint64() idx := block.Number().Uint64()
...@@ -254,11 +256,12 @@ func (s *SyncService) initializeLatestL1(ctcDeployHeight *big.Int) error { ...@@ -254,11 +256,12 @@ func (s *SyncService) initializeLatestL1(ctcDeployHeight *big.Int) error {
return fmt.Errorf("Current block height greater than index") return fmt.Errorf("Current block height greater than index")
} }
s.SetLatestIndex(&idx) 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() txs := block.Transactions()
if len(txs) != 1 { 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] tx := txs[0]
s.SetLatestL1Timestamp(tx.L1Timestamp()) 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