Skip to main content

miden_node_store/
lib.rs

1// Required by code generated by the upstream `#[instrument]` macro.
2extern crate miden_node_tracing as tracing;
3
4mod account_state_forest;
5mod accounts;
6pub mod allowlist;
7mod blocks;
8mod data_directory;
9mod db;
10mod errors;
11pub mod genesis;
12mod proven_tip;
13pub mod state;
14
15#[cfg(feature = "rocksdb")]
16pub use accounts::PersistentAccountTree;
17pub use accounts::{AccountTreeWithHistory, HistoricalError, InMemoryAccountTree};
18pub use blocks::BlockStore;
19pub use data_directory::DataDirectory;
20pub use db::queries::StorageMapValuesPage;
21pub use db::{
22    AccountVaultValue,
23    DatabaseOptions,
24    Db,
25    NoteRecord,
26    NoteSyncRecord,
27    NoteSyncUpdate,
28    NullifierInfo,
29    TransactionRecord,
30};
31pub use errors::{
32    AccountStateForestUpdateError,
33    ApplyBlockError,
34    ApplyBlockWithProvingInputsError,
35    DatabaseError,
36    GetAccountError,
37    GetBlockHeaderError,
38    GetBlockInclusionProofsError,
39    GetNoteInclusionProofsError,
40    NoteSyncError,
41    RangeBeyondTip,
42    StateSyncError,
43};
44pub use genesis::GenesisState;
45pub use state::{
46    BlockWriter,
47    LoadedState,
48    ProofWriter,
49    ScopedBlockNum,
50    ScopedBlockRange,
51    State,
52    StateView,
53    StateWitnesses,
54    WriterTask,
55};
56
57/// Returns the store crate version.
58pub fn version() -> &'static str {
59    env!("CARGO_PKG_VERSION")
60}
61
62/// Returns the default number of SQLite connections used by store database pools.
63pub fn default_sqlite_connection_pool_size() -> std::num::NonZeroUsize {
64    DatabaseOptions::default().connection_pool_size
65}
66
67/// Test-only helpers exposed for downstream integration tests.
68///
69/// This module is hidden from public docs and not part of the stable API. It exists so
70/// integration tests in sibling crates (e.g. `miden-node-rpc`) can seed network-account
71/// rows directly into the store's SQLite database without us widening the visibility of
72/// the internal query layer.
73#[doc(hidden)]
74pub mod test_support {
75    use std::path::Path;
76
77    use miden_protocol::Word;
78    use miden_protocol::account::AccountId;
79    use miden_protocol::block::BlockNumber;
80
81    use crate::db::queries::{AccountRow, NetworkAccountType};
82    use crate::errors::DatabaseError;
83
84    /// Opens a fresh connection to the store's SQLite database and inserts a private
85    /// network-account row for `account_id`, marking it as a network account in the
86    /// latest state at block 0.
87    ///
88    /// Intended for integration tests that need to exercise the network-account gate
89    /// without running a transaction through the block producer. The store's WAL mode
90    /// makes a secondary connection safe.
91    pub async fn seed_network_account(db_path: &Path, account_id: AccountId) {
92        let (writer, _reader) =
93            miden_node_db::sqlite::open(db_path).expect("connect to store sqlite");
94
95        writer
96            .write::<_, DatabaseError, _>("seed network account", move |tx| {
97                AccountRow::new_private(
98                    account_id,
99                    NetworkAccountType::Network,
100                    Word::default(),
101                    BlockNumber::from(0),
102                    BlockNumber::from(0),
103                )
104                .upsert(tx)
105            })
106            .await
107            .expect("insert network account row");
108    }
109}
110
111// CONSTANTS
112// =================================================================================================
113const COMPONENT: &str = "miden-store";
114const LOG_TARGET: &str = "user::miden-store";