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