Skip to content

Commit

Permalink
feat: upgrade simulation to a CLI (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhgomes authored and Boyuan Feng committed Jun 2, 2022
1 parent 8c32882 commit 743853c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
3 changes: 2 additions & 1 deletion manta-pay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ required-features = ["groth16", "manta-crypto/getrandom", "test"]

[[bin]]
name = "simulation"
required-features = ["groth16", "simulation"]
required-features = ["clap", "groth16", "simulation"]

[features]
# Enable Arkworks Backend
Expand Down Expand Up @@ -117,6 +117,7 @@ ark-std = { version = "0.3.0", optional = true, default-features = false }
bip32 = { version = "0.3.0", optional = true, default-features = false, features = ["bip39", "secp256k1"] }
blake2 = { version = "0.10.4", default-features = false }
bs58 = { version = "0.4.0", optional = true, default-features = false, features = ["alloc"] }
clap = { version = "3.1.15", optional = true, default-features = false, features = ["color", "derive", "std", "suggestions", "unicode", "wrap_help"] }
derivative = { version = "2.2.0", default-features = false, features = ["use_core"] }
futures = { version = "0.3.21", optional = true, default-features = false }
indexmap = { version = "1.8.0", optional = true, default-features = false }
Expand Down
42 changes: 24 additions & 18 deletions manta-pay/src/bin/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@

//! Manta Pay Simulation
// TODO: Add CLI interface and configuration for simulation parameters. See the old simulation code
// `test/simulation/mod.rs` for more information.

use clap::{error::ErrorKind, CommandFactory, Parser};
use manta_accounting::transfer::canonical::generate_context;
use manta_crypto::rand::{OsRng, Rand};
use manta_pay::{config::FullParameters, simulation::Simulation};

/// Runs the Manta Pay simulation.
#[tokio::main(flavor = "multi_thread", worker_threads = 4)]
pub async fn main() {
pub fn main() {
let simulation = Simulation::parse();
let mut rng = OsRng;
let parameters = rng.gen();
let utxo_accumulator_model = rng.gen();
Expand All @@ -35,18 +33,26 @@ pub async fn main() {
&mut rng,
)
.expect("Failed to generate contexts.");
Simulation {
actor_count: 10,
actor_lifetime: 10,
asset_id_count: 3,
starting_balance: 1000000,
match tokio::runtime::Builder::new_multi_thread()
.worker_threads(4)
.build()
{
Ok(runtime) => runtime.block_on(async {
simulation
.run(
&parameters,
&utxo_accumulator_model,
&proving_context,
verifying_context,
&mut rng,
)
.await
}),
Err(err) => Simulation::command()
.error(
ErrorKind::Io,
format_args!("Unable to start `tokio` runtime: {}", err),
)
.exit(),
}
.run(
&parameters,
&utxo_accumulator_model,
&proving_context,
verifying_context,
&mut rng,
)
.await
}
1 change: 1 addition & 0 deletions manta-pay/src/simulation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ where
}

/// Simulation Configuration
#[cfg_attr(feature = "clap", derive(clap::Parser))]
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub struct Simulation {
/// Actor Count
Expand Down

0 comments on commit 743853c

Please sign in to comment.