forked from 0xPolygonMiden/miden-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c17dbc
commit e66a8b5
Showing
10 changed files
with
185 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[package] | ||
name = "miden-stress-test" | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
version.workspace = true | ||
license.workspace = true | ||
authors.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
exclude.workspace = true | ||
readme.workspace = true | ||
|
||
[dependencies] | ||
async-trait = { version = "0.1" } | ||
anyhow = "1.0" | ||
itertools = { version = "0.13" } | ||
miden-lib = { workspace = true } | ||
miden-node-proto = { workspace = true } | ||
miden-node-utils = { workspace = true } | ||
miden-objects = { workspace = true } | ||
miden-processor = { workspace = true } | ||
miden-stdlib = { workspace = true } | ||
miden-tx = { workspace = true } | ||
miden-node-block-producer = { workspace = true } | ||
miden-node-store = { workspace = true } | ||
rand = { version = "0.8" } | ||
serde = { version = "1.0", features = ["derive"] } | ||
thiserror = { workspace = true } | ||
tokio = { workspace = true, features = ["rt-multi-thread", "net", "macros", "sync", "time"] } | ||
tokio-stream = { workspace = true, features = ["net"] } | ||
tonic = { workspace = true } | ||
tracing = { workspace = true } | ||
rand_chacha = "0.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
use anyhow::Context; | ||
use miden_lib::{ | ||
accounts::{auth::RpoFalcon512, faucets::BasicFungibleFaucet, wallets::BasicWallet}, | ||
transaction::TransactionKernel, | ||
}; | ||
use miden_node_block_producer::{ | ||
batch_builder::TransactionBatch, config::BlockProducerConfig, server::BlockProducer, | ||
test_utils::MockProvenTxBuilder, | ||
}; | ||
use miden_node_store::{config::StoreConfig, server::Store}; | ||
use miden_objects::{ | ||
accounts::{AccountBuilder, AccountIdAnchor, AccountStorageMode, AccountType}, | ||
assets::{Asset, FungibleAsset, TokenSymbol}, | ||
crypto::dsa::rpo_falcon512::SecretKey, | ||
testing::notes::NoteBuilder, | ||
transaction::OutputNote, | ||
Digest, Felt, | ||
}; | ||
use miden_processor::crypto::RpoRandomCoin; | ||
use rand::Rng; | ||
use tokio::task::JoinSet; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let block_producer_config = BlockProducerConfig::default(); | ||
let store_config = StoreConfig::default(); | ||
let mut join_set = JoinSet::new(); | ||
|
||
// Start store | ||
let store = Store::init(store_config).await.context("Loading store").unwrap(); | ||
let _ = join_set.spawn(async move { store.serve().await.context("Serving store") }).id(); | ||
|
||
// Start block-producer | ||
// TODO: is the full the BlockProducer needed? we should instantiate only a BlockBuilder | ||
let block_producer = BlockProducer::init(block_producer_config) | ||
.await | ||
.context("Loading block-producer") | ||
.unwrap(); | ||
|
||
println!("Creating new faucet account..."); | ||
let coin_seed: [u64; 4] = rand::thread_rng().gen(); | ||
let mut rng = RpoRandomCoin::new(coin_seed.map(Felt::new)); | ||
let key_pair = SecretKey::with_rng(&mut rng); | ||
let init_seed = [0_u8; 32]; | ||
let (new_faucet, _seed) = AccountBuilder::new() | ||
.init_seed(init_seed) | ||
.anchor(AccountIdAnchor::PRE_GENESIS) | ||
.account_type(AccountType::FungibleFaucet) | ||
.storage_mode(AccountStorageMode::Private) | ||
.with_component(RpoFalcon512::new(key_pair.public_key())) | ||
.with_component( | ||
BasicFungibleFaucet::new(TokenSymbol::new("TEST").unwrap(), 2, Felt::new(100_000)) | ||
.unwrap(), | ||
) | ||
.build() | ||
.unwrap(); | ||
let faucet_id = new_faucet.id(); | ||
|
||
// The amount of blocks to create and process. Each block contains 4 batches. | ||
// Each batch contains 2 txs: one to create a note and another to consume it. | ||
const N_BLOCKS: usize = 250_000; // 250_000 blocks * 4 batches/block * 1 accounts/batch = 1_000_000 accounts | ||
|
||
for block_num in 0..N_BLOCKS { | ||
let mut batches = Vec::with_capacity(4); | ||
for _ in 0..4 { | ||
// Create wallet | ||
let (new_account, _) = AccountBuilder::new() | ||
.init_seed(init_seed) | ||
.anchor(AccountIdAnchor::PRE_GENESIS) | ||
.account_type(AccountType::RegularAccountImmutableCode) | ||
.storage_mode(AccountStorageMode::Private) | ||
.with_component(RpoFalcon512::new(key_pair.public_key())) | ||
.with_component(BasicWallet) | ||
.build() | ||
.unwrap(); | ||
let account_id = new_account.id(); | ||
|
||
// Create note | ||
let asset = Asset::Fungible(FungibleAsset::new(faucet_id, 10).unwrap()); | ||
let coin_seed: [u64; 4] = rand::thread_rng().gen(); | ||
let rng: RpoRandomCoin = RpoRandomCoin::new(coin_seed.map(Felt::new)); | ||
let note = NoteBuilder::new(faucet_id, rng) | ||
.add_assets(vec![asset.clone()]) | ||
.build(&TransactionKernel::assembler()) | ||
.unwrap(); | ||
|
||
let batch = { | ||
// First tx: create the note | ||
let create_notes_tx = MockProvenTxBuilder::with_account( | ||
faucet_id, | ||
Digest::default(), | ||
Digest::default(), | ||
) | ||
.output_notes(vec![OutputNote::Full(note.clone())]) | ||
.build(); | ||
|
||
// Second tx: consume the note | ||
let consume_notes_txs = MockProvenTxBuilder::with_account( | ||
account_id, | ||
Digest::default(), | ||
Digest::default(), | ||
) | ||
.unauthenticated_notes(vec![note]) | ||
.build(); | ||
|
||
TransactionBatch::new([&create_notes_tx, &consume_notes_txs], Default::default()) | ||
.unwrap() | ||
}; | ||
batches.push(batch); | ||
} | ||
println!("Building block {}...", block_num); | ||
// Inserts the block into the store sending it via StoreClient (RPC) | ||
block_producer.block_builder.build_block(&batches).await.unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters