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