miden-node-store 0.17.0-rc.4

Miden node's state store component
Documentation
// Required by code generated by the upstream `#[instrument]` macro.
extern crate miden_node_tracing as tracing;

mod account_state_forest;
mod accounts;
pub mod allowlist;
mod blocks;
mod data_directory;
mod db;
mod errors;
pub mod genesis;
mod proven_tip;
pub mod state;

#[cfg(feature = "rocksdb")]
pub use accounts::PersistentAccountTree;
pub use accounts::{AccountTreeWithHistory, HistoricalError, InMemoryAccountTree};
pub use blocks::BlockStore;
pub use data_directory::DataDirectory;
pub use db::models::conv::SqlTypeConvert;
pub use db::models::queries::StorageMapValuesPage;
pub use db::{
    AccountVaultValue,
    DatabaseOptions,
    Db,
    NoteRecord,
    NoteSyncRecord,
    NoteSyncUpdate,
    NullifierInfo,
    TransactionRecord,
};
pub use errors::{
    AccountStateForestUpdateError,
    ApplyBlockError,
    ApplyBlockWithProvingInputsError,
    DatabaseError,
    GetAccountError,
    GetBlockHeaderError,
    GetBlockInclusionProofsError,
    GetNoteInclusionProofsError,
    NoteSyncError,
    RangeBeyondTip,
    StateSyncError,
};
pub use genesis::GenesisState;
pub use state::{
    BlockWriter,
    LoadedState,
    ProofWriter,
    ScopedBlockNum,
    ScopedBlockRange,
    State,
    StateView,
    StateWitnesses,
    WriterTask,
};

/// Returns the store crate version.
pub fn version() -> &'static str {
    env!("CARGO_PKG_VERSION")
}

/// Returns the default number of SQLite connections used by store database pools.
pub fn default_sqlite_connection_pool_size() -> std::num::NonZeroUsize {
    DatabaseOptions::default().connection_pool_size
}

/// Test-only helpers exposed for downstream integration tests.
///
/// This module is hidden from public docs and not part of the stable API. It exists so
/// integration tests in sibling crates (e.g. `miden-node-rpc`) can seed network-account
/// rows directly into the store's SQLite database without us widening the visibility of
/// the internal query layer.
#[doc(hidden)]
pub mod test_support {
    use std::path::Path;

    use miden_protocol::Word;
    use miden_protocol::account::AccountId;
    use miden_protocol::block::BlockNumber;

    use crate::db::queries::{AccountRow, NetworkAccountType};
    use crate::errors::DatabaseError;

    /// Opens a fresh connection to the store's SQLite database and inserts a private
    /// network-account row for `account_id`, marking it as a network account in the
    /// latest state at block 0.
    ///
    /// Intended for integration tests that need to exercise the network-account gate
    /// without running a transaction through the block producer. The store's WAL mode
    /// makes a secondary connection safe.
    pub async fn seed_network_account(db_path: &Path, account_id: AccountId) {
        let (writer, _reader) =
            miden_node_db::sqlite::open(db_path).expect("connect to store sqlite");

        writer
            .write::<_, DatabaseError, _>("seed network account", move |tx| {
                AccountRow::new_private(
                    account_id,
                    NetworkAccountType::Network,
                    Word::default(),
                    BlockNumber::from(0),
                    BlockNumber::from(0),
                )
                .upsert(tx)
            })
            .await
            .expect("insert network account row");
    }
}

// CONSTANTS
// =================================================================================================
const COMPONENT: &str = "miden-store";
const LOG_TARGET: &str = "user::miden-store";