From 26750f6d9b2f514602af33c77b64c8347a98a67f Mon Sep 17 00:00:00 2001 From: erhant Date: Tue, 14 Jul 2026 18:35:56 +0300 Subject: [PATCH] fix(sequencer): fix copilot reviews --- lez/chain_state/DESIGN.md | 14 ++++++++++---- lez/storage/src/sequencer/mod.rs | 4 +++- lez/storage/src/sequencer/tests.rs | 6 ++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lez/chain_state/DESIGN.md b/lez/chain_state/DESIGN.md index 35e9a2b9..cb8595aa 100644 --- a/lez/chain_state/DESIGN.md +++ b/lez/chain_state/DESIGN.md @@ -66,13 +66,19 @@ Shared types moved into the crate: `AcceptOutcome`, `BlockIngestError`, `StallReason`, and `Tip`. ```rust -struct Tip { block_id: u64, hash: HashType, l1_slot: Slot } +struct Tip { block_id: u64, hash: HashType } -enum AcceptOutcome { Applied, AlreadyApplied, Parked(BlockIngestError) } +enum AcceptOutcome { + Applied, + AlreadyApplied, + Parked(BlockIngestError), + RetryableFailure(BlockIngestError), +} ``` -`Tip` carries `l1_slot` (recorded atomically with the tip) because the anchor / -chain-consistency logic keys on the inscription slot, not just `(id, hash)`. +`Tip` will additionally carry `l1_slot` once the anchor layer lands (recorded +atomically with the tip), because the anchor / chain-consistency logic keys on +the inscription slot, not just `(id, hash)`. ## 4. The two-tier `ChainState` diff --git a/lez/storage/src/sequencer/mod.rs b/lez/storage/src/sequencer/mod.rs index cb986e26..bd2364e9 100644 --- a/lez/storage/src/sequencer/mod.rs +++ b/lez/storage/src/sequencer/mod.rs @@ -487,7 +487,9 @@ impl RocksDBIO { if !first { let last_curr_block = self.get_meta_last_block_in_db()?; - if block.header.block_id > last_curr_block { + // `>=` so a same-height overwrite (a reorg replacing the tip block) + // also refreshes the tip hash in `latest_block_meta`. + if block.header.block_id >= last_curr_block { self.put_meta_last_block_in_db_batch(block.header.block_id, batch)?; self.put_meta_latest_block_meta_batch( &BlockMeta { diff --git a/lez/storage/src/sequencer/tests.rs b/lez/storage/src/sequencer/tests.rs index 1473d27e..ea9dc96a 100644 --- a/lez/storage/src/sequencer/tests.rs +++ b/lez/storage/src/sequencer/tests.rs @@ -105,4 +105,10 @@ fn store_followed_block_overwrites_competing_block_at_same_id() { assert_eq!(stored.header.hash, block2b.header.hash); assert!(matches!(stored.bedrock_status, BedrockStatus::Pending)); assert_eq!(stored_balance(&dbio), 300); + + // The tip meta must follow the reorg winner, or a restart seeds the chain + // from the orphaned block's hash. + let meta = dbio.latest_block_meta().unwrap(); + assert_eq!(meta.id, 2); + assert_eq!(meta.hash, block2b.header.hash); }