mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-06-11 11:39:34 +00:00
initial removals
This commit is contained in:
parent
feb6cb7f92
commit
38c826ae73
@ -12,7 +12,6 @@ pub type BlockHash = HashType;
|
||||
pub struct BlockMeta {
|
||||
pub id: BlockId,
|
||||
pub hash: BlockHash,
|
||||
pub msg_id: MantleMsgId,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
@ -3,7 +3,7 @@ use std::{collections::HashMap, path::Path, sync::Arc};
|
||||
use anyhow::{Context as _, Result};
|
||||
use common::{
|
||||
HashType,
|
||||
block::{Block, BlockMeta, MantleMsgId},
|
||||
block::{Block, BlockMeta},
|
||||
transaction::LeeTransaction,
|
||||
};
|
||||
use lee::V03State;
|
||||
@ -56,16 +56,10 @@ impl SequencerStore {
|
||||
pub fn create_db_with_genesis(
|
||||
location: &Path,
|
||||
genesis_block: &Block,
|
||||
genesis_msg_id: MantleMsgId,
|
||||
genesis_state: &V03State,
|
||||
signing_key: lee::PrivateKey,
|
||||
) -> DbResult<Self> {
|
||||
let dbio = Arc::new(RocksDBIO::create(
|
||||
location,
|
||||
genesis_block,
|
||||
genesis_msg_id,
|
||||
genesis_state,
|
||||
)?);
|
||||
let dbio = Arc::new(RocksDBIO::create(location, genesis_block, genesis_state)?);
|
||||
let genesis_id = dbio.get_meta_first_block_in_db()?;
|
||||
let tx_hash_to_block_map = block_to_transactions_map(genesis_block);
|
||||
|
||||
@ -134,14 +128,9 @@ impl SequencerStore {
|
||||
self.dbio.get_all_blocks()
|
||||
}
|
||||
|
||||
pub(crate) fn update(
|
||||
&mut self,
|
||||
block: &Block,
|
||||
msg_id: MantleMsgId,
|
||||
state: &V03State,
|
||||
) -> DbResult<()> {
|
||||
pub(crate) fn update(&mut self, block: &Block, state: &V03State) -> DbResult<()> {
|
||||
let new_transactions_map = block_to_transactions_map(block);
|
||||
self.dbio.atomic_update(block, msg_id, state)?;
|
||||
self.dbio.atomic_update(block, state)?;
|
||||
self.tx_hash_to_block_map.extend(new_transactions_map);
|
||||
Ok(())
|
||||
}
|
||||
@ -225,7 +214,6 @@ mod tests {
|
||||
let mut node_store = SequencerStore::create_db_with_genesis(
|
||||
path,
|
||||
&genesis_block,
|
||||
[0; 32],
|
||||
&testnet_initial_state::initial_state(),
|
||||
signing_key,
|
||||
)
|
||||
@ -239,7 +227,7 @@ mod tests {
|
||||
assert_eq!(None, retrieved_tx);
|
||||
// Add the block with the transaction
|
||||
let dummy_state = V03State::new_with_genesis_accounts(&[], vec![], 0);
|
||||
node_store.update(&block, [1; 32], &dummy_state).unwrap();
|
||||
node_store.update(&block, &dummy_state).unwrap();
|
||||
// Try again
|
||||
let retrieved_tx = node_store.get_transaction_by_hash(tx.hash());
|
||||
assert_eq!(Some(tx), retrieved_tx);
|
||||
@ -265,7 +253,6 @@ mod tests {
|
||||
let node_store = SequencerStore::create_db_with_genesis(
|
||||
path,
|
||||
&genesis_block,
|
||||
[0; 32],
|
||||
&testnet_initial_state::initial_state(),
|
||||
signing_key,
|
||||
)
|
||||
@ -274,7 +261,6 @@ mod tests {
|
||||
// Verify that initially the latest block hash equals genesis hash
|
||||
let latest_meta = node_store.latest_block_meta().unwrap();
|
||||
assert_eq!(latest_meta.hash, genesis_hash);
|
||||
assert_eq!(latest_meta.msg_id, [0; 32]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -295,7 +281,6 @@ mod tests {
|
||||
let mut node_store = SequencerStore::create_db_with_genesis(
|
||||
path,
|
||||
&genesis_block,
|
||||
[0; 32],
|
||||
&testnet_initial_state::initial_state(),
|
||||
signing_key,
|
||||
)
|
||||
@ -305,17 +290,13 @@ mod tests {
|
||||
let tx = common::test_utils::produce_dummy_empty_transaction();
|
||||
let block = common::test_utils::produce_dummy_block(1, None, vec![tx]);
|
||||
let block_hash = block.header.hash;
|
||||
let block_msg_id = [1; 32];
|
||||
|
||||
let dummy_state = V03State::new_with_genesis_accounts(&[], vec![], 0);
|
||||
node_store
|
||||
.update(&block, block_msg_id, &dummy_state)
|
||||
.unwrap();
|
||||
node_store.update(&block, &dummy_state).unwrap();
|
||||
|
||||
// Verify that the latest block meta now equals the new block's hash and msg_id
|
||||
// Verify that the latest block meta now equals the new block's hash
|
||||
let latest_meta = node_store.latest_block_meta().unwrap();
|
||||
assert_eq!(latest_meta.hash, block_hash);
|
||||
assert_eq!(latest_meta.msg_id, block_msg_id);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -336,7 +317,6 @@ mod tests {
|
||||
let mut node_store = SequencerStore::create_db_with_genesis(
|
||||
path,
|
||||
&genesis_block,
|
||||
[0; 32],
|
||||
&testnet_initial_state::initial_state(),
|
||||
signing_key,
|
||||
)
|
||||
@ -348,7 +328,7 @@ mod tests {
|
||||
let block_id = block.header.block_id;
|
||||
|
||||
let dummy_state = V03State::new_with_genesis_accounts(&[], vec![], 0);
|
||||
node_store.update(&block, [1; 32], &dummy_state).unwrap();
|
||||
node_store.update(&block, &dummy_state).unwrap();
|
||||
|
||||
// Verify initial status is Pending
|
||||
let retrieved_block = node_store.get_block_at_id(block_id).unwrap().unwrap();
|
||||
@ -389,7 +369,6 @@ mod tests {
|
||||
let mut node_store = SequencerStore::create_db_with_genesis(
|
||||
path,
|
||||
&genesis_block,
|
||||
[0; 32],
|
||||
&testnet_initial_state::initial_state(),
|
||||
signing_key.clone(),
|
||||
)
|
||||
@ -398,11 +377,7 @@ mod tests {
|
||||
// Add a new block
|
||||
let block = common::test_utils::produce_dummy_block(1, None, vec![tx.clone()]);
|
||||
node_store
|
||||
.update(
|
||||
&block,
|
||||
[1; 32],
|
||||
&V03State::new_with_genesis_accounts(&[], vec![], 0),
|
||||
)
|
||||
.update(&block, &V03State::new_with_genesis_accounts(&[], vec![], 0))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
|
||||
@ -96,9 +96,6 @@ impl<BP: BlockPublisherTrait> SequencerCore<BP> {
|
||||
db_path.display()
|
||||
);
|
||||
|
||||
// TODO: Remove msg_id from BlockMeta — it is no longer needed now that
|
||||
// zone-sdk manages L1 settlement state via its own checkpoint.
|
||||
let genesis_msg_id = [0; 32];
|
||||
let genesis_parent_msg_id = [0; 32];
|
||||
let (genesis_state, genesis_txs) = build_genesis_state(&config);
|
||||
|
||||
@ -114,7 +111,6 @@ impl<BP: BlockPublisherTrait> SequencerCore<BP> {
|
||||
let store = SequencerStore::create_db_with_genesis(
|
||||
&db_path,
|
||||
&genesis_block,
|
||||
genesis_msg_id,
|
||||
&genesis_state,
|
||||
signing_key,
|
||||
)
|
||||
@ -275,16 +271,12 @@ impl<BP: BlockPublisherTrait> SequencerCore<BP> {
|
||||
deposit_event_ids,
|
||||
} = block_with_meta;
|
||||
|
||||
// TODO: Remove msg_id from store.update — it is no longer needed now that
|
||||
// zone-sdk manages L1 settlement state via its own checkpoint.
|
||||
let placeholder_msg_id = [0_u8; 32];
|
||||
|
||||
self.block_publisher
|
||||
.publish_block(&block)
|
||||
.await
|
||||
.context("Failed to publish block to Bedrock")?;
|
||||
|
||||
self.store.update(&block, placeholder_msg_id, &self.state)?;
|
||||
self.store.update(&block, &self.state)?;
|
||||
|
||||
let updated_deposits = self
|
||||
.store
|
||||
@ -841,11 +833,9 @@ mod tests {
|
||||
};
|
||||
let genesis_block = genesis_hashable_data.into_pending_block(&signing_key, [0; 32]);
|
||||
|
||||
let expected_msg_id = [7; 32];
|
||||
SequencerStore::create_db_with_genesis(
|
||||
&config.home.join("rocksdb"),
|
||||
&genesis_block,
|
||||
expected_msg_id,
|
||||
&genesis_state,
|
||||
signing_key,
|
||||
)
|
||||
@ -853,10 +843,8 @@ mod tests {
|
||||
|
||||
let (sequencer, _mempool_handle) =
|
||||
SequencerCoreWithMockClients::start_from_config(config).await;
|
||||
let latest_meta = sequencer.store.latest_block_meta().unwrap();
|
||||
|
||||
assert_eq!(latest_meta.msg_id, expected_msg_id);
|
||||
assert_eq!(sequencer.chain_height, 1);
|
||||
assert!(sequencer.store.latest_block_meta().is_ok());
|
||||
}
|
||||
|
||||
#[should_panic(expected = "Failed to open database")]
|
||||
|
||||
@ -2,7 +2,7 @@ use std::{path::Path, sync::Arc};
|
||||
|
||||
use common::{
|
||||
HashType,
|
||||
block::{BedrockStatus, Block, BlockMeta, MantleMsgId},
|
||||
block::{BedrockStatus, Block, BlockMeta},
|
||||
};
|
||||
use lee::V03State;
|
||||
use rocksdb::{
|
||||
@ -54,12 +54,7 @@ impl RocksDBIO {
|
||||
Self::open_inner(path, &db_opts)
|
||||
}
|
||||
|
||||
pub fn create(
|
||||
path: &Path,
|
||||
genesis_block: &Block,
|
||||
genesis_msg_id: MantleMsgId,
|
||||
genesis_state: &V03State,
|
||||
) -> DbResult<Self> {
|
||||
pub fn create(path: &Path, genesis_block: &Block, genesis_state: &V03State) -> DbResult<Self> {
|
||||
let mut db_opts = Options::default();
|
||||
db_opts.create_missing_column_families(true);
|
||||
db_opts.create_if_missing(true);
|
||||
@ -69,14 +64,13 @@ impl RocksDBIO {
|
||||
if !is_start_set {
|
||||
let block_id = genesis_block.header.block_id;
|
||||
// TODO: Shouldn't this be atomic (batched)?
|
||||
dbio.put_meta_first_block_in_db(genesis_block, genesis_msg_id)?;
|
||||
dbio.put_meta_first_block_in_db(genesis_block)?;
|
||||
dbio.put_meta_is_first_block_set()?;
|
||||
dbio.put_meta_last_block_in_db(block_id)?;
|
||||
dbio.put_meta_last_finalized_block_id(None)?;
|
||||
dbio.put_meta_latest_block_meta(&BlockMeta {
|
||||
id: genesis_block.header.block_id,
|
||||
hash: genesis_block.header.hash,
|
||||
msg_id: genesis_msg_id,
|
||||
})?;
|
||||
dbio.put_lee_state_in_db(genesis_state)?;
|
||||
}
|
||||
@ -168,7 +162,7 @@ impl RocksDBIO {
|
||||
self.put_batch(&LEEStateCellRef(state), (), batch)
|
||||
}
|
||||
|
||||
pub fn put_meta_first_block_in_db(&self, block: &Block, msg_id: MantleMsgId) -> DbResult<()> {
|
||||
pub fn put_meta_first_block_in_db(&self, block: &Block) -> DbResult<()> {
|
||||
let cf_meta = self.meta_column();
|
||||
self.db
|
||||
.put_cf(
|
||||
@ -189,7 +183,7 @@ impl RocksDBIO {
|
||||
.map_err(|rerr| DbError::rocksdb_cast_message(rerr, None))?;
|
||||
|
||||
let mut batch = WriteBatch::default();
|
||||
self.put_block(block, msg_id, true, &mut batch)?;
|
||||
self.put_block(block, true, &mut batch)?;
|
||||
self.db.write(batch).map_err(|rerr| {
|
||||
DbError::rocksdb_cast_message(
|
||||
rerr,
|
||||
@ -312,13 +306,7 @@ impl RocksDBIO {
|
||||
Ok(removed)
|
||||
}
|
||||
|
||||
pub fn put_block(
|
||||
&self,
|
||||
block: &Block,
|
||||
msg_id: MantleMsgId,
|
||||
first: bool,
|
||||
batch: &mut WriteBatch,
|
||||
) -> DbResult<()> {
|
||||
pub fn put_block(&self, block: &Block, first: bool, batch: &mut WriteBatch) -> DbResult<()> {
|
||||
let cf_block = self.block_column();
|
||||
|
||||
if !first {
|
||||
@ -330,7 +318,6 @@ impl RocksDBIO {
|
||||
&BlockMeta {
|
||||
id: block.header.block_id,
|
||||
hash: block.header.hash,
|
||||
msg_id,
|
||||
},
|
||||
batch,
|
||||
)?;
|
||||
@ -452,15 +439,10 @@ impl RocksDBIO {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn atomic_update(
|
||||
&self,
|
||||
block: &Block,
|
||||
msg_id: MantleMsgId,
|
||||
state: &V03State,
|
||||
) -> DbResult<()> {
|
||||
pub fn atomic_update(&self, block: &Block, state: &V03State) -> DbResult<()> {
|
||||
let block_id = block.header.block_id;
|
||||
let mut batch = WriteBatch::default();
|
||||
self.put_block(block, msg_id, false, &mut batch)?;
|
||||
self.put_block(block, false, &mut batch)?;
|
||||
self.put_lee_state_in_db_batch(state, &mut batch)?;
|
||||
self.db.write(batch).map_err(|rerr| {
|
||||
DbError::rocksdb_cast_message(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user