From ca660f5fe0ed65d47b255759875bb226a69f56e9 Mon Sep 17 00:00:00 2001 From: aggstam Date: Thu, 2 Jun 2022 17:09:43 +0300 Subject: [PATCH] darkfid, faucetd: optional clock sync(config/args based) --- bin/darkfid/darkfid_config.toml | 3 +++ bin/darkfid/src/main.rs | 16 +++++++++++----- bin/faucetd/faucetd_config.toml | 3 +++ bin/faucetd/src/main.rs | 16 +++++++++++++++- contrib/localnet/darkfid0.toml | 3 +++ contrib/localnet/darkfid1.toml | 3 +++ contrib/localnet/darkfid2.toml | 3 +++ contrib/localnet/faucetd.toml | 3 +++ script/consensus_simulation.sh | 9 ++++++--- 9 files changed, 50 insertions(+), 9 deletions(-) diff --git a/bin/darkfid/darkfid_config.toml b/bin/darkfid/darkfid_config.toml index 43bff23b1..75206eacd 100644 --- a/bin/darkfid/darkfid_config.toml +++ b/bin/darkfid/darkfid_config.toml @@ -59,3 +59,6 @@ # Whitelisted faucet addresses #faucet_pub = [] + +# Verify system clock is correct +#clock_sync = true diff --git a/bin/darkfid/src/main.rs b/bin/darkfid/src/main.rs index da9bc78c6..e2b43aff2 100644 --- a/bin/darkfid/src/main.rs +++ b/bin/darkfid/src/main.rs @@ -129,6 +129,10 @@ struct Args { /// Whitelisted faucet address (repeatable flag) faucet_pub: Vec, + #[structopt(long)] + /// Verify system clock is correct + clock_sync: bool, + #[structopt(short, parse(from_occurrences))] /// Increase verbosity (-vvv supported) verbose: u8, @@ -197,11 +201,13 @@ impl Darkfid { async_daemonize!(realmain); async fn realmain(args: Args, ex: Arc>) -> Result<()> { - // We verify that the system clock is valid before initializing - if (check_clock().await).is_err() { - error!("System clock is invalid, terminating..."); - return Err(Error::InvalidClock) - }; + if args.clock_sync { + // We verify that the system clock is valid before initializing + if (check_clock().await).is_err() { + error!("System clock is invalid, terminating..."); + return Err(Error::InvalidClock) + }; + } // We use this handler to block this function after detaching all // tasks, and to catch a shutdown signal, where we can clean up and diff --git a/bin/faucetd/faucetd_config.toml b/bin/faucetd/faucetd_config.toml index b6c4090fe..2e6f9428e 100644 --- a/bin/faucetd/faucetd_config.toml +++ b/bin/faucetd/faucetd_config.toml @@ -41,3 +41,6 @@ # Airdrop amount limit #airdrop_limit = "10" + +# Verify system clock is correct +#clock_sync = true diff --git a/bin/faucetd/src/main.rs b/bin/faucetd/src/main.rs index 612e73658..e13764f25 100644 --- a/bin/faucetd/src/main.rs +++ b/bin/faucetd/src/main.rs @@ -37,7 +37,9 @@ use darkfi::{ decode_base10, expand_path, path::get_config_path, serial::serialize, - sleep, NetworkName, + sleep, + time::check_clock, + NetworkName, }, wallet::walletdb::init_wallet, Error, Result, @@ -113,6 +115,10 @@ struct Args { /// Airdrop amount limit airdrop_limit: String, // We convert this to biguint with decode_base10 + #[structopt(long)] + /// Verify system clock is correct + clock_sync: bool, + #[structopt(short, parse(from_occurrences))] /// Increase verbosity (-vvv supported) verbose: u8, @@ -295,6 +301,14 @@ async fn prune_airdrop_map(map: Arc>>, timeout: i64) async_daemonize!(realmain); async fn realmain(args: Args, ex: Arc>) -> Result<()> { + if args.clock_sync { + // We verify that the system clock is valid before initializing + if (check_clock().await).is_err() { + error!("System clock is invalid, terminating..."); + return Err(Error::InvalidClock) + }; + } + // We use this handler to block this function after detaching all // tasks, and to catch a shutdown signal, where we can clean up and // exit gracefully. diff --git a/contrib/localnet/darkfid0.toml b/contrib/localnet/darkfid0.toml index bd87efc51..225e50788 100644 --- a/contrib/localnet/darkfid0.toml +++ b/contrib/localnet/darkfid0.toml @@ -56,3 +56,6 @@ sync_p2p_external = "tls://127.0.0.1:8342" # Whitelisted faucet public key faucet_pub = ["1z3JuN456MieHtpoF4cr5a1ntFF87L8Z3m2E5ACppFodFcjnLS"] + +# Verify system clock is correct +#clock_sync = true diff --git a/contrib/localnet/darkfid1.toml b/contrib/localnet/darkfid1.toml index fc65f8d58..4b2f7a35f 100644 --- a/contrib/localnet/darkfid1.toml +++ b/contrib/localnet/darkfid1.toml @@ -56,3 +56,6 @@ sync_p2p_seed = ["tls://127.0.0.1:8342"] # Whitelisted faucet public key faucet_pub = ["1z3JuN456MieHtpoF4cr5a1ntFF87L8Z3m2E5ACppFodFcjnLS"] + +# Verify system clock is correct +#clock_sync = true diff --git a/contrib/localnet/darkfid2.toml b/contrib/localnet/darkfid2.toml index 40e9cdfbc..5560d2fdb 100644 --- a/contrib/localnet/darkfid2.toml +++ b/contrib/localnet/darkfid2.toml @@ -56,3 +56,6 @@ sync_p2p_seed = ["tls://127.0.0.1:8342"] # Whitelisted faucet public key faucet_pub = ["1z3JuN456MieHtpoF4cr5a1ntFF87L8Z3m2E5ACppFodFcjnLS"] + +# Verify system clock is correct +#clock_sync = true diff --git a/contrib/localnet/faucetd.toml b/contrib/localnet/faucetd.toml index 8c9df25cc..a7cffd4d8 100644 --- a/contrib/localnet/faucetd.toml +++ b/contrib/localnet/faucetd.toml @@ -35,3 +35,6 @@ sync_p2p_seed = ["tls://127.0.0.1:8342"] # Peers to connect to for the syncing protocol #sync_p2p_peer = [] + +# Verify system clock is correct +#clock_sync = true diff --git a/script/consensus_simulation.sh b/script/consensus_simulation.sh index 39568ecd3..555422dc1 100755 --- a/script/consensus_simulation.sh +++ b/script/consensus_simulation.sh @@ -20,7 +20,8 @@ LOG_TARGETS="!sled,!net" ./darkfid \ --rpc-listen tcp://127.0.0.1:6010 \ --sync-p2p-accept tcp://127.0.0.1:6020 \ --sync-p2p-external tcp://127.0.0.1:6020 \ - --wallet-path ./tmp/node0/wallet.db & + --wallet-path ./tmp/node0/wallet.db \ + --clock-sync & pids[${#pids[@]}]=$! @@ -42,7 +43,8 @@ do --rpc-listen tcp://127.0.0.1:601$i \ --sync-p2p-accept tcp://127.0.0.1:602$i \ --sync-p2p-external tcp://127.0.0.1:602$i \ - --wallet-path ./tmp/node$i/wallet.db & + --wallet-path ./tmp/node$i/wallet.db \ + --clock-sync & pids[${#pids[@]}]=$! # waiting for node to setup sleep 20 @@ -72,4 +74,5 @@ LOG_TARGETS="!sled,!net" ./darkfid \ --rpc-listen tcp://127.0.0.1:601$bound \ --sync-p2p-accept tcp://127.0.0.1:602$bound \ --sync-p2p-external tcp://127.0.0.1:602$bound \ - --wallet-path ./tmp/node$bound/wallet.db + --wallet-path ./tmp/node$bound/wallet.db \ + --clock-sync