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