From b45e054b3568625e8d1af0399871557edd37002a Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Thu, 22 Jan 2026 16:32:12 +0100 Subject: [PATCH] lost change --- crates/store/src/state/loader.rs | 27 +++++++++++++++------------ crates/store/src/state/mod.rs | 14 +++++--------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/crates/store/src/state/loader.rs b/crates/store/src/state/loader.rs index 4aa8e2590..504ea0631 100644 --- a/crates/store/src/state/loader.rs +++ b/crates/store/src/state/loader.rs @@ -8,10 +8,11 @@ //! - **Persistent mode** (`rocksdb` feature enabled): Trees are loaded from persistent storage if //! data exists, otherwise rebuilt from the database and persisted. +use std::future::Future; use std::path::Path; use miden_protocol::Word; -use miden_protocol::block::account_tree::account_id_to_smt_key; +use miden_protocol::block::account_tree::{AccountTree, account_id_to_smt_key}; use miden_protocol::block::nullifier_tree::NullifierTree; use miden_protocol::block::{BlockHeader, BlockNumber, Blockchain}; #[cfg(not(feature = "rocksdb"))] @@ -84,15 +85,13 @@ pub trait StorageLoader: SmtStorage + Sized { fn load_account_tree( self, db: &mut Db, - ) -> impl std::future::Future, StateInitializationError>> + Send; + ) -> impl Future>, StateInitializationError>> + Send; /// Loads a nullifier tree, either from persistent storage or by rebuilding from DB. fn load_nullifier_tree( self, db: &mut Db, - ) -> impl std::future::Future< - Output = Result>, StateInitializationError>, - > + Send; + ) -> impl Future>, StateInitializationError>> + Send; } // MEMORY STORAGE IMPLEMENTATION @@ -107,13 +106,14 @@ impl StorageLoader for MemoryStorage { async fn load_account_tree( self, db: &mut Db, - ) -> Result, StateInitializationError> { + ) -> Result>, StateInitializationError> { let account_data = db.select_all_account_commitments().await?; let smt_entries = account_data .into_iter() .map(|(id, commitment)| (account_id_to_smt_key(id), commitment)); - LargeSmt::with_entries(self, smt_entries) - .map_err(account_tree_large_smt_error_to_init_error) + let smt = LargeSmt::with_entries(self, smt_entries) + .map_err(account_tree_large_smt_error_to_init_error)?; + AccountTree::new(smt).map_err(StateInitializationError::FailedToCreateAccountsTree) } async fn load_nullifier_tree( @@ -144,13 +144,15 @@ impl StorageLoader for RocksDbStorage { async fn load_account_tree( self, db: &mut Db, - ) -> Result, StateInitializationError> { + ) -> Result>, StateInitializationError> { // If RocksDB storage has data, load from it directly let has_data = self .has_leaves() .map_err(|e| StateInitializationError::AccountTreeIoError(e.to_string()))?; if has_data { - return load_smt(self); + let smt = load_smt(self)?; + return AccountTree::new(smt) + .map_err(StateInitializationError::FailedToCreateAccountsTree); } info!(target: COMPONENT, "RocksDB account tree storage is empty, populating from SQLite"); @@ -158,8 +160,9 @@ impl StorageLoader for RocksDbStorage { let smt_entries = account_data .into_iter() .map(|(id, commitment)| (account_id_to_smt_key(id), commitment)); - LargeSmt::with_entries(self, smt_entries) - .map_err(account_tree_large_smt_error_to_init_error) + let smt = LargeSmt::with_entries(self, smt_entries) + .map_err(account_tree_large_smt_error_to_init_error)?; + AccountTree::new(smt).map_err(StateInitializationError::FailedToCreateAccountsTree) } async fn load_nullifier_tree( diff --git a/crates/store/src/state/mod.rs b/crates/store/src/state/mod.rs index 3c422121b..2d704671c 100644 --- a/crates/store/src/state/mod.rs +++ b/crates/store/src/state/mod.rs @@ -27,11 +27,11 @@ use miden_protocol::Word; use miden_protocol::account::delta::AccountUpdateDetails; use miden_protocol::account::{AccountId, StorageMapWitness, StorageSlotName}; use miden_protocol::asset::{AssetVaultKey, AssetWitness}; -use miden_protocol::block::account_tree::{AccountTree, AccountWitness}; -use miden_protocol::block::nullifier_tree::NullifierWitness; +use miden_protocol::block::account_tree::AccountWitness; +use miden_protocol::block::nullifier_tree::{NullifierTree, NullifierWitness}; use miden_protocol::block::{BlockHeader, BlockInputs, BlockNumber, Blockchain, ProvenBlock}; use miden_protocol::crypto::merkle::mmr::{Forest, MmrDelta, MmrPeaks, MmrProof, PartialMmr}; -use miden_protocol::crypto::merkle::smt::{SmtProof, SmtStorage}; +use miden_protocol::crypto::merkle::smt::{LargeSmt, SmtProof, SmtStorage}; use miden_protocol::note::{NoteDetails, NoteId, NoteScript, Nullifier}; use miden_protocol::transaction::{OutputNote, PartialBlockchain}; use miden_protocol::utils::Serializable; @@ -91,9 +91,7 @@ struct InnerState where S: SmtStorage, { - nullifier_tree: miden_protocol::block::nullifier_tree::NullifierTree< - miden_protocol::crypto::merkle::smt::LargeSmt, - >, + nullifier_tree: NullifierTree>, blockchain: Blockchain, account_tree: AccountTreeWithHistory, } @@ -156,9 +154,7 @@ impl State { let latest_block_num = blockchain.chain_tip().unwrap_or(BlockNumber::GENESIS); let account_storage = TreeStorage::create(data_path, ACCOUNT_TREE_STORAGE_DIR)?; - let smt = account_storage.load_account_tree(&mut db).await?; - let account_tree = - AccountTree::new(smt).map_err(StateInitializationError::FailedToCreateAccountsTree)?; + let account_tree = account_storage.load_account_tree(&mut db).await?; let nullifier_storage = TreeStorage::create(data_path, NULLIFIER_TREE_STORAGE_DIR)?; let nullifier_tree = nullifier_storage.load_nullifier_tree(&mut db).await?;