mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-08 22:28:12 -05:00
crypsinous_playground: simulation epochs as arg
This commit is contained in:
@@ -11,3 +11,6 @@
|
|||||||
|
|
||||||
# Password for the wallet database
|
# Password for the wallet database
|
||||||
#wallet_pass = "changeme"
|
#wallet_pass = "changeme"
|
||||||
|
|
||||||
|
# How many epochs to simulate
|
||||||
|
#epochs = 1
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ struct Args {
|
|||||||
#[structopt(long, default_value = "changeme")]
|
#[structopt(long, default_value = "changeme")]
|
||||||
/// Password for the wallet database
|
/// Password for the wallet database
|
||||||
wallet_pass: String,
|
wallet_pass: String,
|
||||||
|
|
||||||
|
#[structopt(short, default_value = "1")]
|
||||||
|
/// How many epochs to simulate
|
||||||
|
epochs: u64,
|
||||||
|
|
||||||
#[structopt(short, parse(from_occurrences))]
|
#[structopt(short, parse(from_occurrences))]
|
||||||
/// Increase verbosity (-vvv supported)
|
/// Increase verbosity (-vvv supported)
|
||||||
@@ -45,6 +49,14 @@ struct Args {
|
|||||||
// Other flows that happen through a slot, like broadcasting blocks or syncing are out of scope.
|
// Other flows that happen through a slot, like broadcasting blocks or syncing are out of scope.
|
||||||
async_daemonize!(realmain);
|
async_daemonize!(realmain);
|
||||||
async fn realmain(args: Args, _ex: Arc<smol::Executor<'_>>) -> Result<()> {
|
async fn realmain(args: Args, _ex: Arc<smol::Executor<'_>>) -> Result<()> {
|
||||||
|
|
||||||
|
// Epochs sanity check
|
||||||
|
let epochs = args.epochs;
|
||||||
|
if epochs < 1 {
|
||||||
|
error!("Epochs must be a positive number.");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
info!("Simulation epochs: {}", epochs);
|
||||||
|
|
||||||
// Initialize wallet that holds coins for staking
|
// Initialize wallet that holds coins for staking
|
||||||
let wallet = init_wallet(&args.wallet_path, &args.wallet_pass).await?;
|
let wallet = init_wallet(&args.wallet_path, &args.wallet_pass).await?;
|
||||||
@@ -69,40 +81,38 @@ async fn realmain(args: Args, _ex: Arc<smol::Executor<'_>>) -> Result<()> {
|
|||||||
let proving_key = ProvingKey::build(k, &LeadContract::default());
|
let proving_key = ProvingKey::build(k, &LeadContract::default());
|
||||||
let verifying_key = VerifyingKey::build(k, &LeadContract::default());
|
let verifying_key = VerifyingKey::build(k, &LeadContract::default());
|
||||||
|
|
||||||
// Simulating an epoch with 10 slots
|
// Simulating epochs with 10 slots
|
||||||
let epoch = 0;
|
for epoch in 0..epochs {
|
||||||
let slot = 0;
|
info!("Epoch {} started!", epoch);
|
||||||
info!("Epoch {} started!", epoch);
|
// Generating epoch coins
|
||||||
|
// TODO: Retrieve previous lead proof
|
||||||
// Generating epoch coins
|
let eta = pallas::Base::one();
|
||||||
// TODO: Retrieve previous lead proof
|
let epoch_coins = coins::create_epoch_coins(eta, &owned, epoch, 0);
|
||||||
let eta = pallas::Base::one();
|
info!("Generated epoch_coins: {}", epoch_coins.len());
|
||||||
let epoch_coins = coins::create_epoch_coins(eta, &owned, epoch, slot);
|
for slot in 0..10 {
|
||||||
info!("Generated epoch_coins: {}", epoch_coins.len());
|
// Checking if slot leader
|
||||||
for slot in 0..10 {
|
info!("Slot {} started!", slot);
|
||||||
// Checking if slot leader
|
let (won, idx) = coins::is_leader(slot, &epoch_coins);
|
||||||
info!("Slot {} started!", slot);
|
info!("Lottery outcome: {}", won);
|
||||||
let (won, idx) = coins::is_leader(slot, &epoch_coins);
|
if !won {
|
||||||
info!("Lottery outcome: {}", won);
|
continue
|
||||||
if !won {
|
}
|
||||||
continue
|
// TODO: Generate rewards transaction
|
||||||
|
info!("Winning coin index: {}", idx);
|
||||||
|
// Generating leader proof
|
||||||
|
let coin = epoch_coins[slot as usize][idx];
|
||||||
|
let proof = lead_proof::create_lead_proof(&proving_key, coin);
|
||||||
|
if proof.is_err() {
|
||||||
|
error!("Error during leader proof creation: {}", proof.err().unwrap());
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
//Verifying generated proof against winning coin public inputs
|
||||||
|
info!("Leader proof generated successfully, veryfing...");
|
||||||
|
match lead_proof::verify_lead_proof(&verifying_key, &proof.unwrap(), &coin.public_inputs()) {
|
||||||
|
Ok(_) => info!("Proof veryfied succsessfully!"),
|
||||||
|
Err(e) => error!("Error during leader proof verification: {}", e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// TODO: Generate rewards transaction
|
|
||||||
info!("Winning coin index: {}", idx);
|
|
||||||
// Generating leader proof
|
|
||||||
let coin = epoch_coins[slot as usize][idx];
|
|
||||||
let proof = lead_proof::create_lead_proof(&proving_key, coin);
|
|
||||||
if proof.is_err() {
|
|
||||||
error!("Error during leader proof creation: {}", proof.err().unwrap());
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
//Verifying generated proof against winning coin public inputs
|
|
||||||
info!("Leader proof generated successfully, veryfing...");
|
|
||||||
match lead_proof::verify_lead_proof(&verifying_key, &proof.unwrap(), &coin.public_inputs()) {
|
|
||||||
Ok(_) => info!("Proof veryfied succsessfully!"),
|
|
||||||
Err(e) => error!("Error during leader proof verification: {}", e),
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user