Просмотр исходного кода

darkfid, faucetd: optional clock sync(config/args based)

aggstam 4 лет назад
Родитель
Сommit
ca660f5fe0

+ 3 - 0
bin/darkfid/darkfid_config.toml

@@ -59,3 +59,6 @@
 
 
 # Whitelisted faucet addresses
 # Whitelisted faucet addresses
 #faucet_pub = []
 #faucet_pub = []
+
+# Verify system clock is correct
+#clock_sync = true

+ 11 - 5
bin/darkfid/src/main.rs

@@ -129,6 +129,10 @@ struct Args {
     /// Whitelisted faucet address (repeatable flag)
     /// Whitelisted faucet address (repeatable flag)
     faucet_pub: Vec<String>,
     faucet_pub: Vec<String>,
 
 
+    #[structopt(long)]
+    /// Verify system clock is correct
+    clock_sync: bool,
+
     #[structopt(short, parse(from_occurrences))]
     #[structopt(short, parse(from_occurrences))]
     /// Increase verbosity (-vvv supported)
     /// Increase verbosity (-vvv supported)
     verbose: u8,
     verbose: u8,
@@ -197,11 +201,13 @@ impl Darkfid {
 
 
 async_daemonize!(realmain);
 async_daemonize!(realmain);
 async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
 async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> 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
     // We use this handler to block this function after detaching all
     // tasks, and to catch a shutdown signal, where we can clean up and
     // tasks, and to catch a shutdown signal, where we can clean up and

+ 3 - 0
bin/faucetd/faucetd_config.toml

@@ -41,3 +41,6 @@
 
 
 # Airdrop amount limit
 # Airdrop amount limit
 #airdrop_limit = "10"
 #airdrop_limit = "10"
+
+# Verify system clock is correct
+#clock_sync = true

+ 15 - 1
bin/faucetd/src/main.rs

@@ -37,7 +37,9 @@ use darkfi::{
         decode_base10, expand_path,
         decode_base10, expand_path,
         path::get_config_path,
         path::get_config_path,
         serial::serialize,
         serial::serialize,
-        sleep, NetworkName,
+        sleep,
+        time::check_clock,
+        NetworkName,
     },
     },
     wallet::walletdb::init_wallet,
     wallet::walletdb::init_wallet,
     Error, Result,
     Error, Result,
@@ -113,6 +115,10 @@ struct Args {
     /// Airdrop amount limit
     /// Airdrop amount limit
     airdrop_limit: String, // We convert this to biguint with decode_base10
     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))]
     #[structopt(short, parse(from_occurrences))]
     /// Increase verbosity (-vvv supported)
     /// Increase verbosity (-vvv supported)
     verbose: u8,
     verbose: u8,
@@ -295,6 +301,14 @@ async fn prune_airdrop_map(map: Arc<Mutex<HashMap<Address, i64>>>, timeout: i64)
 
 
 async_daemonize!(realmain);
 async_daemonize!(realmain);
 async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
 async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> 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
     // We use this handler to block this function after detaching all
     // tasks, and to catch a shutdown signal, where we can clean up and
     // tasks, and to catch a shutdown signal, where we can clean up and
     // exit gracefully.
     // exit gracefully.

+ 3 - 0
contrib/localnet/darkfid0.toml

@@ -56,3 +56,6 @@ sync_p2p_external = "tls://127.0.0.1:8342"
 
 
 # Whitelisted faucet public key
 # Whitelisted faucet public key
 faucet_pub = ["1z3JuN456MieHtpoF4cr5a1ntFF87L8Z3m2E5ACppFodFcjnLS"]
 faucet_pub = ["1z3JuN456MieHtpoF4cr5a1ntFF87L8Z3m2E5ACppFodFcjnLS"]
+
+# Verify system clock is correct
+#clock_sync = true

+ 3 - 0
contrib/localnet/darkfid1.toml

@@ -56,3 +56,6 @@ sync_p2p_seed = ["tls://127.0.0.1:8342"]
 
 
 # Whitelisted faucet public key
 # Whitelisted faucet public key
 faucet_pub = ["1z3JuN456MieHtpoF4cr5a1ntFF87L8Z3m2E5ACppFodFcjnLS"]
 faucet_pub = ["1z3JuN456MieHtpoF4cr5a1ntFF87L8Z3m2E5ACppFodFcjnLS"]
+
+# Verify system clock is correct
+#clock_sync = true

+ 3 - 0
contrib/localnet/darkfid2.toml

@@ -56,3 +56,6 @@ sync_p2p_seed = ["tls://127.0.0.1:8342"]
 
 
 # Whitelisted faucet public key
 # Whitelisted faucet public key
 faucet_pub = ["1z3JuN456MieHtpoF4cr5a1ntFF87L8Z3m2E5ACppFodFcjnLS"]
 faucet_pub = ["1z3JuN456MieHtpoF4cr5a1ntFF87L8Z3m2E5ACppFodFcjnLS"]
+
+# Verify system clock is correct
+#clock_sync = true

+ 3 - 0
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
 # Peers to connect to for the syncing protocol
 #sync_p2p_peer = []
 #sync_p2p_peer = []
+
+# Verify system clock is correct
+#clock_sync = true

+ 6 - 3
script/consensus_simulation.sh

@@ -20,7 +20,8 @@ LOG_TARGETS="!sled,!net" ./darkfid \
     --rpc-listen tcp://127.0.0.1:6010 \
     --rpc-listen tcp://127.0.0.1:6010 \
     --sync-p2p-accept tcp://127.0.0.1:6020 \
     --sync-p2p-accept tcp://127.0.0.1:6020 \
     --sync-p2p-external 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[@]}]=$!
 pids[${#pids[@]}]=$!
 
 
@@ -42,7 +43,8 @@ do
     --rpc-listen tcp://127.0.0.1:601$i \
     --rpc-listen tcp://127.0.0.1:601$i \
     --sync-p2p-accept tcp://127.0.0.1:602$i \
     --sync-p2p-accept tcp://127.0.0.1:602$i \
     --sync-p2p-external 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[@]}]=$!
   pids[${#pids[@]}]=$!
   # waiting for node to setup
   # waiting for node to setup
   sleep 20
   sleep 20
@@ -72,4 +74,5 @@ LOG_TARGETS="!sled,!net" ./darkfid \
     --rpc-listen tcp://127.0.0.1:601$bound \
     --rpc-listen tcp://127.0.0.1:601$bound \
     --sync-p2p-accept tcp://127.0.0.1:602$bound \
     --sync-p2p-accept tcp://127.0.0.1:602$bound \
     --sync-p2p-external 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