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