From 2b51f7ba06538a0250759b70ad16dda7453af5eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erce=20Can=20Bekt=C3=BCre?= <47954181+ercecan@users.noreply.github.com> Date: Thu, 19 Dec 2024 14:27:28 +0300 Subject: [PATCH] Cleanup ledgerdb (#1623) --- bin/citrea/src/rollup/mod.rs | 15 +- .../tests/bitcoin_e2e/batch_prover_test.rs | 2 +- bin/citrea/tests/e2e/sequencer_behaviour.rs | 2 +- crates/batch-prover/src/da_block_handler.rs | 23 ++- crates/batch-prover/src/proving.rs | 9 +- crates/batch-prover/src/runner.rs | 16 +- crates/common/src/rpc/mod.rs | 9 +- crates/common/src/utils.rs | 10 +- crates/fullnode/src/da_block_handler.rs | 18 +- crates/fullnode/src/runner.rs | 6 +- crates/sequencer/src/commitment/controller.rs | 14 +- crates/sequencer/src/commitment/mod.rs | 4 +- crates/sequencer/src/runner.rs | 4 +- .../full-node/db/sov-db/src/ledger_db/mod.rs | 159 +++++------------- .../full-node/db/sov-db/src/ledger_db/rpc.rs | 25 +-- .../db/sov-db/src/ledger_db/traits.rs | 59 +++---- .../full-node/db/sov-db/src/schema/tables.rs | 41 +---- .../full-node/db/sov-db/src/schema/types.rs | 43 +---- .../rollup-interface/src/node/rpc/mod.rs | 17 -- 19 files changed, 159 insertions(+), 317 deletions(-) diff --git a/bin/citrea/src/rollup/mod.rs b/bin/citrea/src/rollup/mod.rs index 964c16ccb..fc186aa35 100644 --- a/bin/citrea/src/rollup/mod.rs +++ b/bin/citrea/src/rollup/mod.rs @@ -13,7 +13,7 @@ use jsonrpsee::RpcModule; use sov_db::ledger_db::migrations::LedgerDBMigrator; use sov_db::ledger_db::{LedgerDB, SharedLedgerOps}; use sov_db::rocks_db_config::RocksdbConfig; -use sov_db::schema::types::BatchNumber; +use sov_db::schema::types::SoftConfirmationNumber; use sov_modules_api::Spec; use sov_modules_rollup_blueprint::RollupBlueprint; use sov_modules_stf_blueprint::{Runtime as RuntimeTrait, StfBlueprint}; @@ -123,7 +123,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { .get_head_soft_confirmation() .map_err(|e| anyhow!("Failed to get head soft confirmation: {}", e))? .map(|(l2_height, _)| l2_height) - .unwrap_or(BatchNumber(0)); + .unwrap_or(SoftConfirmationNumber(0)); let mut fork_manager = ForkManager::new(FORKS, current_l2_height.0); fork_manager.register_handler(Box::new(ledger_db.clone())); @@ -254,7 +254,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { .get_head_soft_confirmation() .map_err(|e| anyhow!("Failed to get head soft confirmation: {}", e))? .map(|(l2_height, _)| l2_height) - .unwrap_or(BatchNumber(0)); + .unwrap_or(SoftConfirmationNumber(0)); let mut fork_manager = ForkManager::new(FORKS, current_l2_height.0); fork_manager.register_handler(Box::new(ledger_db.clone())); @@ -389,12 +389,11 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { let elfs_by_spec = self.get_batch_proof_elfs(); let current_l2_height = ledger_db - .get_head_soft_confirmation() + .get_head_soft_confirmation_height() .map_err(|e| anyhow!("Failed to get head soft confirmation: {}", e))? - .map(|(l2_height, _)| l2_height) - .unwrap_or(BatchNumber(0)); + .unwrap_or(0); - let mut fork_manager = ForkManager::new(FORKS, current_l2_height.0); + let mut fork_manager = ForkManager::new(FORKS, current_l2_height); fork_manager.register_handler(Box::new(ledger_db.clone())); let runner = CitreaBatchProver::new( @@ -488,7 +487,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { .get_head_soft_confirmation() .map_err(|e| anyhow!("Failed to get head soft confirmation: {}", e))? .map(|(l2_height, _)| l2_height) - .unwrap_or(BatchNumber(0)); + .unwrap_or(SoftConfirmationNumber(0)); let mut fork_manager = ForkManager::new(FORKS, current_l2_height.0); fork_manager.register_handler(Box::new(ledger_db.clone())); diff --git a/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs b/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs index f70757632..cd0797981 100644 --- a/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs +++ b/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs @@ -291,7 +291,7 @@ impl TestCase for SkipPreprovenCommitmentsTest { // Wait for the full node to see all process verify and store all batch proofs full_node.wait_for_l1_height(finalized_height, None).await?; - let proofs = wait_for_zkproofs(full_node, finalized_height, None) + let proofs = wait_for_zkproofs(full_node, finalized_height, Some(Duration::from_secs(600))) .await .unwrap(); diff --git a/bin/citrea/tests/e2e/sequencer_behaviour.rs b/bin/citrea/tests/e2e/sequencer_behaviour.rs index 73f0754fd..34b2a91f6 100644 --- a/bin/citrea/tests/e2e/sequencer_behaviour.rs +++ b/bin/citrea/tests/e2e/sequencer_behaviour.rs @@ -425,7 +425,7 @@ async fn test_gas_limit_too_high() { assert_eq!(block_from_sequencer.header.hash, block.header.hash); seq_test_client.send_publish_batch_request().await; - wait_for_l2_block(&full_node_test_client, 2, None).await; + wait_for_l2_block(&full_node_test_client, 2, Some(Duration::from_secs(60))).await; let block = full_node_test_client .eth_get_block_by_number(Some(BlockNumberOrTag::Latest)) diff --git a/crates/batch-prover/src/da_block_handler.rs b/crates/batch-prover/src/da_block_handler.rs index 047e3a8e4..39fcf1863 100644 --- a/crates/batch-prover/src/da_block_handler.rs +++ b/crates/batch-prover/src/da_block_handler.rs @@ -17,7 +17,7 @@ use rand::Rng; use serde::de::DeserializeOwned; use serde::Serialize; use sov_db::ledger_db::BatchProverLedgerOps; -use sov_db::schema::types::{BatchNumber, SlotNumber}; +use sov_db::schema::types::{SlotNumber, SoftConfirmationNumber}; use sov_modules_api::fork::fork_from_block_number; use sov_modules_api::{DaSpec, StateDiff, Zkvm}; use sov_rollup_interface::da::{BlockHeaderTrait, SequencerCommitment}; @@ -366,9 +366,9 @@ pub(crate) async fn get_batch_proof_circuit_input_from_commitments< let mut witnesses = vec![]; let start_l2 = sequencer_commitment.l2_start_block_number; let end_l2 = sequencer_commitment.l2_end_block_number; - let soft_confirmations_in_commitment = match ledger_db - .get_soft_confirmation_range(&(BatchNumber(start_l2)..=BatchNumber(end_l2))) - { + let soft_confirmations_in_commitment = match ledger_db.get_soft_confirmation_range( + &(SoftConfirmationNumber(start_l2)..=SoftConfirmationNumber(end_l2)), + ) { Ok(soft_confirmations) => soft_confirmations, Err(e) => { return Err(anyhow!( @@ -451,14 +451,13 @@ pub(crate) fn break_sequencer_commitments_into_groups( for l2_height in sequencer_commitment.l2_start_block_number..=sequencer_commitment.l2_end_block_number { - let state_diff = - ledger_db - .get_l2_state_diff(BatchNumber(l2_height))? - .ok_or(anyhow!( - "Could not find state diff for L2 range {}-{}", - sequencer_commitment.l2_start_block_number, - sequencer_commitment.l2_end_block_number - ))?; + let state_diff = ledger_db + .get_l2_state_diff(SoftConfirmationNumber(l2_height))? + .ok_or(anyhow!( + "Could not find state diff for L2 range {}-{}", + sequencer_commitment.l2_start_block_number, + sequencer_commitment.l2_end_block_number + ))?; sequencer_commitment_state_diff = merge_state_diffs(sequencer_commitment_state_diff, state_diff); } diff --git a/crates/batch-prover/src/proving.rs b/crates/batch-prover/src/proving.rs index dda312fd1..b680cc284 100644 --- a/crates/batch-prover/src/proving.rs +++ b/crates/batch-prover/src/proving.rs @@ -11,7 +11,7 @@ use citrea_primitives::forks::FORKS; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use sov_db::ledger_db::BatchProverLedgerOps; -use sov_db::schema::types::{BatchNumber, StoredBatchProof, StoredBatchProofOutput}; +use sov_db::schema::types::{SoftConfirmationNumber, StoredBatchProof, StoredBatchProofOutput}; use sov_modules_api::{BatchProofCircuitOutput, BlobReaderTrait, SlotData, SpecId, Zkvm}; use sov_rollup_interface::da::{BlockHeaderTrait, DaNamespace, DaSpec, SequencerCommitment}; use sov_rollup_interface::fork::fork_from_block_number; @@ -165,7 +165,7 @@ where .expect("There should be a state root"); let initial_batch_hash = ledger - .get_soft_confirmation_by_number(&BatchNumber(first_l2_height_of_l1)) + .get_soft_confirmation_by_number(&SoftConfirmationNumber(first_l2_height_of_l1)) .map_err(|e| { L1ProcessingError::Other(format!("Error getting initial batch hash: {:?}", e)) })? @@ -390,7 +390,10 @@ pub(crate) fn save_commitments( let l2_end_height = sequencer_commitment.l2_end_block_number; for i in l2_start_height..=l2_end_height { ledger_db - .put_soft_confirmation_status(BatchNumber(i), SoftConfirmationStatus::Proven) + .put_soft_confirmation_status( + SoftConfirmationNumber(i), + SoftConfirmationStatus::Proven, + ) .unwrap_or_else(|_| { panic!( "Failed to put soft confirmation status in the ledger db {}", diff --git a/crates/batch-prover/src/runner.rs b/crates/batch-prover/src/runner.rs index 84ef59105..76acd6342 100644 --- a/crates/batch-prover/src/runner.rs +++ b/crates/batch-prover/src/runner.rs @@ -19,7 +19,7 @@ use jsonrpsee::http_client::{HttpClient, HttpClientBuilder}; use jsonrpsee::server::{BatchRequestConfig, ServerBuilder}; use jsonrpsee::RpcModule; use sov_db::ledger_db::BatchProverLedgerOps; -use sov_db::schema::types::{BatchNumber, SlotNumber}; +use sov_db::schema::types::{SlotNumber, SoftConfirmationNumber}; use sov_ledger_rpc::LedgerRpcClient; use sov_modules_api::{Context, SignedSoftConfirmation, SlotData, Spec}; use sov_modules_stf_blueprint::{Runtime, StfBlueprint}; @@ -130,12 +130,8 @@ where } }; - // Start the main rollup loop - let item_numbers = ledger_db.get_next_items_numbers(); - let last_soft_confirmation_processed_before_shutdown = - item_numbers.soft_confirmation_number; // Last L1/L2 height before shutdown. - let start_l2_height = last_soft_confirmation_processed_before_shutdown; + let start_l2_height = ledger_db.get_head_soft_confirmation_height()?.unwrap_or(0) + 1; Ok(Self { start_l2_height, @@ -446,8 +442,10 @@ where } // Save state diff to ledger DB - self.ledger_db - .set_l2_state_diff(BatchNumber(l2_height), soft_confirmation_result.state_diff)?; + self.ledger_db.set_l2_state_diff( + SoftConfirmationNumber(l2_height), + soft_confirmation_result.state_diff, + )?; // Save witnesses data to ledger db self.ledger_db.set_l2_witness( @@ -472,7 +470,7 @@ where self.ledger_db.extend_l2_range_of_l1_slot( SlotNumber(current_l1_block.header().height()), - BatchNumber(l2_height), + SoftConfirmationNumber(l2_height), )?; // Register this new block with the fork manager to active diff --git a/crates/common/src/rpc/mod.rs b/crates/common/src/rpc/mod.rs index 26fed170b..d34eab3fe 100644 --- a/crates/common/src/rpc/mod.rs +++ b/crates/common/src/rpc/mod.rs @@ -11,7 +11,7 @@ use jsonrpsee::types::error::{INTERNAL_ERROR_CODE, INTERNAL_ERROR_MSG}; use jsonrpsee::types::{ErrorObjectOwned, Request}; use jsonrpsee::{MethodResponse, RpcModule}; use sov_db::ledger_db::{LedgerDB, SharedLedgerOps}; -use sov_db::schema::types::BatchNumber; +use sov_db::schema::types::SoftConfirmationNumber; use tower_http::cors::{Any, CorsLayer}; // Exit early if head_batch_num is below this threshold @@ -33,7 +33,7 @@ pub fn register_healthcheck_rpc( ) }; - let Some((BatchNumber(head_batch_num), _)) = ledger_db + let Some((SoftConfirmationNumber(head_batch_num), _)) = ledger_db .get_head_soft_confirmation() .map_err(|err| error(&format!("Failed to get head soft batch: {}", err)))? else { @@ -47,7 +47,8 @@ pub fn register_healthcheck_rpc( let soft_batches = ledger_db .get_soft_confirmation_range( - &(BatchNumber(head_batch_num - 1)..=BatchNumber(head_batch_num)), + &(SoftConfirmationNumber(head_batch_num - 1) + ..=SoftConfirmationNumber(head_batch_num)), ) .map_err(|err| error(&format!("Failed to get soft batch range: {}", err)))?; @@ -58,7 +59,7 @@ pub fn register_healthcheck_rpc( .get_head_soft_confirmation() .map_err(|err| error(&format!("Failed to get head soft batch: {}", err)))? .unwrap(); - if new_head_batch_num > BatchNumber(head_batch_num) { + if new_head_batch_num > SoftConfirmationNumber(head_batch_num) { Ok::<(), ErrorObjectOwned>(()) } else { Err(error("Block number is not increasing")) diff --git a/crates/common/src/utils.rs b/crates/common/src/utils.rs index 2a35866b6..88b757633 100644 --- a/crates/common/src/utils.rs +++ b/crates/common/src/utils.rs @@ -1,7 +1,7 @@ use std::collections::{HashMap, HashSet}; use sov_db::ledger_db::SharedLedgerOps; -use sov_db::schema::types::BatchNumber; +use sov_db::schema::types::SoftConfirmationNumber; use sov_modules_api::{Context, Spec}; use sov_rollup_interface::da::{DaSpec, SequencerCommitment}; use sov_rollup_interface::digest::Digest; @@ -53,8 +53,9 @@ fn filter_out_commitments_by_status( visited_l2_ranges.insert(current_range); // Check if the commitment was previously finalized. - let Some(status) = ledger_db - .get_soft_confirmation_status(BatchNumber(sequencer_commitment.l2_end_block_number))? + let Some(status) = ledger_db.get_soft_confirmation_status(SoftConfirmationNumber( + sequencer_commitment.l2_end_block_number, + ))? else { filtered.push(sequencer_commitment.clone()); continue; @@ -76,7 +77,8 @@ pub fn check_l2_range_exists( last_l2_height_of_l1: u64, ) -> bool { if let Ok(range) = ledger_db.get_soft_confirmation_range( - &(BatchNumber(first_l2_height_of_l1)..=BatchNumber(last_l2_height_of_l1)), + &(SoftConfirmationNumber(first_l2_height_of_l1) + ..=SoftConfirmationNumber(last_l2_height_of_l1)), ) { if (range.len() as u64) >= (last_l2_height_of_l1 - first_l2_height_of_l1 + 1) { return true; diff --git a/crates/fullnode/src/da_block_handler.rs b/crates/fullnode/src/da_block_handler.rs index 02880be85..862b52e28 100644 --- a/crates/fullnode/src/da_block_handler.rs +++ b/crates/fullnode/src/da_block_handler.rs @@ -17,7 +17,7 @@ use serde::de::DeserializeOwned; use serde::Serialize; use sov_db::ledger_db::NodeLedgerOps; use sov_db::schema::types::{ - BatchNumber, SlotNumber, StoredBatchProofOutput, StoredSoftConfirmation, + SlotNumber, SoftConfirmationNumber, StoredBatchProofOutput, StoredSoftConfirmation, }; use sov_modules_api::{Context, Zkvm}; use sov_rollup_interface::da::{BlockHeaderTrait, SequencerCommitment}; @@ -238,7 +238,7 @@ where // and compare the root with the one from the ledger let stored_soft_confirmations: Vec = self.ledger_db.get_soft_confirmation_range( - &(BatchNumber(start_l2_height)..=BatchNumber(end_l2_height)), + &(SoftConfirmationNumber(start_l2_height)..=SoftConfirmationNumber(end_l2_height)), )?; // Make sure that the number of stored soft confirmations is equal to the range's length. @@ -279,11 +279,13 @@ where )?; for i in start_l2_height..=end_l2_height { - self.ledger_db - .put_soft_confirmation_status(BatchNumber(i), SoftConfirmationStatus::Finalized)?; + self.ledger_db.put_soft_confirmation_status( + SoftConfirmationNumber(i), + SoftConfirmationStatus::Finalized, + )?; } self.ledger_db - .set_last_commitment_l2_height(BatchNumber(end_l2_height))?; + .set_last_commitment_l2_height(SoftConfirmationNumber(end_l2_height))?; Ok(()) } @@ -410,8 +412,10 @@ where let l2_start_height = commitment.l2_start_block_number; let l2_end_height = commitment.l2_end_block_number; for i in l2_start_height..=l2_end_height { - self.ledger_db - .put_soft_confirmation_status(BatchNumber(i), SoftConfirmationStatus::Proven)?; + self.ledger_db.put_soft_confirmation_status( + SoftConfirmationNumber(i), + SoftConfirmationStatus::Proven, + )?; } } // store in ledger db diff --git a/crates/fullnode/src/runner.rs b/crates/fullnode/src/runner.rs index 2658631b5..3e596b87f 100644 --- a/crates/fullnode/src/runner.rs +++ b/crates/fullnode/src/runner.rs @@ -19,7 +19,7 @@ use jsonrpsee::http_client::{HttpClient, HttpClientBuilder}; use jsonrpsee::server::{BatchRequestConfig, RpcServiceBuilder, ServerBuilder}; use jsonrpsee::RpcModule; use sov_db::ledger_db::NodeLedgerOps; -use sov_db::schema::types::{BatchNumber, SlotNumber}; +use sov_db::schema::types::{SlotNumber, SoftConfirmationNumber}; use sov_ledger_rpc::LedgerRpcClient; use sov_modules_api::{Context, SignedSoftConfirmation, Spec}; use sov_modules_stf_blueprint::{Runtime, StfBlueprint}; @@ -125,7 +125,7 @@ where } }; - let start_l2_height = ledger_db.get_next_items_numbers().soft_confirmation_number; + let start_l2_height = ledger_db.get_head_soft_confirmation_height()?.unwrap_or(0) + 1; info!("Starting L2 height: {}", start_l2_height); @@ -293,7 +293,7 @@ where self.ledger_db.extend_l2_range_of_l1_slot( SlotNumber(current_l1_block.header().height()), - BatchNumber(l2_height), + SoftConfirmationNumber(l2_height), )?; // Register this new block with the fork manager to active diff --git a/crates/sequencer/src/commitment/controller.rs b/crates/sequencer/src/commitment/controller.rs index 6fb4e8fd6..6452a1c85 100644 --- a/crates/sequencer/src/commitment/controller.rs +++ b/crates/sequencer/src/commitment/controller.rs @@ -4,7 +4,7 @@ use citrea_common::utils::merge_state_diffs; use citrea_primitives::compression::compress_blob; use citrea_primitives::MAX_TXBODY_SIZE; use sov_db::ledger_db::SequencerLedgerOps; -use sov_db::schema::types::BatchNumber; +use sov_db::schema::types::SoftConfirmationNumber; use sov_modules_api::StateDiff; use tracing::{debug, warn}; @@ -46,14 +46,14 @@ where let last_finalized_l2_height = self .ledger_db .get_last_commitment_l2_height()? - .unwrap_or(BatchNumber(0)); + .unwrap_or(SoftConfirmationNumber(0)); let last_pending_l2_height = self .ledger_db .get_pending_commitments_l2_range()? .iter() .map(|(_, end)| *end) .max() - .unwrap_or(BatchNumber(0)); + .unwrap_or(SoftConfirmationNumber(0)); let last_committed_l2_height = cmp::max(last_finalized_l2_height, last_pending_l2_height); // If block state diff is empty, it is certain that state diff threshold won't be exceeded. @@ -97,7 +97,7 @@ where fn check_min_soft_confirmations( &self, - last_committed_l2_height: BatchNumber, + last_committed_l2_height: SoftConfirmationNumber, current_l2_height: u64, ) -> Option { // If the last commitment made is on par with the head @@ -121,13 +121,13 @@ where debug!("Enough soft confirmations to submit commitment"); Some(CommitmentInfo { - l2_height_range: BatchNumber(l2_start)..=BatchNumber(l2_end), + l2_height_range: SoftConfirmationNumber(l2_start)..=SoftConfirmationNumber(l2_end), }) } fn check_state_diff_threshold( &self, - last_committed_l2_height: BatchNumber, + last_committed_l2_height: SoftConfirmationNumber, current_l2_height: u64, state_diff: &StateDiff, ) -> Option { @@ -157,7 +157,7 @@ where debug!("Enough state diff size to submit commitment"); Some(CommitmentInfo { - l2_height_range: BatchNumber(l2_start)..=BatchNumber(l2_end), + l2_height_range: SoftConfirmationNumber(l2_start)..=SoftConfirmationNumber(l2_end), }) } diff --git a/crates/sequencer/src/commitment/mod.rs b/crates/sequencer/src/commitment/mod.rs index 62622486d..57bbdf7b5 100644 --- a/crates/sequencer/src/commitment/mod.rs +++ b/crates/sequencer/src/commitment/mod.rs @@ -9,7 +9,7 @@ use parking_lot::RwLock; use rs_merkle::algorithms::Sha256; use rs_merkle::MerkleTree; use sov_db::ledger_db::SequencerLedgerOps; -use sov_db::schema::types::{BatchNumber, SlotNumber}; +use sov_db::schema::types::{SlotNumber, SoftConfirmationNumber}; use sov_modules_api::StateDiff; use sov_rollup_interface::da::{BlockHeaderTrait, DaData, SequencerCommitment}; use sov_rollup_interface::services::da::{DaService, SenderWithNotifier}; @@ -26,7 +26,7 @@ mod controller; #[derive(Clone, Debug)] pub struct CommitmentInfo { /// L2 heights to commit - pub l2_height_range: RangeInclusive, + pub l2_height_range: RangeInclusive, } pub struct CommitmentService diff --git a/crates/sequencer/src/runner.rs b/crates/sequencer/src/runner.rs index 9fe38a16b..19004e4b1 100644 --- a/crates/sequencer/src/runner.rs +++ b/crates/sequencer/src/runner.rs @@ -30,7 +30,7 @@ use reth_transaction_pool::{ use sov_accounts::Accounts; use sov_accounts::Response::{AccountEmpty, AccountExists}; use sov_db::ledger_db::SequencerLedgerOps; -use sov_db::schema::types::{BatchNumber, SlotNumber}; +use sov_db::schema::types::{SlotNumber, SoftConfirmationNumber}; use sov_modules_api::hooks::HookSoftConfirmationInfo; use sov_modules_api::transaction::Transaction; use sov_modules_api::{ @@ -580,7 +580,7 @@ where // connect L1 and L2 height self.ledger_db.extend_l2_range_of_l1_slot( SlotNumber(da_block.header().height()), - BatchNumber(l2_height), + SoftConfirmationNumber(l2_height), )?; // Register this new block with the fork manager to active diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs index 1163a5f2b..44cf8453a 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs @@ -1,5 +1,5 @@ use std::path::Path; -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use serde::de::DeserializeOwned; use serde::Serialize; @@ -14,16 +14,16 @@ use crate::rocks_db_config::RocksdbConfig; #[cfg(test)] use crate::schema::tables::TestTableNew; use crate::schema::tables::{ - BatchByNumber, CommitmentsByNumber, ExecutedMigrations, L2GenesisStateRoot, L2RangeByL1Height, - L2Witness, LastPrunedBlock, LastSequencerCommitmentSent, LastStateDiff, - LightClientProofBySlotNumber, MempoolTxs, PendingProvingSessions, - PendingSequencerCommitmentL2Range, ProofsBySlotNumberV2, ProverLastScannedSlot, - ProverStateDiffs, SlotByHash, SlotByNumber, SoftConfirmationByHash, SoftConfirmationByNumber, - SoftConfirmationStatus, VerifiedBatchProofsBySlotNumber, LEDGER_TABLES, + CommitmentsByNumber, ExecutedMigrations, L2GenesisStateRoot, L2RangeByL1Height, L2Witness, + LastPrunedBlock, LastSequencerCommitmentSent, LastStateDiff, LightClientProofBySlotNumber, + MempoolTxs, PendingProvingSessions, PendingSequencerCommitmentL2Range, ProofsBySlotNumberV2, + ProverLastScannedSlot, ProverStateDiffs, SlotByHash, SoftConfirmationByHash, + SoftConfirmationByNumber, SoftConfirmationStatus, VerifiedBatchProofsBySlotNumber, + LEDGER_TABLES, }; use crate::schema::types::{ - BatchNumber, L2HeightRange, SlotNumber, StoredBatchProof, StoredBatchProofOutput, - StoredLightClientProof, StoredLightClientProofOutput, StoredSlot, StoredSoftConfirmation, + L2HeightRange, SlotNumber, SoftConfirmationNumber, StoredBatchProof, StoredBatchProofOutput, + StoredLightClientProof, StoredLightClientProofOutput, StoredSoftConfirmation, StoredTransaction, StoredVerifiedProof, }; @@ -46,19 +46,6 @@ pub struct LedgerDB { /// The database which stores the committed ledger. Uses an optimized layout which /// requires transactions to be executed before being committed. pub(crate) db: Arc, - pub(crate) next_item_numbers: Arc>, -} - -/// A SlotNumber, BatchNumber, TxNumber, and EventNumber which are grouped together, typically representing -/// the respective heights at the start or end of slot processing. -#[derive(Default, Clone, Debug)] -pub struct ItemNumbers { - /// The slot number - pub slot_number: u64, - /// The soft confirmation number - pub soft_confirmation_number: u64, - /// The batch number - pub batch_number: u64, } impl LedgerDB { @@ -75,18 +62,8 @@ impl LedgerDB { .unwrap_or_else(|| LEDGER_TABLES.iter().map(|e| e.to_string()).collect()); let inner = DB::open(path, "ledger-db", tables, &raw_options)?; - let next_item_numbers = ItemNumbers { - slot_number: Self::last_version_written(&inner, SlotByNumber)?.unwrap_or_default() + 1, - soft_confirmation_number: Self::last_version_written(&inner, SoftConfirmationByNumber)? - .unwrap_or_default() - + 1, - batch_number: Self::last_version_written(&inner, BatchByNumber)?.unwrap_or_default() - + 1, - }; - Ok(Self { db: Arc::new(inner), - next_item_numbers: Arc::new(Mutex::new(next_item_numbers)), }) } @@ -161,7 +138,7 @@ impl SharedLedgerOps for LedgerDB { fn put_soft_confirmation( &self, batch: &StoredSoftConfirmation, - batch_number: &BatchNumber, + batch_number: &SoftConfirmationNumber, schema_batch: &mut SchemaBatch, ) -> Result<(), anyhow::Error> { schema_batch.put::(batch_number, batch)?; @@ -175,15 +152,6 @@ impl SharedLedgerOps for LedgerDB { soft_confirmation_receipt: SoftConfirmationReceipt, tx_bodies: Option>>, ) -> Result<(), anyhow::Error> { - // Create a scope to ensure that the lock is released before we commit to the db - let mut current_item_numbers = { - let mut next_item_numbers = self.next_item_numbers.lock().unwrap(); - let item_numbers = next_item_numbers.clone(); - next_item_numbers.soft_confirmation_number += 1; - item_numbers - // The lock is released here - }; - let mut schema_batch = SchemaBatch::new(); let tx_bodies = if let Some(tx_bodies) = tx_bodies { @@ -201,11 +169,12 @@ impl SharedLedgerOps for LedgerDB { body: tx_body, }) .collect(); + let l2_height = soft_confirmation_receipt.l2_height; // Insert soft confirmation let soft_confirmation_to_store = StoredSoftConfirmation { da_slot_height: soft_confirmation_receipt.da_slot_height, - l2_height: current_item_numbers.soft_confirmation_number, + l2_height, da_slot_hash: soft_confirmation_receipt.da_slot_hash.into(), da_slot_txs_commitment: soft_confirmation_receipt.da_slot_txs_commitment.into(), hash: soft_confirmation_receipt.hash, @@ -220,10 +189,9 @@ impl SharedLedgerOps for LedgerDB { }; self.put_soft_confirmation( &soft_confirmation_to_store, - &BatchNumber(current_item_numbers.soft_confirmation_number), + &SoftConfirmationNumber(l2_height), &mut schema_batch, )?; - current_item_numbers.soft_confirmation_number += 1; self.db.write_schemas(schema_batch)?; @@ -235,7 +203,7 @@ impl SharedLedgerOps for LedgerDB { fn extend_l2_range_of_l1_slot( &self, l1_height: SlotNumber, - l2_height: BatchNumber, + l2_height: SoftConfirmationNumber, ) -> Result<(), anyhow::Error> { let current_range = self.db.get::(&l1_height)?; @@ -252,24 +220,6 @@ impl SharedLedgerOps for LedgerDB { Ok(()) } - /// Get the next slot, block, transaction numbers - #[instrument(level = "trace", skip(self), ret)] - fn get_next_items_numbers(&self) -> ItemNumbers { - self.next_item_numbers.lock().unwrap().clone() - } - - /// Gets all slots with numbers `range.start` to `range.end`. If `range.end` is outside - /// the range of the database, the result will smaller than the requested range. - /// Note that this method blindly preallocates for the requested range, so it should not be exposed - /// directly via rpc. - #[instrument(level = "trace", skip(self), err)] - fn _get_slot_range( - &self, - range: &std::ops::Range, - ) -> Result, anyhow::Error> { - self.get_data_range::(range) - } - /// Gets l1 height of l1 hash #[instrument(level = "trace", skip(self), err, ret)] fn get_state_diff(&self) -> Result { @@ -294,7 +244,7 @@ impl SharedLedgerOps for LedgerDB { #[instrument(level = "trace", skip(self), err, ret)] fn put_soft_confirmation_status( &self, - height: BatchNumber, + height: SoftConfirmationNumber, status: sov_rollup_interface::rpc::SoftConfirmationStatus, ) -> Result<(), anyhow::Error> { let mut schema_batch = SchemaBatch::new(); @@ -309,7 +259,7 @@ impl SharedLedgerOps for LedgerDB { #[instrument(level = "trace", skip(self), err, ret)] fn get_soft_confirmation_status( &self, - height: BatchNumber, + height: SoftConfirmationNumber, ) -> Result, anyhow::Error> { let status = self.db.get::(&height)?; @@ -369,7 +319,7 @@ impl SharedLedgerOps for LedgerDB { .transpose() } else { self.db - .get::(&BatchNumber(l2_height))? + .get::(&SoftConfirmationNumber(l2_height))? .map(|soft_confirmation| { bincode::deserialize(&soft_confirmation.state_root).map_err(Into::into) }) @@ -381,7 +331,7 @@ impl SharedLedgerOps for LedgerDB { #[instrument(level = "trace", skip(self), err)] fn get_head_soft_confirmation( &self, - ) -> anyhow::Result> { + ) -> anyhow::Result> { let mut iter = self.db.iter::()?; iter.seek_to_last(); @@ -392,6 +342,11 @@ impl SharedLedgerOps for LedgerDB { } } + fn get_head_soft_confirmation_height(&self) -> anyhow::Result> { + let head_l2_height = Self::last_version_written(&self.db, SoftConfirmationByNumber)?; + Ok(head_l2_height) + } + /// Gets all soft confirmations with numbers `range.start` to `range.end`. If `range.end` is outside /// the range of the database, the result will smaller than the requested range. /// Note that this method blindly preallocates for the requested range, so it should not be exposed @@ -399,10 +354,10 @@ impl SharedLedgerOps for LedgerDB { #[instrument(level = "trace", skip(self), err)] fn get_soft_confirmation_range( &self, - range: &std::ops::RangeInclusive, + range: &std::ops::RangeInclusive, ) -> Result, anyhow::Error> { let start = *range.start(); - let end = BatchNumber(range.end().0 + 1); + let end = SoftConfirmationNumber(range.end().0 + 1); self.get_data_range::(&(start..end)) } @@ -410,7 +365,7 @@ impl SharedLedgerOps for LedgerDB { #[instrument(level = "trace", skip(self), err)] fn get_soft_confirmation_by_number( &self, - number: &BatchNumber, + number: &SoftConfirmationNumber, ) -> Result, anyhow::Error> { self.db.get::(number) } @@ -418,7 +373,7 @@ impl SharedLedgerOps for LedgerDB { /// Get the most recent committed batch /// Returns L2 height. #[instrument(level = "trace", skip(self), err, ret)] - fn get_last_commitment_l2_height(&self) -> anyhow::Result> { + fn get_last_commitment_l2_height(&self) -> anyhow::Result> { self.db.get::(&()) } @@ -426,7 +381,10 @@ impl SharedLedgerOps for LedgerDB { /// For a sequencer, the last commitment height is set when the block is produced. /// For a full node the last commitment is set when a commitment is read from a finalized DA layer block. #[instrument(level = "trace", skip(self), err, ret)] - fn set_last_commitment_l2_height(&self, l2_height: BatchNumber) -> Result<(), anyhow::Error> { + fn set_last_commitment_l2_height( + &self, + l2_height: SoftConfirmationNumber, + ) -> Result<(), anyhow::Error> { let mut schema_batch = SchemaBatch::new(); schema_batch.put::(&(), &l2_height)?; @@ -521,7 +479,9 @@ impl BatchProverLedgerOps for LedgerDB { &self, l2_height: u64, ) -> anyhow::Result> { - let buf = self.db.get::(&BatchNumber(l2_height))?; + let buf = self + .db + .get::(&SoftConfirmationNumber(l2_height))?; if let Some((state_buf, offchain_buf)) = buf { let state_witness = bincode::deserialize(&state_buf)?; let offchain_witness = bincode::deserialize(&offchain_buf)?; @@ -579,7 +539,10 @@ impl BatchProverLedgerOps for LedgerDB { let state_buf = bincode::serialize(state_witness)?; let offchain_buf = bincode::serialize(offchain_witness)?; let mut schema_batch = SchemaBatch::new(); - schema_batch.put::(&BatchNumber(l2_height), &(state_buf, offchain_buf))?; + schema_batch.put::( + &SoftConfirmationNumber(l2_height), + &(state_buf, offchain_buf), + )?; self.db.write_schemas(schema_batch)?; @@ -588,7 +551,7 @@ impl BatchProverLedgerOps for LedgerDB { fn set_l2_state_diff( &self, - l2_height: BatchNumber, + l2_height: SoftConfirmationNumber, state_diff: StateDiff, ) -> anyhow::Result<()> { let mut schema_batch = SchemaBatch::new(); @@ -599,7 +562,10 @@ impl BatchProverLedgerOps for LedgerDB { Ok(()) } - fn get_l2_state_diff(&self, l2_height: BatchNumber) -> anyhow::Result> { + fn get_l2_state_diff( + &self, + l2_height: SoftConfirmationNumber, + ) -> anyhow::Result> { self.db.get::(&l2_height) } @@ -661,32 +627,6 @@ impl ProvingServiceLedgerOps for LedgerDB { } impl SequencerLedgerOps for LedgerDB { - /// Put slots - #[instrument(level = "trace", skip(self, schema_batch), err, ret)] - fn put_slot( - &self, - slot: &StoredSlot, - slot_number: &SlotNumber, - schema_batch: &mut SchemaBatch, - ) -> Result<(), anyhow::Error> { - schema_batch.put::(slot_number, slot)?; - schema_batch.put::(&slot.hash, slot_number) - } - - /// Used by the sequencer to record that it has committed to soft confirmations on a given L2 height - #[instrument(level = "trace", skip(self), err, ret)] - fn set_last_sequencer_commitment_l2_height( - &self, - l2_height: BatchNumber, - ) -> Result<(), anyhow::Error> { - let mut schema_batch = SchemaBatch::new(); - - schema_batch.put::(&(), &l2_height)?; - self.db.write_schemas(schema_batch)?; - - Ok(()) - } - /// Gets all pending commitments' l2 ranges. /// Returns start-end L2 heights. #[instrument(level = "trace", skip(self), err)] @@ -808,19 +748,6 @@ impl NodeLedgerOps for LedgerDB { } } - /// Get the most recent committed slot, if any - #[instrument(level = "trace", skip(self), err)] - fn get_head_slot(&self) -> anyhow::Result> { - let mut iter = self.db.iter::()?; - iter.seek_to_last(); - - match iter.next() { - Some(Ok(item)) => Ok(Some(item.into_tuple())), - Some(Err(e)) => Err(e), - _ => Ok(None), - } - } - /// Gets the commitments in the da slot with given height if any #[instrument(level = "trace", skip(self), err)] fn get_commitments_on_da_slot( diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/rpc.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/rpc.rs index e287dae5e..cfd306517 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/rpc.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/rpc.rs @@ -8,7 +8,7 @@ use crate::schema::tables::{ CommitmentsByNumber, SlotByHash, SoftConfirmationByHash, SoftConfirmationByNumber, SoftConfirmationStatus, VerifiedBatchProofsBySlotNumber, }; -use crate::schema::types::{BatchNumber, SlotNumber}; +use crate::schema::types::{SlotNumber, SoftConfirmationNumber}; /// The maximum number of batches that can be requested in a single RPC range query const MAX_BATCHES_PER_REQUEST: u64 = 20; @@ -94,7 +94,7 @@ impl LedgerRpcProvider for LedgerDB { ) -> Result { if self .db - .get::(&BatchNumber(l2_height)) + .get::(&SoftConfirmationNumber(l2_height)) .ok() .flatten() .is_none() @@ -107,7 +107,7 @@ impl LedgerRpcProvider for LedgerDB { let status = self .db - .get::(&BatchNumber(l2_height))?; + .get::(&SoftConfirmationNumber(l2_height))?; match status { Some(status) => Ok(status), @@ -196,19 +196,22 @@ impl LedgerRpcProvider for LedgerDB { fn get_head_soft_confirmation( &self, ) -> Result, anyhow::Error> { - let next_ids = self.get_next_items_numbers(); + let head_l2_height = + Self::last_version_written(&self.db, SoftConfirmationByNumber)?.unwrap_or(0); - if let Some(stored_soft_confirmation) = self.db.get::( - &BatchNumber(next_ids.soft_confirmation_number.saturating_sub(1)), - )? { + if let Some(stored_soft_confirmation) = self + .db + .get::(&SoftConfirmationNumber(head_l2_height))? + { return Ok(Some(stored_soft_confirmation.try_into()?)); } Ok(None) } fn get_head_soft_confirmation_height(&self) -> Result { - let next_ids = self.get_next_items_numbers(); - Ok(next_ids.soft_confirmation_number.saturating_sub(1)) + let head_l2_height = + Self::last_version_written(&self.db, SoftConfirmationByNumber)?.unwrap_or(0); + Ok(head_l2_height) } } @@ -216,10 +219,10 @@ impl LedgerDB { fn resolve_soft_confirmation_identifier( &self, batch_id: &SoftConfirmationIdentifier, - ) -> Result, anyhow::Error> { + ) -> Result, anyhow::Error> { match batch_id { SoftConfirmationIdentifier::Hash(hash) => self.db.get::(hash), - SoftConfirmationIdentifier::Number(num) => Ok(Some(BatchNumber(*num))), + SoftConfirmationIdentifier::Number(num) => Ok(Some(SoftConfirmationNumber(*num))), } } } diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs index befd64c1a..1f7e0438d 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs @@ -8,10 +8,9 @@ use sov_rollup_interface::stf::{SoftConfirmationReceipt, StateDiff}; use sov_rollup_interface::zk::Proof; use sov_schema_db::SchemaBatch; -use super::ItemNumbers; use crate::schema::types::{ - BatchNumber, L2HeightRange, SlotNumber, StoredBatchProof, StoredBatchProofOutput, - StoredLightClientProof, StoredLightClientProofOutput, StoredSlot, StoredSoftConfirmation, + L2HeightRange, SlotNumber, SoftConfirmationNumber, StoredBatchProof, StoredBatchProofOutput, + StoredLightClientProof, StoredLightClientProofOutput, StoredSoftConfirmation, }; /// Shared ledger operations @@ -23,7 +22,7 @@ pub trait SharedLedgerOps { fn put_soft_confirmation( &self, batch: &StoredSoftConfirmation, - batch_number: &BatchNumber, + batch_number: &SoftConfirmationNumber, schema_batch: &mut SchemaBatch, ) -> Result<()>; @@ -39,18 +38,9 @@ pub trait SharedLedgerOps { fn extend_l2_range_of_l1_slot( &self, l1_height: SlotNumber, - l2_height: BatchNumber, + l2_height: SoftConfirmationNumber, ) -> Result<()>; - /// Get the next slot, block, transaction numbers - fn get_next_items_numbers(&self) -> ItemNumbers; - - /// Gets all slots with numbers `range.start` to `range.end`. If `range.end` is outside - /// the range of the database, the result will smaller than the requested range. - /// Note that this method blindly preallocates for the requested range, so it should not be exposed - /// directly via rpc. - fn _get_slot_range(&self, range: &std::ops::Range) -> Result>; - /// Gets l1 height of l1 hash fn get_state_diff(&self) -> Result; @@ -63,14 +53,14 @@ pub trait SharedLedgerOps { /// Saves a soft confirmation status for a given L1 height fn put_soft_confirmation_status( &self, - height: BatchNumber, + height: SoftConfirmationNumber, status: sov_rollup_interface::rpc::SoftConfirmationStatus, ) -> Result<()>; /// Returns a soft confirmation status for a given L1 height fn get_soft_confirmation_status( &self, - height: BatchNumber, + height: SoftConfirmationNumber, ) -> Result>; /// Gets the commitments in the da slot with given height if any @@ -94,7 +84,12 @@ pub trait SharedLedgerOps { ) -> anyhow::Result>; /// Get the most recent committed soft confirmation, if any - fn get_head_soft_confirmation(&self) -> Result>; + fn get_head_soft_confirmation( + &self, + ) -> Result>; + + /// Get the most recent committed soft confirmation height, if any + fn get_head_soft_confirmation_height(&self) -> Result>; /// Gets all soft confirmations with numbers `range.start` to `range.end`. If `range.end` is outside /// the range of the database, the result will smaller than the requested range. @@ -102,22 +97,22 @@ pub trait SharedLedgerOps { /// directly via rpc. fn get_soft_confirmation_range( &self, - range: &std::ops::RangeInclusive, + range: &std::ops::RangeInclusive, ) -> Result>; /// Gets all soft confirmations by numbers fn get_soft_confirmation_by_number( &self, - number: &BatchNumber, + number: &SoftConfirmationNumber, ) -> Result>; /// Used by the sequencer to record that it has committed to soft confirmations on a given L2 height - fn set_last_commitment_l2_height(&self, l2_height: BatchNumber) -> Result<()>; + fn set_last_commitment_l2_height(&self, l2_height: SoftConfirmationNumber) -> Result<()>; /// Get the most recent committed batch /// Returns L2 height. - fn get_last_commitment_l2_height(&self) -> anyhow::Result>; + fn get_last_commitment_l2_height(&self) -> anyhow::Result>; /// Get the last scanned slot fn get_last_scanned_l1_height(&self) -> Result>; @@ -148,9 +143,6 @@ pub trait NodeLedgerOps: SharedLedgerOps { output: StoredBatchProofOutput, ) -> Result<()>; - /// Get the most recent committed slot, if any - fn get_head_slot(&self) -> Result>; - /// Gets the commitments in the da slot with given height if any fn get_commitments_on_da_slot(&self, height: u64) -> Result>>; } @@ -185,10 +177,14 @@ pub trait BatchProverLedgerOps: SharedLedgerOps + Send + Sync { ) -> Result<()>; /// Save a specific L2 range state diff - fn set_l2_state_diff(&self, l2_height: BatchNumber, state_diff: StateDiff) -> Result<()>; + fn set_l2_state_diff( + &self, + l2_height: SoftConfirmationNumber, + state_diff: StateDiff, + ) -> Result<()>; /// Returns an L2 state diff - fn get_l2_state_diff(&self, l2_height: BatchNumber) -> Result>; + fn get_l2_state_diff(&self, l2_height: SoftConfirmationNumber) -> Result>; /// Clears all pending proving sessions fn clear_pending_proving_sessions(&self) -> Result<()>; @@ -228,17 +224,6 @@ pub trait ProvingServiceLedgerOps: BatchProverLedgerOps + SharedLedgerOps + Send /// Sequencer ledger operations pub trait SequencerLedgerOps: SharedLedgerOps { - /// Put slots - fn put_slot( - &self, - slot: &StoredSlot, - slot_number: &SlotNumber, - schema_batch: &mut SchemaBatch, - ) -> Result<()>; - - /// Used by the sequencer to record that it has committed to soft confirmations on a given L2 height - fn set_last_sequencer_commitment_l2_height(&self, l2_height: BatchNumber) -> Result<()>; - /// Gets all pending commitments' l2 ranges. /// Returns start-end L2 heights. fn get_pending_commitments_l2_range(&self) -> Result>; diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/tables.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/tables.rs index e19f4bfe5..f8d1554c0 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/tables.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/tables.rs @@ -1,18 +1,5 @@ //! This module defines the following tables: //! -//! -//! Slot Tables: -//! - `SlotNumber -> StoredSlot` -//! - `SlotNumber -> Vec` -//! -//! Batch Tables: -//! - `BatchNumber -> StoredBatch` -//! - `BatchHash -> BatchNumber` -//! -//! Tx Tables: -//! - `TxNumber -> (TxHash,Tx)` -//! - `TxHash -> TxNumber` -//! //! JMT Tables: //! - `KeyHash -> Key` //! - `(Key, Version) -> JmtValue` @@ -31,8 +18,8 @@ use sov_schema_db::schema::{KeyDecoder, KeyEncoder, ValueCodec}; use sov_schema_db::{CodecError, SeekKeyEncoder}; use super::types::{ - AccessoryKey, AccessoryStateValue, BatchNumber, DbHash, JmtValue, L2HeightRange, SlotNumber, - StateKey, StoredBatch, StoredBatchProof, StoredLightClientProof, StoredSlot, + AccessoryKey, AccessoryStateValue, DbHash, JmtValue, L2HeightRange, SlotNumber, + SoftConfirmationNumber, StateKey, StoredBatchProof, StoredLightClientProof, StoredSoftConfirmation, StoredVerifiedProof, }; @@ -48,7 +35,6 @@ pub const STATE_TABLES: &[&str] = &[ /// transaction, events, receipts, etc. pub const LEDGER_TABLES: &[&str] = &[ ExecutedMigrations::table_name(), - SlotByNumber::table_name(), SlotByHash::table_name(), SoftConfirmationByNumber::table_name(), SoftConfirmationByHash::table_name(), @@ -60,7 +46,6 @@ pub const LEDGER_TABLES: &[&str] = &[ PendingSequencerCommitmentL2Range::table_name(), LastSequencerCommitmentSent::table_name(), ProverLastScannedSlot::table_name(), - BatchByNumber::table_name(), SoftConfirmationStatus::table_name(), CommitmentsByNumber::table_name(), ProofsBySlotNumber::table_name(), @@ -232,11 +217,6 @@ define_table_with_seek_key_codec!( (LastStateDiff) () => StateDiff ); -define_table_with_seek_key_codec!( - /// The primary source for slot data - (SlotByNumber) SlotNumber => StoredSlot -); - define_table_with_default_codec!( /// A "secondary index" for slot data by hash (SlotByHash) DbHash => SlotNumber @@ -249,12 +229,12 @@ define_table_with_default_codec!( define_table_with_seek_key_codec!( /// The primary source for soft confirmation data - (SoftConfirmationByNumber) BatchNumber => StoredSoftConfirmation + (SoftConfirmationByNumber) SoftConfirmationNumber => StoredSoftConfirmation ); define_table_with_default_codec!( /// A "secondary index" for soft confirmation data by hash - (SoftConfirmationByHash) DbHash => BatchNumber + (SoftConfirmationByHash) DbHash => SoftConfirmationNumber ); define_table_with_default_codec!( @@ -264,7 +244,7 @@ define_table_with_default_codec!( define_table_with_default_codec!( /// The primary source of state & offchain witnesses by L2 height - (L2Witness) BatchNumber => (Vec, Vec) + (L2Witness) SoftConfirmationNumber => (Vec, Vec) ); define_table_with_default_codec!( @@ -279,7 +259,7 @@ define_table_with_default_codec!( define_table_with_seek_key_codec!( /// Sequencer uses this table to store the last commitment it sent - (LastSequencerCommitmentSent) () => BatchNumber + (LastSequencerCommitmentSent) () => SoftConfirmationNumber ); define_table_with_seek_key_codec!( @@ -290,14 +270,9 @@ define_table_with_seek_key_codec!( (ProverLastScannedSlot) () => SlotNumber ); -define_table_with_seek_key_codec!( - /// The primary source for batch data - (BatchByNumber) BatchNumber => StoredBatch -); - define_table_with_default_codec!( /// Check whether a block is finalized - (SoftConfirmationStatus) BatchNumber => sov_rollup_interface::rpc::SoftConfirmationStatus + (SoftConfirmationStatus) SoftConfirmationNumber => sov_rollup_interface::rpc::SoftConfirmationStatus ); define_table_without_codec!( @@ -338,7 +313,7 @@ define_table_with_default_codec!( define_table_with_default_codec!( /// L2 height to state diff for prover - (ProverStateDiffs) BatchNumber => StateDiff + (ProverStateDiffs) SoftConfirmationNumber => StateDiff ); define_table_with_seek_key_codec!( diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs index 390163557..6f90dad4e 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs @@ -1,12 +1,10 @@ use std::fmt::Debug; -use std::marker::PhantomData; use std::sync::Arc; use borsh::{BorshDeserialize, BorshSerialize}; -use serde::de::DeserializeOwned; use sov_rollup_interface::rpc::{ BatchProofOutputRpcResponse, BatchProofResponse, HexTx, LightClientProofOutputRpcResponse, - LightClientProofResponse, SoftConfirmationResponse, TxResponse, VerifiedBatchProofResponse, + LightClientProofResponse, SoftConfirmationResponse, VerifiedBatchProofResponse, }; use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; use sov_rollup_interface::zk::{BatchProofInfo, CumulativeStateDiff, Proof}; @@ -57,18 +55,6 @@ pub type DbHash = [u8; 32]; pub type JmtValue = Option>; pub(crate) type StateKey = Vec; -/// The on-disk format of a slot. Specifies the batches contained in the slot -/// and the hash of the da block. TODO(@preston-evans98): add any additional data -/// required to reconstruct the da block proof. -#[derive(Debug, PartialEq, BorshDeserialize, BorshSerialize)] -pub struct StoredSlot { - /// The slot's hash, as reported by the DA layer. - pub hash: DbHash, - /// Any extra data which the rollup decides to store relating to this slot. - pub extra_data: DbBytes, - /// The range of batches which occurred in this slot. - pub batches: std::ops::Range, -} /// The on-disk format for a light client proof output #[derive(Debug, PartialEq, BorshDeserialize, BorshSerialize)] pub struct StoredLightClientProofOutput { @@ -289,7 +275,7 @@ where /// The range of L2 heights (soft confirmations) for a given L1 block /// (start, end) inclusive -pub type L2HeightRange = (BatchNumber, BatchNumber); +pub type L2HeightRange = (SoftConfirmationNumber, SoftConfirmationNumber); impl TryFrom for SoftConfirmationResponse { type Error = anyhow::Error; @@ -322,16 +308,6 @@ impl TryFrom for SoftConfirmationResponse { } } -/// The on-disk format for a batch. Stores the hash and identifies the range of transactions -/// included in the batch. -#[derive(Debug, PartialEq, BorshDeserialize, BorshSerialize)] -pub struct StoredBatch { - /// The hash of the batch, as reported by the DA layer. - pub hash: DbHash, - /// The range of transactions which occurred in this batch. - pub txs: std::ops::Range, -} - /// The on-disk format of a transaction. Includes the txhash, the serialized tx data, /// and identifies the events emitted by this transaction #[derive(Debug, PartialEq, BorshSerialize, BorshDeserialize, Clone)] @@ -342,17 +318,6 @@ pub struct StoredTransaction { pub body: Option>, } -impl TryFrom for TxResponse { - type Error = anyhow::Error; - fn try_from(value: StoredTransaction) -> Result { - Ok(Self { - hash: value.hash, - body: value.body.map(HexTx::from), - phantom_data: PhantomData, - }) - } -} - macro_rules! u64_wrapper { ($name:ident) => { /// A typed wrapper around u64 implementing `Encode` and `Decode` @@ -381,6 +346,4 @@ macro_rules! u64_wrapper { } u64_wrapper!(SlotNumber); -u64_wrapper!(BatchNumber); -u64_wrapper!(TxNumber); -u64_wrapper!(EventNumber); +u64_wrapper!(SoftConfirmationNumber); diff --git a/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs b/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs index 5d7e18205..64f15740e 100644 --- a/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs +++ b/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs @@ -6,7 +6,6 @@ extern crate alloc; use alloc::collections::BTreeMap; use alloc::string::String; use alloc::vec::Vec; -use core::marker::PhantomData; use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; @@ -330,22 +329,6 @@ pub fn sequencer_commitment_to_response( } } -/// The response to a JSON-RPC request for a particular transaction. -#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct TxResponse { - /// The hex encoded transaction hash. - #[serde(with = "utils::rpc_hex")] - pub hash: [u8; 32], - /// The transaction body, if stored by the rollup. - #[serde(skip_serializing_if = "Option::is_none")] - pub body: Option, - /// The custom receipt specified by the rollup. This typically contains - /// information about the outcome of the transaction. - #[serde(skip_serializing)] - pub phantom_data: PhantomData, -} - /// An RPC response which might contain a full item or just its hash. #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] #[serde(untagged, rename_all = "camelCase")]