Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/node/src/commands/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl BootstrapCommand {
let genesis_block =
read_bootstrap_genesis_block(self.genesis_block_file.as_deref(), self.network).await?;
let genesis_commitment = genesis_block.inner().header().commitment();
State::bootstrap(genesis_block, &self.data_directory)?;
State::bootstrap(genesis_block, &self.data_directory).await?;
info!(
target: crate::LOG_TARGET,
"Node bootstrap complete",
Expand Down
4 changes: 3 additions & 1 deletion bin/stress-test/src/seeding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ pub async fn seed_store_with_readers(
);
let genesis_block = genesis_state.into_block().expect("genesis block should be created");
let genesis_header = genesis_block.inner().header().clone();
State::bootstrap(genesis_block, &data_directory).expect("store should bootstrap");
State::bootstrap(genesis_block, &data_directory)
.await
.expect("store should bootstrap");

let (state, mut block_writer, writer_task) = load_state(data_directory.clone()).await;

Expand Down
2 changes: 1 addition & 1 deletion bin/validator/src/commands/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ mod tests {
assert_eq!(config.to_commitment(), commitment);
let node_directory = root.path().join("node");
fs_err::create_dir(&node_directory).unwrap();
miden_node_store::State::bootstrap(genesis, &node_directory).unwrap();
miden_node_store::State::bootstrap(genesis, &node_directory).await.unwrap();
let directories = miden_node_store::DataDirectory::load(node_directory).unwrap();
let block_store = BlockStore::load(directories.block_store_dir()).unwrap();
assert_eq!(block_store.load_block(BlockNumber::GENESIS).await.unwrap(), Some(block_bytes));
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/batch_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ mod tests {
)?,
chain.protocol_config().clone(),
)?;
State::bootstrap(genesis, directory.path())?;
State::bootstrap(genesis, directory.path()).await?;
let (state, ..) = State::for_tests(directory.path()).await;
let inputs = get_tx_inputs(&state, &transaction).await?;
let transaction =
Expand Down
2 changes: 1 addition & 1 deletion crates/block-producer/src/fee_collector/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async fn collector_deployment_proves_the_block_and_supports_a_new_collector() {
transactions: Arc::new(Mutex::new(BTreeSet::new())),
reject_transaction: Arc::new(AtomicBool::new(true)),
};
State::bootstrap(genesis, directory.path()).unwrap();
State::bootstrap(genesis, directory.path()).await.unwrap();
let shutdown = CancellationToken::new();
let (state, mut writer, mut proof_writer, writer_task) =
State::load(directory.path(), StorageOptions::default())
Expand Down
11 changes: 6 additions & 5 deletions crates/block-producer/src/fee_collector/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ mod tests {
chain.add_account(faucet.clone())?;
let mut chain = chain.build()?;
let directory = tempfile::tempdir()?;
bootstrap(&chain, directory.path())?;
bootstrap(&chain, directory.path()).await?;
let (state, mut writer, _proof_writer) = State::for_tests(directory.path()).await;
let target = ACCOUNT_ID_REGULAR_PRIVATE_ACCOUNT_UPDATABLE_CODE.try_into()?;
let mut builder =
Expand Down Expand Up @@ -446,7 +446,7 @@ mod tests {
chain.add_account(collector.account().clone())?;
let mut chain = chain.fee_faucet_id(faucet.id()).build()?;
let directory = tempfile::tempdir()?;
bootstrap(&chain, directory.path())?;
bootstrap(&chain, directory.path()).await?;
let (state, mut writer, _proof_writer) = State::for_tests(directory.path()).await;
let asset = FungibleAsset::new(faucet.id(), 20)?;
let note = TxFeeNote::builder()
Expand Down Expand Up @@ -515,7 +515,7 @@ mod tests {
Ok(())
}

fn bootstrap(chain: &MockChain, path: &Path) -> anyhow::Result<()> {
async fn bootstrap(chain: &MockChain, path: &Path) -> anyhow::Result<()> {
let genesis = chain.latest_block();
State::bootstrap(
GenesisBlock::new(
Expand All @@ -528,12 +528,13 @@ mod tests {
)?,
path,
)
.await
}

#[tokio::test(flavor = "multi_thread")]
async fn rejects_missing_or_mismatched_signing_keys() -> anyhow::Result<()> {
let directory = tempfile::tempdir()?;
bootstrap(&MockChain::builder().build()?, directory.path())?;
bootstrap(&MockChain::builder().build()?, directory.path()).await?;
let (state, ..) = State::for_tests(directory.path()).await;
let (account, _) = mock_collection_account().into_parts();
let target = ACCOUNT_ID_REGULAR_PRIVATE_ACCOUNT_UPDATABLE_CODE.try_into()?;
Expand All @@ -554,7 +555,7 @@ mod tests {
#[tokio::test(flavor = "multi_thread")]
async fn rejects_an_ordinary_wallet_as_the_collector() -> anyhow::Result<()> {
let directory = tempfile::tempdir()?;
bootstrap(&MockChain::builder().build()?, directory.path())?;
bootstrap(&MockChain::builder().build()?, directory.path()).await?;
let (state, ..) = State::for_tests(directory.path()).await;
let account = MockChain::builder().add_existing_wallet(Auth::basic_ecdsa())?;
let target = ACCOUNT_ID_REGULAR_PRIVATE_ACCOUNT_UPDATABLE_CODE.try_into()?;
Expand Down
4 changes: 3 additions & 1 deletion crates/block-producer/src/rpc_sync/block_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ async fn sync_blocks(
blocks: Vec<SignedBlock>,
) -> (anyhow::Result<()>, BlockHeader) {
let directory = tempfile::tempdir().unwrap();
State::bootstrap(genesis.clone().into_block().unwrap(), directory.path()).unwrap();
State::bootstrap(genesis.clone().into_block().unwrap(), directory.path())
.await
.unwrap();
let (state, writer, _proof_writer, writer_task) =
State::load(directory.path(), StorageOptions::default())
.await
Expand Down
6 changes: 3 additions & 3 deletions crates/block-producer/src/server/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async fn block_producer_starts_with_store_state() {
let account_file = crate::test_utils::mock_collection_account();
let mut deployed_account = account_file.account().clone();
deployed_account.set_nonce(ONE).unwrap();
bootstrap_store(data_directory.path(), deployed_account);
bootstrap_store(data_directory.path(), deployed_account).await;
let (state, block_writer, proof_writer) = State::for_tests(data_directory.path()).await;
let shutdown = miden_node_utils::shutdown::CancellationToken::new();

Expand Down Expand Up @@ -112,7 +112,7 @@ async fn block_producer_starts_with_store_state() {
block_producer.wait().await.unwrap();
}

fn bootstrap_store(path: &std::path::Path, account: Account) {
async fn bootstrap_store(path: &std::path::Path, account: Account) {
let signer = random_secret_key();
let faucet = crate::test_utils::mock_native_faucet();
let config = ProtocolConfig::current(AssetId::new_fungible(faucet.id())).unwrap();
Expand All @@ -125,5 +125,5 @@ fn bootstrap_store(path: &std::path::Path, account: Account) {
);
let genesis_block = genesis_state.into_block().expect("genesis block should be created");

State::bootstrap(genesis_block, path).expect("store should bootstrap");
State::bootstrap(genesis_block, path).await.expect("store should bootstrap");
}
31 changes: 18 additions & 13 deletions crates/rpc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl TestStore {
async fn start_with_base_fee(verification_base_fee: u32) -> Self {
let data_directory = new_tempdir();
let genesis_commitment =
Self::bootstrap_with_base_fee(&data_directory, verification_base_fee);
Self::bootstrap_with_base_fee(&data_directory, verification_base_fee).await;
let (state, writer, ..) = State::for_tests(&data_directory).await;
Self {
state,
Expand All @@ -181,7 +181,8 @@ impl TestStore {
) -> Self {
let data_directory = new_tempdir();
let genesis_commitment =
Self::bootstrap_from_mock_genesis(&data_directory, genesis_block, protocol_config);
Self::bootstrap_from_mock_genesis(&data_directory, genesis_block, protocol_config)
.await;
let (state, writer, ..) = State::for_tests(&data_directory).await;
Self {
state,
Expand All @@ -191,11 +192,11 @@ impl TestStore {
}
}

fn bootstrap(path: &std::path::Path) -> Word {
Self::bootstrap_with_base_fee(path, 0)
async fn bootstrap(path: &std::path::Path) -> Word {
Self::bootstrap_with_base_fee(path, 0).await
}

fn bootstrap_with_base_fee(path: &std::path::Path, verification_base_fee: u32) -> Word {
async fn bootstrap_with_base_fee(path: &std::path::Path, verification_base_fee: u32) -> Word {
let config = GenesisConfig::default();
let validator_key =
miden_protocol::crypto::dsa::ecdsa_k256_keccak::SigningKey::read_from_bytes(&[7; 32])
Expand All @@ -220,12 +221,12 @@ impl TestStore {
genesis_state.clone().into_block().expect("genesis block should be created");
let genesis_commitment = genesis_block.inner().header().commitment();

State::bootstrap(genesis_block, path).expect("store should bootstrap");
State::bootstrap(genesis_block, path).await.expect("store should bootstrap");

genesis_commitment
}

fn bootstrap_from_mock_genesis(
async fn bootstrap_from_mock_genesis(
path: &std::path::Path,
genesis_block: &ProvenBlock,
protocol_config: &ProtocolConfig,
Expand All @@ -241,7 +242,9 @@ impl TestStore {
.expect("mock genesis should become a store genesis block after stripping signatures");
let genesis_commitment = genesis_block.inner().header().commitment();

State::bootstrap(genesis_block, path).expect("store should bootstrap from mock genesis");
State::bootstrap(genesis_block, path)
.await
.expect("store should bootstrap from mock genesis");

genesis_commitment
}
Expand Down Expand Up @@ -813,7 +816,7 @@ async fn rpc_server_forwards_valid_deferred_proofs_and_rejects_missing_witnesses
let genesis =
GenesisBlock::new(fixture.genesis.clone(), fixture.inputs.protocol_config().clone())
.unwrap();
State::bootstrap(genesis, &data_directory).unwrap();
State::bootstrap(genesis, &data_directory).await.unwrap();
let (state, ..) = State::for_tests(&data_directory).await;
let submissions = Arc::new(std::sync::Mutex::new(Vec::new()));
let (validator, _, _, _guard) =
Expand Down Expand Up @@ -934,7 +937,8 @@ async fn rpc_rejects_post_deployment_network_account_tx() {
miden_node_store::test_support::seed_network_account(
&store.data_directory_path().join("miden-store.sqlite3"),
network_account_id,
);
)
.await;

// Build a non-deployment tx for that account.
let (account, _) = build_test_account([0; 32]);
Expand Down Expand Up @@ -1093,10 +1097,11 @@ async fn start_source_rpc_with_genesis(
&block_producer_dir,
genesis_block,
protocol_config,
);
)
.await;
},
None => {
TestStore::bootstrap(&block_producer_dir);
TestStore::bootstrap(&block_producer_dir).await;
},
}
let (block_producer_state, ..) = State::for_tests(&block_producer_dir).await;
Expand Down Expand Up @@ -1740,7 +1745,7 @@ async fn start_rpc_with_allowlist(
AccountAdmission::enabled(allowlist)
};
let block_producer_dir = new_tempdir();
TestStore::bootstrap(&block_producer_dir);
TestStore::bootstrap(&block_producer_dir).await;
let (block_producer_state, ..) = State::for_tests(&block_producer_dir).await;
let state = Arc::clone(&store.state);

Expand Down
4 changes: 2 additions & 2 deletions crates/store/src/account_state_forest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ use miden_protocol::{EMPTY_WORD, Word};
use thiserror::Error;

use crate::COMPONENT;
pub use crate::db::models::queries::HISTORICAL_BLOCK_RETENTION;
use crate::db::models::queries::{PrecomputedPublicAccountState, PrecomputedPublicAccountStates};
pub use crate::db::HISTORICAL_BLOCK_RETENTION;
use crate::db::{PrecomputedPublicAccountState, PrecomputedPublicAccountStates};
use crate::errors::AccountStateForestUpdateError;

#[cfg(test)]
Expand Down
16 changes: 0 additions & 16 deletions crates/store/src/db/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,5 @@ pub fn verify_latest_schema(database_filepath: &Path) -> std::result::Result<(),
Ok(())
}

#[cfg(test)]
pub(crate) fn test_connection() -> diesel::SqliteConnection {
use diesel::{Connection, SqliteConnection};

let temp_dir = tempfile::tempdir().expect("failed to create temp directory");
let database_filepath = temp_dir.path().join("test.sqlite3");
bootstrap_database(&database_filepath).expect("database should bootstrap");

let conn = SqliteConnection::establish(
database_filepath.to_str().expect("temp database path should be valid UTF-8"),
)
.expect("temp file sqlite should always work");
let _kept_dir = temp_dir.keep();
conn
}

#[cfg(test)]
mod tests;
Loading
Loading