Skip to main content

miden_node_store/
lib.rs

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