mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-07-10 07:50:11 +00:00
refactor(indexer): remove now-redundant last_breakpoint_id meta cell
This commit is contained in:
parent
3bfa210eac
commit
f668f3de17
@ -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);
|
||||
|
||||
@ -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<Vec<u8>> {
|
||||
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);
|
||||
|
||||
|
||||
@ -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<StallReason>` 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 {
|
||||
|
||||
@ -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::<FirstBlockSetCell>(())?.is_some())
|
||||
}
|
||||
|
||||
pub fn get_meta_last_breakpoint_id(&self) -> DbResult<Option<u64>> {
|
||||
self.get_opt::<LastBreakpointIdCell>(())
|
||||
.map(|opt| opt.map(|cell| cell.0))
|
||||
}
|
||||
|
||||
pub fn get_meta_tip_slot_in_db(&self) -> DbResult<Option<u64>> {
|
||||
self.get_opt::<TipSlotCell>(())
|
||||
.map(|opt| opt.map(|cell| cell.0))
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
@ -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| {
|
||||
|
||||
@ -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), ())
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user