miden_node_store/state/
bootstrap.rs1use std::path::Path;
2
3use anyhow::Context;
4use miden_node_tracing::{debug, instrument};
5
6use crate::DataDirectory;
7use crate::blocks::BlockStore;
8use crate::db::Db;
9use crate::genesis::GenesisBlock;
10use crate::state::State;
11
12impl State {
13 #[instrument(name = "bootstrap", err)]
16 pub async fn bootstrap(genesis: GenesisBlock, data_directory: &Path) -> anyhow::Result<()> {
17 let data_directory =
18 DataDirectory::load(data_directory.to_path_buf()).with_context(|| {
19 format!("failed to load data directory at {}", data_directory.display())
20 })?;
21 debug!("Data directory loaded", path = data_directory);
22
23 let block_store_path = data_directory.block_store_dir();
24 let _block_store =
25 BlockStore::bootstrap(block_store_path.clone(), &genesis).with_context(|| {
26 format!("failed to bootstrap block store at {}", block_store_path.display())
27 })?;
28 debug!("Block store created", path = block_store_path);
29
30 let database_filepath = data_directory.database_path();
31 Db::bootstrap(database_filepath.clone(), genesis).await.with_context(|| {
32 format!("failed to bootstrap database at {}", database_filepath.display())
33 })?;
34 debug!("Database created", path = database_filepath);
35
36 Ok(())
37 }
38}