Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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?;
tracing::info!(
target: crate::LOG_TARGET,
{
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 @@ -234,7 +234,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
60 changes: 4 additions & 56 deletions crates/block-producer/src/server/tests.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
use std::num::NonZeroUsize;
use std::sync::Arc;
use std::time::Duration;

use miden_node_store::GenesisState;
use miden_node_store::state::State;
use miden_node_utils::fee::test_fee_params;
use miden_protocol::Word;
use miden_protocol::batch::ProvenBatch;
use miden_protocol::block::{BlockHeader, BlockNumber, ValidatorKeys};
use miden_protocol::block::{BlockNumber, ValidatorKeys};
use miden_protocol::testing::random_secret_key::random_secret_key;
use url::Url;

use crate::domain::transaction::AuthenticatedTransaction;
use crate::mempool::{Mempool, MempoolConfig};
use crate::server::MempoolStats;
use crate::test_utils::MockProvenTxBuilder;
use crate::test_utils::batch::TransactionBatchConstructor;
use crate::{
DEFAULT_BATCH_WORKERS,
DEFAULT_MAX_BATCHES_PER_BLOCK,
Expand All @@ -25,54 +17,10 @@ use crate::{
Sequencer,
};

#[test]
fn mempool_stats_track_uncommitted_work_and_the_canonical_tip() {
let shared = Mempool::shared(BlockNumber::GENESIS, MempoolConfig::default());
let mut mempool = shared.lock().unwrap();
let tx = Arc::new(AuthenticatedTransaction::from_inner(
MockProvenTxBuilder::with_account_index(100).build(),
));

mempool.add_transaction(Arc::clone(&tx)).unwrap();
let stats = MempoolStats::from_mempool(&mempool);
assert_eq!(stats.chain_tip, BlockNumber::GENESIS);
assert_eq!(stats.uncommitted_transactions, 1);
assert_eq!(stats.unbatched_transactions, 1);
assert_eq!(stats.proposed_batches, 0);
assert_eq!(stats.proven_batches, 0);

mempool.select_any_batch().unwrap();
let stats = MempoolStats::from_mempool(&mempool);
assert_eq!(stats.uncommitted_transactions, 1);
assert_eq!(stats.unbatched_transactions, 0);
assert_eq!(stats.proposed_batches, 1);
assert_eq!(stats.proven_batches, 0);

mempool.commit_batch(Arc::new(ProvenBatch::mocked_from_transactions([
tx.raw_proven_transaction()
])));
let stats = MempoolStats::from_mempool(&mempool);
assert_eq!(stats.proposed_batches, 0);
assert_eq!(stats.proven_batches, 1);

let block = mempool.select_block();
let stats = MempoolStats::from_mempool(&mempool);
assert_eq!(stats.chain_tip, BlockNumber::GENESIS);
assert_eq!(stats.uncommitted_transactions, 1);
assert_eq!(stats.proven_batches, 0);

let header = BlockHeader::mock(block.block_number, None, None, &[], Word::empty());
mempool.commit_block(&header);
let stats = MempoolStats::from_mempool(&mempool);
assert_eq!(stats.chain_tip, BlockNumber::GENESIS.child());
assert_eq!(stats.uncommitted_transactions, 0);
assert_eq!(stats.proven_batches, 0);
}

#[tokio::test]
async fn block_producer_starts_with_store_state() {
let data_directory = tempfile::tempdir().expect("tempdir should be created");
bootstrap_store(data_directory.path());
bootstrap_store(data_directory.path()).await;
let (state, block_writer, proof_writer) = State::for_tests(data_directory.path()).await;

let block_producer = Sequencer {
Expand All @@ -99,7 +47,7 @@ async fn block_producer_starts_with_store_state() {
assert_eq!(status.chain_tip, BlockNumber::GENESIS);
}

fn bootstrap_store(path: &std::path::Path) {
async fn bootstrap_store(path: &std::path::Path) {
let signer = random_secret_key();
let genesis_state = GenesisState::new(
vec![],
Expand All @@ -110,5 +58,5 @@ fn bootstrap_store(path: &std::path::Path) {
);
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");
}
13 changes: 7 additions & 6 deletions crates/rpc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl TestStore {

async fn start() -> Self {
let data_directory = new_tempdir();
let genesis_commitment = Self::bootstrap(&data_directory);
let genesis_commitment = Self::bootstrap(&data_directory).await;
let (state, ..) = State::for_tests(&data_directory).await;
Self {
state,
Expand All @@ -102,7 +102,7 @@ impl TestStore {
}
}

fn bootstrap(path: &std::path::Path) -> Word {
async fn bootstrap(path: &std::path::Path) -> Word {
let config = GenesisConfig::default();
let validator_key =
miden_protocol::crypto::dsa::ecdsa_k256_keccak::SigningKey::read_from_bytes(&[7; 32])
Expand All @@ -115,7 +115,7 @@ 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
}
Expand Down Expand Up @@ -434,7 +434,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 @@ -556,7 +557,7 @@ async fn start_source_rpc(
) -> (RpcClient, TestStore) {
let store = TestStore::start().await;
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 Expand Up @@ -1024,7 +1025,7 @@ async fn start_rpc() -> (RpcClient, std::net::SocketAddr, TestStore) {
let grpc_options = GrpcOptions::test();
let store = TestStore::start().await;
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