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