From f668f3de17140b9d6bcbde0eb0c02b2d3300e893 Mon Sep 17 00:00:00 2001 From: erhant Date: Thu, 9 Jul 2026 20:23:25 +0300 Subject: [PATCH] refactor(indexer): remove now-redundant `last_breakpoint_id` meta cell --- lez/indexer/core/src/block_store.rs | 1 - lez/storage/src/indexer/indexer_cells.rs | 25 +-------------------- lez/storage/src/indexer/mod.rs | 11 ++------- lez/storage/src/indexer/read_once.rs | 10 ++------- lez/storage/src/indexer/tests.rs | 11 +++------ lez/storage/src/indexer/write_atomic.rs | 13 ++--------- lez/storage/src/indexer/write_non_atomic.rs | 6 +---- 7 files changed, 11 insertions(+), 66 deletions(-) diff --git a/lez/indexer/core/src/block_store.rs b/lez/indexer/core/src/block_store.rs index 5298b96d..d88078e9 100644 --- a/lez/indexer/core/src/block_store.rs +++ b/lez/indexer/core/src/block_store.rs @@ -878,7 +878,6 @@ mod accept_tests { // Snapshot at block 100 = genesis + 99 transfers, written with the block. let bp1 = store.dbio.get_breakpoint(1).expect("breakpoint 1 present"); assert_eq!(bp1.get_account_by_id(from).balance, 10000 - 99); - assert_eq!(store.dbio.get_meta_last_breakpoint_id().unwrap(), Some(1)); // The #605 restart: reopening past the boundary must work. drop(store); diff --git a/lez/storage/src/indexer/indexer_cells.rs b/lez/storage/src/indexer/indexer_cells.rs index e00e6faf..ef104f1a 100644 --- a/lez/storage/src/indexer/indexer_cells.rs +++ b/lez/storage/src/indexer/indexer_cells.rs @@ -7,7 +7,7 @@ use crate::{ error::DbError, indexer::{ ACC_NUM_CELL_NAME, BLOCK_HASH_CELL_NAME, BREAKPOINT_CELL_NAME, CF_ACC_META, - CF_BREAKPOINT_NAME, CF_HASH_TO_ID, CF_TX_TO_ID, DB_META_LAST_BREAKPOINT_ID, + CF_BREAKPOINT_NAME, CF_HASH_TO_ID, CF_TX_TO_ID, DB_META_LAST_OBSERVED_L1_LIB_HEADER_ID_IN_DB_KEY, DB_META_STALL_REASON_KEY, DB_META_TIP_SLOT_KEY, DB_META_ZONE_SDK_INDEXER_CURSOR_KEY, TX_HASH_CELL_NAME, }, @@ -36,29 +36,6 @@ impl SimpleWritableCell for LastObservedL1LibHeaderCell { } } -#[derive(Debug, BorshSerialize, BorshDeserialize)] -pub struct LastBreakpointIdCell(pub u64); - -impl SimpleStorableCell for LastBreakpointIdCell { - type KeyParams = (); - - const CELL_NAME: &'static str = DB_META_LAST_BREAKPOINT_ID; - const CF_NAME: &'static str = CF_META_NAME; -} - -impl SimpleReadableCell for LastBreakpointIdCell {} - -impl SimpleWritableCell for LastBreakpointIdCell { - fn value_constructor(&self) -> DbResult> { - borsh::to_vec(&self).map_err(|err| { - DbError::borsh_cast_message( - err, - Some("Failed to serialize last breakpoint id".to_owned()), - ) - }) - } -} - #[derive(BorshDeserialize)] pub struct BreakpointCellOwned(pub V03State); diff --git a/lez/storage/src/indexer/mod.rs b/lez/storage/src/indexer/mod.rs index 5a265d47..0955ef26 100644 --- a/lez/storage/src/indexer/mod.rs +++ b/lez/storage/src/indexer/mod.rs @@ -21,8 +21,6 @@ pub mod write_non_atomic; /// Key base for storing metainformation about id of last observed L1 lib header in db. pub const DB_META_LAST_OBSERVED_L1_LIB_HEADER_ID_IN_DB_KEY: &str = "last_observed_l1_lib_header_in_db"; -/// Key base for storing metainformation about the last breakpoint. -pub const DB_META_LAST_BREAKPOINT_ID: &str = "last_breakpoint_id"; /// Key base for storing the zone-sdk indexer cursor (opaque bytes). pub const DB_META_ZONE_SDK_INDEXER_CURSOR_KEY: &str = "zone_sdk_indexer_cursor"; /// Key base for storing the persisted `Option` diagnostic record (opaque JSON bytes). @@ -89,10 +87,9 @@ impl RocksDBIO { let dbio = Self { db }; - // Seed the genesis snapshot once; reopening must not clobber breakpoint meta. - if dbio.get_meta_last_breakpoint_id()?.is_none() { + // Seed the genesis snapshot once; reopening must not clobber it. + if dbio.get_breakpoint_opt(0)?.is_none() { dbio.put_breakpoint(0, initial_state)?; - dbio.put_meta_last_breakpoint_id(0)?; } Ok(dbio) @@ -160,10 +157,6 @@ impl RocksDBIO { } // walk down to the nearest snapshot that exists - // - // NOTE: we do not use `get_meta_last_breakpoint_id` here because - // it may be stale if the last breakpoint was deleted, and simply - // computing it from `block_id` is enough let target = closest_breakpoint_id(block_id); let mut br_id = target; let mut state = loop { diff --git a/lez/storage/src/indexer/read_once.rs b/lez/storage/src/indexer/read_once.rs index 043c0311..3fbf6026 100644 --- a/lez/storage/src/indexer/read_once.rs +++ b/lez/storage/src/indexer/read_once.rs @@ -3,9 +3,8 @@ use crate::{ DBIO as _, cells::shared_cells::{BlockCell, FirstBlockCell, FirstBlockSetCell, LastBlockCell}, indexer::indexer_cells::{ - AccNumTxCell, BlockHashToBlockIdMapCell, BreakpointCellOwned, LastBreakpointIdCell, - LastObservedL1LibHeaderCell, StallReasonCellOwned, TipSlotCell, TxHashToBlockIdMapCell, - ZoneSdkIndexerCursorCellOwned, + AccNumTxCell, BlockHashToBlockIdMapCell, BreakpointCellOwned, LastObservedL1LibHeaderCell, + StallReasonCellOwned, TipSlotCell, TxHashToBlockIdMapCell, ZoneSdkIndexerCursorCellOwned, }, }; @@ -32,11 +31,6 @@ impl RocksDBIO { Ok(self.get_opt::(())?.is_some()) } - pub fn get_meta_last_breakpoint_id(&self) -> DbResult> { - self.get_opt::(()) - .map(|opt| opt.map(|cell| cell.0)) - } - pub fn get_meta_tip_slot_in_db(&self) -> DbResult> { self.get_opt::(()) .map(|opt| opt.map(|cell| cell.0)) diff --git a/lez/storage/src/indexer/tests.rs b/lez/storage/src/indexer/tests.rs index 7c8f055f..840c99fe 100644 --- a/lez/storage/src/indexer/tests.rs +++ b/lez/storage/src/indexer/tests.rs @@ -58,7 +58,6 @@ fn start_db() { let first_id = dbio.get_meta_first_block_id_in_db().unwrap(); let is_first_set = dbio.get_meta_is_first_block_set().unwrap(); let last_observed_l1_header = dbio.get_meta_last_observed_l1_lib_header_in_db().unwrap(); - let last_br_id = dbio.get_meta_last_breakpoint_id().unwrap(); let last_block = dbio.get_block(1).unwrap(); let breakpoint = dbio.get_breakpoint(0).unwrap(); let final_state = dbio.final_state().unwrap(); @@ -67,7 +66,6 @@ fn start_db() { assert_eq!(first_id, None); assert_eq!(last_observed_l1_header, None); assert!(!is_first_set); - assert_eq!(last_br_id, Some(0)); // TODO: Will be None after we remove hardcoded testnet state assert!(last_block.is_none()); assert_eq!( breakpoint.get_account_by_id(acc1()), @@ -107,7 +105,6 @@ fn one_block_insertion() { .unwrap() .unwrap(); let is_first_set = dbio.get_meta_is_first_block_set().unwrap(); - let last_br_id = dbio.get_meta_last_breakpoint_id().unwrap(); let last_block = dbio.get_block(last_id).unwrap().unwrap(); let breakpoint = dbio.get_breakpoint(0).unwrap(); let final_state = dbio.final_state().unwrap(); @@ -116,7 +113,6 @@ fn one_block_insertion() { assert_eq!(first_id, Some(1)); assert_eq!(last_observed_l1_header, [1; 32]); assert!(is_first_set); - assert_eq!(last_br_id, Some(0)); assert_eq!(last_block.header.hash, block.header.hash); assert_eq!( breakpoint.get_account_by_id(acc1()).balance @@ -198,7 +194,6 @@ fn put_block_stores_breakpoint_in_same_batch() { dbio.put_block(&block, [i; 32], 0, marker.as_ref()).unwrap(); } - assert_eq!(dbio.get_meta_last_breakpoint_id().unwrap(), Some(1)); let bp1 = dbio.get_breakpoint(1).unwrap(); assert_eq!(bp1.get_account_by_id(acc1()).balance, 10000); assert_eq!(bp1.get_account_by_id(acc2()).balance, 20000); @@ -488,12 +483,12 @@ fn account_map() { } #[test] -fn reopen_preserves_breakpoint_meta() { +fn reopen_preserves_seeded_breakpoint() { let temp_dir = tempdir().unwrap(); { let dbio = RocksDBIO::open_or_create(temp_dir.path(), &initial_state()).unwrap(); - dbio.put_meta_last_breakpoint_id(5).unwrap(); + assert!(dbio.get_breakpoint_opt(0).unwrap().is_some()); } // drop releases the RocksDB lock let dbio = RocksDBIO::open_or_create(temp_dir.path(), &initial_state()).unwrap(); - assert_eq!(dbio.get_meta_last_breakpoint_id().unwrap(), Some(5)); + assert!(dbio.get_breakpoint_opt(0).unwrap().is_some()); } diff --git a/lez/storage/src/indexer/write_atomic.rs b/lez/storage/src/indexer/write_atomic.rs index 9cab8755..7cd16e10 100644 --- a/lez/storage/src/indexer/write_atomic.rs +++ b/lez/storage/src/indexer/write_atomic.rs @@ -7,8 +7,8 @@ use crate::{ DBIO as _, cells::shared_cells::{FirstBlockCell, FirstBlockSetCell, LastBlockCell}, indexer::indexer_cells::{ - AccNumTxCell, BlockHashToBlockIdMapCell, BreakpointCellRef, LastBreakpointIdCell, - LastObservedL1LibHeaderCell, TipSlotCell, TxHashToBlockIdMapCell, + AccNumTxCell, BlockHashToBlockIdMapCell, BreakpointCellRef, LastObservedL1LibHeaderCell, + TipSlotCell, TxHashToBlockIdMapCell, }, }; @@ -131,14 +131,6 @@ impl RocksDBIO { self.put_batch(&LastObservedL1LibHeaderCell(l1_lib_header), (), write_batch) } - pub fn put_meta_last_breakpoint_id_batch( - &self, - br_id: u64, - write_batch: &mut WriteBatch, - ) -> DbResult<()> { - self.put_batch(&LastBreakpointIdCell(br_id), (), write_batch) - } - pub fn put_meta_tip_slot_in_db_batch( &self, l1_slot: u64, @@ -239,7 +231,6 @@ impl RocksDBIO { .checked_div(BREAKPOINT_INTERVAL.into()) .expect("Breakpoint interval is not zero"); self.put_batch(&BreakpointCellRef(state), br_id, &mut write_batch)?; - self.put_meta_last_breakpoint_id_batch(br_id, &mut write_batch)?; } self.db.write(write_batch).map_err(|rerr| { diff --git a/lez/storage/src/indexer/write_non_atomic.rs b/lez/storage/src/indexer/write_non_atomic.rs index 382e9d83..214531bc 100644 --- a/lez/storage/src/indexer/write_non_atomic.rs +++ b/lez/storage/src/indexer/write_non_atomic.rs @@ -3,7 +3,7 @@ use crate::{ DBIO as _, cells::shared_cells::{FirstBlockSetCell, LastBlockCell}, indexer::indexer_cells::{ - BreakpointCellRef, LastBreakpointIdCell, LastObservedL1LibHeaderCell, StallReasonCellRef, + BreakpointCellRef, LastObservedL1LibHeaderCell, StallReasonCellRef, ZoneSdkIndexerCursorCellRef, }, }; @@ -23,10 +23,6 @@ impl RocksDBIO { self.put(&LastObservedL1LibHeaderCell(l1_lib_header), ()) } - pub fn put_meta_last_breakpoint_id(&self, br_id: u64) -> DbResult<()> { - self.put(&LastBreakpointIdCell(br_id), ()) - } - pub fn put_meta_is_first_block_set(&self) -> DbResult<()> { self.put(&FirstBlockSetCell(true), ()) }