From 23e49ffb6701ba1db8eb2560ea075cf54a098db1 Mon Sep 17 00:00:00 2001 From: parazyd Date: Tue, 26 Apr 2022 17:35:24 +0200 Subject: [PATCH] darkfid: Fix compilation. --- bin/darkfid2/src/main.rs | 45 ++++++++++------------------------------ src/consensus/state.rs | 4 ++-- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/bin/darkfid2/src/main.rs b/bin/darkfid2/src/main.rs index 8587c8aa3..12d9c800b 100644 --- a/bin/darkfid2/src/main.rs +++ b/bin/darkfid2/src/main.rs @@ -5,7 +5,6 @@ use async_std::sync::{Arc, Mutex}; use async_trait::async_trait; use easy_parallel::Parallel; use futures_lite::future; -use lazy_init::Lazy; use log::{error, info}; use serde_derive::Deserialize; use simplelog::{ColorChoice, TermLogger, TerminalMode}; @@ -14,9 +13,7 @@ use structopt_toml::StructOptToml; use url::Url; use darkfi::{ - async_daemonize, - blockchain::{NullifierStore, RootStore}, - cli_desc, + async_daemonize, cli_desc, consensus::{ proto::{ ProtocolParticipant, ProtocolProposal, ProtocolSync, ProtocolSyncConsensus, ProtocolTx, @@ -30,7 +27,7 @@ use darkfi::{ crypto::token_list::{DrkTokenList, TokenList}, net, net::P2pPtr, - node::{Client, State}, + node::Client, rpc::{ jsonrpc, jsonrpc::{ @@ -44,7 +41,7 @@ use darkfi::{ expand_path, path::get_config_path, }, - wallet::walletdb::{init_wallet, WalletPtr}, + wallet::walletdb::init_wallet, Error, Result, }; @@ -137,11 +134,10 @@ struct Args { pub struct Darkfid { synced: Mutex, // AtomicBool is weird in Arc - client: Client, consensus_p2p: Option, sync_p2p: Option, + client: Arc, validator_state: ValidatorStatePtr, - state: Arc>, drk_tokenlist: DrkTokenList, btc_tokenlist: TokenList, eth_tokenlist: TokenList, @@ -180,8 +176,6 @@ impl RequestHandler for Darkfid { impl Darkfid { pub async fn new( - db: &sled::Db, - wallet: WalletPtr, validator_state: ValidatorStatePtr, consensus_p2p: Option, sync_p2p: Option, @@ -195,30 +189,14 @@ impl Darkfid { TokenList::new(include_bytes!("../../../contrib/token/solana_token_list.min.json"))?; let drk_tokenlist = DrkTokenList::new(&sol_tokenlist, ð_tokenlist, &btc_tokenlist)?; - // Initialize Client - let client = Client::new(wallet).await?; - let tree = client.get_tree().await?; - let merkle_roots = RootStore::new(db)?; - let nullifiers = NullifierStore::new(db)?; - - // Initialize State - let state = Arc::new(Mutex::new(State { - tree, - merkle_roots, - nullifiers, - cashier_pubkeys: vec![], - faucet_pubkeys: vec![], - mint_vk: Lazy::new(), - burn_vk: Lazy::new(), - })); + let client = validator_state.read().await.client.clone(); Ok(Self { synced: Mutex::new(false), - client, consensus_p2p, sync_p2p, + client, validator_state, - state, drk_tokenlist, btc_tokenlist, eth_tokenlist, @@ -258,11 +236,12 @@ async fn realmain(args: Args, ex: Arc>) -> Result<()> { }; // TODO: sqldb init cleanup - Client::new(wallet.clone()).await?; - let address = wallet.get_default_address().await?; + // Initialize Client + let client = Arc::new(Client::new(wallet).await?); // Initialize validator state - let state = ValidatorState::new(&sled_db, address, genesis_ts, genesis_data)?; + let state = + ValidatorState::new(&sled_db, genesis_ts, genesis_data, client, vec![], vec![]).await?; let sync_p2p = { info!("Registering block sync P2P protocols..."); @@ -357,9 +336,7 @@ async fn realmain(args: Args, ex: Arc>) -> Result<()> { }; // Initialize program state - let darkfid = - Darkfid::new(&sled_db, wallet, state.clone(), consensus_p2p.clone(), sync_p2p.clone()) - .await?; + let darkfid = Darkfid::new(state.clone(), consensus_p2p.clone(), sync_p2p.clone()).await?; let darkfid = Arc::new(darkfid); // JSON-RPC server diff --git a/src/consensus/state.rs b/src/consensus/state.rs index a371d687f..a87a943eb 100644 --- a/src/consensus/state.rs +++ b/src/consensus/state.rs @@ -115,7 +115,7 @@ pub struct ValidatorState { /// Canonical state machine pub state_machine: Arc>, /// Client providing wallet access - pub client: Client, + pub client: Arc, /// Pending transactions pub unconfirmed_txs: Vec, /// Participation flag @@ -128,7 +128,7 @@ impl ValidatorState { db: &sled::Db, // <-- TODO: Avoid this with some wrapping, sled should only be in blockchain genesis_ts: Timestamp, genesis_data: blake3::Hash, - client: Client, + client: Arc, cashier_pubkeys: Vec, faucet_pubkeys: Vec, ) -> Result {