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