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/// internal diesel types.
74#[doc(hidden)]
75pub mod test_support {
76    use std::path::Path;
77
78    use diesel::prelude::*;
79    use miden_protocol::Word;
80    use miden_protocol::account::AccountId;
81    use miden_protocol::block::BlockNumber;
82
83    use crate::db::models::queries::{AccountRowInsert, NetworkAccountType};
84    use crate::db::schema;
85
86    /// Opens a fresh connection to the store's SQLite database and inserts a private
87    /// network-account row for `account_id`, marking it as a network account in the
88    /// latest state at block 0.
89    ///
90    /// Intended for integration tests that need to exercise the network-account gate
91    /// without running a transaction through the block producer. The store's WAL mode
92    /// makes a secondary connection safe.
93    pub fn seed_network_account(db_path: &Path, account_id: AccountId) {
94        let mut conn = SqliteConnection::establish(db_path.to_str().expect("db path is utf-8"))
95            .expect("connect to store sqlite");
96
97        let row = AccountRowInsert::new_private(
98            account_id,
99            NetworkAccountType::Network,
100            Word::default(),
101            BlockNumber::from(0),
102            BlockNumber::from(0),
103        );
104        diesel::insert_into(schema::accounts::table)
105            .values(&row)
106            .execute(&mut conn)
107            .expect("insert network account row");
108    }
109}
110
111// CONSTANTS
112// =================================================================================================
113const COMPONENT: &str = "miden-store";
114const LOG_TARGET: &str = "user::miden-store";