From 814458a5858939868de0296afca360bf36eca933 Mon Sep 17 00:00:00 2001 From: SantiagoPittella Date: Thu, 30 Jan 2025 11:33:30 -0300 Subject: [PATCH] fix: lint --- bin/stress-test/src/main.rs | 47 +++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/bin/stress-test/src/main.rs b/bin/stress-test/src/main.rs index 55d05aced..b4cb537e1 100644 --- a/bin/stress-test/src/main.rs +++ b/bin/stress-test/src/main.rs @@ -7,9 +7,8 @@ use std::{ use anyhow::Context; use clap::{Parser, Subcommand}; use miden_lib::{ - account::{self, auth::RpoFalcon512, faucets::BasicFungibleFaucet, wallets::BasicWallet}, + account::{auth::RpoFalcon512, faucets::BasicFungibleFaucet, wallets::BasicWallet}, note::create_p2id_note, - transaction::TransactionKernel, }; use miden_node_block_producer::{ batch_builder::TransactionBatch, block_builder::BlockBuilder, store::StoreClient, @@ -23,13 +22,12 @@ use miden_objects::{ block::BlockHeader, crypto::dsa::rpo_falcon512::{PublicKey, SecretKey}, note::{Note, NoteInclusionProof}, - testing::note::NoteBuilder, transaction::{OutputNote, ProvenTransaction}, - Digest, Felt, MAX_OUTPUT_NOTES_PER_BATCH, + Digest, Felt, }; use miden_processor::crypto::{MerklePath, RpoRandomCoin}; use rand::Rng; -use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator}; +use rayon::iter::{IntoParallelIterator, ParallelIterator}; use tokio::{ sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender}, task, @@ -63,7 +61,6 @@ pub enum Command { const BATCHES_PER_BLOCK: usize = 16; const TRANSACTIONS_PER_BATCH: usize = 16; -const NOTES_PER_TRANSACTION: usize = MAX_OUTPUT_NOTES_PER_BATCH / TRANSACTIONS_PER_BATCH; /// Create and store blocks into the store. Create a given number of accounts, where each account /// consumes a note created from a faucet. The cli accepts the following parameters: @@ -112,7 +109,7 @@ async fn seed_store(dump_file: &Path, num_accounts: usize, genesis_file: &Path) ) .unwrap(); - let _block = BlockBuilder::new(store_client.clone()).build_block(&[batch]).await.unwrap(); + BlockBuilder::new(store_client.clone()).build_block(&[batch]).await.unwrap(); // Number of accounts per block let num_accounts_per_block = TRANSACTIONS_PER_BATCH * BATCHES_PER_BLOCK; @@ -123,9 +120,12 @@ async fn seed_store(dump_file: &Path, num_accounts: usize, genesis_file: &Path) // Shared random coin seed and key pair for all accounts let coin_seed: [u64; 4] = rand::thread_rng().gen(); - let mut rng = RpoRandomCoin::new(coin_seed.map(Felt::new)); + let rng = Arc::new(Mutex::new(RpoRandomCoin::new(coin_seed.map(Felt::new)))); // Re-using the same key for all accounts to avoid Falcon key generation overhead - let key_pair = SecretKey::with_rng(&mut rng); + let key_pair = { + let mut rng = rng.lock().unwrap(); + SecretKey::with_rng(&mut *rng) + }; let start_generating_accounts = Instant::now(); @@ -133,7 +133,10 @@ async fn seed_store(dump_file: &Path, num_accounts: usize, genesis_file: &Path) (0..num_accounts).into_par_iter().for_each(|account_index| { let account = create_account(&genesis_header, key_pair.public_key(), (account_index) as u64); - let note = create_note(faucet_id, account); + let note = { + let mut rng = rng.lock().unwrap(); + create_note(faucet_id, account, &mut rng) + }; let path = MerklePath::new(vec![]); let inclusion_proof = NoteInclusionProof::new(0.into(), 0, path).unwrap(); @@ -167,7 +170,7 @@ async fn seed_store(dump_file: &Path, num_accounts: usize, genesis_file: &Path) // Create notes println!("Creating notes..."); - let _notes = task::spawn_blocking(move || { + task::spawn_blocking(move || { generate_batches( num_accounts, faucet_id, @@ -209,16 +212,17 @@ fn print_metrics( avg_insertion_time += *time; if (i + 1) % 1000 == 0 { println!( - "Inserted {} blocks with avg insertion time {} ms", - i + 1, + "Inserted from block {} to block {} with avg insertion time {} ms", + i - 999, + i, (avg_insertion_time / 1000).as_millis() ); avg_insertion_time = Duration::default(); } } - // Print out the store file size every 1k blocks to track the growth of the file. - println!("Store file size every 1k blocks:"); + // Print out the store file size every 1k batches to track the growth of the file. + println!("Store file size every 1k batches:"); for (i, size) in store_file_size_over_time.iter().enumerate() { println!("{}: {} bytes", i * 1000, size); } @@ -228,7 +232,7 @@ fn print_metrics( let final_size = store_file_size_over_time.last().unwrap(); let growth_rate = (final_size - initial_size) as f64 / num_insertions as f64; - println!("Average growth rate: {} bytes per block", growth_rate); + println!("Average growth rate: {} bytes per batch", growth_rate); } /// Create a new faucet account with a given anchor block. @@ -254,17 +258,15 @@ fn create_faucet(anchor_block: &BlockHeader) -> AccountId { /// Create a new note containing 10 tokens of the fungible asset associated with the specified /// `faucet_id`. -fn create_note(faucet_id: AccountId, receipient: AccountId) -> Note { +fn create_note(faucet_id: AccountId, receipient: AccountId, rng: &mut RpoRandomCoin) -> Note { let asset = Asset::Fungible(FungibleAsset::new(faucet_id, 10).unwrap()); - let coin_seed: [u64; 4] = rand::thread_rng().gen(); - let mut rng = RpoRandomCoin::new(coin_seed.map(Felt::new)); create_p2id_note( faucet_id, receipient, vec![asset], miden_objects::note::NoteType::Public, Felt::default(), - &mut rng, + rng, ) .expect("note creation failed") } @@ -319,7 +321,8 @@ async fn build_blocks( if counter % 1000 == 0 { let store_file_size = std::fs::metadata("./miden-store.sqlite3").unwrap().len(); - store_file_sizes.push(store_file_size); + let wal_file_size = std::fs::metadata("./miden-store.sqlite3-wal").unwrap().len(); + store_file_sizes.push(store_file_size + wal_file_size); } counter += 1; @@ -351,8 +354,6 @@ fn generate_batches( let total_blocks = (num_accounts / consumes_per_block) + 1; // +1 to account for the first block with the send assets tx only for i in 0..total_blocks { - println!("Creating block {}/{}...", i + 1, total_blocks); - let start = i * consumes_per_block; let end = ((i * consumes_per_block) + consumes_per_block).min(num_accounts); let accounts_notes_txs_0 = accounts_and_notes[start..end].to_vec();