|
|
@@ -1,30 +1,70 @@
|
|
|
+use async_std::sync::Arc;
|
|
|
use log::{error, info};
|
|
|
-use simplelog::{ColorChoice, Config, LevelFilter, TermLogger, TerminalMode};
|
|
|
+use pasta_curves::pallas;
|
|
|
+use structopt_toml::{serde::Deserialize, structopt::StructOpt, StructOptToml};
|
|
|
|
|
|
use darkfi::{
|
|
|
+ async_daemonize, cli_desc,
|
|
|
crypto::{
|
|
|
lead_proof,
|
|
|
proof::{ProvingKey, VerifyingKey},
|
|
|
},
|
|
|
+ node::Client,
|
|
|
+ wallet::walletdb::init_wallet,
|
|
|
zk::circuit::LeadContract,
|
|
|
+ Result,
|
|
|
};
|
|
|
|
|
|
mod coins;
|
|
|
mod utils;
|
|
|
|
|
|
-/// The porpuse of this script is to simulate a staker actions through an epoch.
|
|
|
-/// Main focus is the crypsinous lottery mechanism and the leader proof creation and validation.
|
|
|
-/// Other flows that happen through a slot, like broadcasting blocks or syncing are out of scope.
|
|
|
-fn main() {
|
|
|
- // Initiate logger
|
|
|
- TermLogger::init(
|
|
|
- LevelFilter::Debug,
|
|
|
- Config::default(),
|
|
|
- TerminalMode::Mixed,
|
|
|
- ColorChoice::Auto,
|
|
|
- )
|
|
|
- .unwrap();
|
|
|
+const CONFIG_FILE: &str = "crypsinous_playground_config.toml";
|
|
|
+const CONFIG_FILE_CONTENTS: &str = include_str!("../crypsinous_playground_config.toml");
|
|
|
+
|
|
|
+#[derive(Clone, Debug, Deserialize, StructOpt, StructOptToml)]
|
|
|
+#[serde(default)]
|
|
|
+#[structopt(name = "crypsinous_playground", about = cli_desc!())]
|
|
|
+struct Args {
|
|
|
+ #[structopt(short, long)]
|
|
|
+ /// Configuration file to use
|
|
|
+ config: Option<String>,
|
|
|
+
|
|
|
+ #[structopt(long, default_value = "~/.config/darkfi/crypsinous_playground/wallet.db")]
|
|
|
+ /// Path to wallet database
|
|
|
+ wallet_path: String,
|
|
|
+
|
|
|
+ #[structopt(long, default_value = "changeme")]
|
|
|
+ /// Password for the wallet database
|
|
|
+ wallet_pass: String,
|
|
|
+
|
|
|
+ #[structopt(short, parse(from_occurrences))]
|
|
|
+ /// Increase verbosity (-vvv supported)
|
|
|
+ verbose: u8,
|
|
|
+}
|
|
|
+
|
|
|
+// The porpuse of this script is to simulate a staker actions through an epoch.
|
|
|
+// Main focus is the crypsinous lottery mechanism and the leader proof creation and validation.
|
|
|
+// Other flows that happen through a slot, like broadcasting blocks or syncing are out of scope.
|
|
|
+async_daemonize!(realmain);
|
|
|
+async fn realmain(args: Args, _ex: Arc<smol::Executor<'_>>) -> Result<()> {
|
|
|
+
|
|
|
+ // Initialize wallet that holds coins for staking
|
|
|
+ let wallet = init_wallet(&args.wallet_path, &args.wallet_pass).await?;
|
|
|
+
|
|
|
+ // Initialize client
|
|
|
+ let client = Arc::new(Client::new(wallet.clone()).await?);
|
|
|
|
|
|
+ // Retrieving nodes wallet coins
|
|
|
+ let mut owned = client.get_own_coins().await?;
|
|
|
+ // If node holds no coins in its wallet, we generate some new staking coins
|
|
|
+ if owned.is_empty() {
|
|
|
+ info!("Node wallet is empty, generating new staking coins...");
|
|
|
+ owned = coins::generate_staking_coins(&wallet).await?;
|
|
|
+ }
|
|
|
+ // If we want to test what will happen if node holds 0 coins, uncomment the below line
|
|
|
+ // owned = vec![];
|
|
|
+ info!("Node coins: {:?}", owned);
|
|
|
+
|
|
|
// Generating leader proof keys
|
|
|
let k: u32 = 13; // Proof rows number
|
|
|
info!("Generating proof keys with k: {}", k);
|
|
|
@@ -37,10 +77,8 @@ fn main() {
|
|
|
info!("Epoch {} started!", epoch);
|
|
|
|
|
|
// Generating epoch coins
|
|
|
- // TODO: Retrieve own coins
|
|
|
- let owned = vec![];
|
|
|
// TODO: Retrieve previous lead proof
|
|
|
- let eta = utils::get_eta(blake3::hash(b"Erebus"));
|
|
|
+ let eta = pallas::Base::one();
|
|
|
let epoch_coins = coins::create_epoch_coins(eta, &owned, epoch, slot);
|
|
|
info!("Generated epoch_coins: {}", epoch_coins.len());
|
|
|
for slot in 0..10 {
|
|
|
@@ -67,5 +105,7 @@ fn main() {
|
|
|
Err(e) => error!("Error during leader proof verification: {}", e),
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ Ok(())
|
|
|
}
|