Jelajahi Sumber

tau: add configurable sync_attempts and sync_timeout

dasman 1 tahun lalu
induk
melakukan
03b9526224
3 mengubah file dengan 24 tambahan dan 7 penghapusan
  1. 8 5
      bin/tau/taud/src/main.rs
  2. 8 0
      bin/tau/taud/src/settings.rs
  3. 8 2
      bin/tau/taud/taud_config.toml

+ 8 - 5
bin/tau/taud/src/main.rs

@@ -527,22 +527,25 @@ async fn realmain(settings: Args, executor: Arc<smol::Executor<'static>>) -> Res
     info!(target: "taud", "Waiting for some P2P connections...");
     sleep(5).await;
 
-    // We'll attempt to sync 5 times
+    // We'll attempt to sync {sync_attempts} times
     if !settings.skip_dag_sync {
-        for i in 1..=6 {
+        for i in 1..=settings.sync_attempts {
             info!(target: "taud", "Syncing event DAG (attempt #{})", i);
             match event_graph.dag_sync().await {
                 Ok(()) => break,
                 Err(e) => {
-                    if i == 6 {
+                    if i == settings.sync_attempts {
                         error!(target: "taud", "Failed syncing DAG. Exiting.");
                         p2p.stop().await;
                         return Err(Error::DagSyncFailed)
                     } else {
                         // TODO: Maybe at this point we should prune or something?
                         // TODO: Or maybe just tell the user to delete the DAG from FS.
-                        error!(target: "taud", "Failed syncing DAG ({}), retrying in 10s...", e);
-                        sleep(10).await;
+                        error!(
+                            "Failed syncing DAG ({}), retrying in {}s...",
+                            e, settings.sync_timeout
+                        );
+                        sleep(settings.sync_timeout.into()).await;
                     }
                 }
             }

+ 8 - 0
bin/tau/taud/src/settings.rs

@@ -50,6 +50,14 @@ pub struct Args {
     #[structopt(long)]
     pub replay_mode: bool,
 
+    /// Number of attempts to sync the DAG.
+    #[structopt(long, default_value = "5")]
+    pub sync_attempts: u8,
+
+    /// Number of seconds to wait before trying again if sync fails.
+    #[structopt(long, default_value = "10")]
+    pub sync_timeout: u8,
+
     #[structopt(flatten)]
     pub net: SettingsOpt,
 

+ 8 - 2
bin/tau/taud/taud_config.toml

@@ -8,7 +8,7 @@
 #datastore = "~/.local/darkfi/taud_db"
 
 ## Sets DB logs replay datastore path
-#replay_datastore = "~/.local/darkfi/replayed_darkirc_db"
+#replay_datastore = "~/.local/darkfi/replayed_taud_db"
 
 ## Run in replay mode to store Sled DB instructions
 ## (for eventgraph debugging tool)
@@ -20,6 +20,12 @@
 ## Whether to pipe notifications or not
 #piped = false
 
+## Number of attempts to sync the DAG.
+#sync_attempts = 5
+
+## Number of seconds to wait before trying again if sync fails.
+#sync_timeout = 10
+
 ## Current display name
 #nickname = "NICKNAME"
 
@@ -36,7 +42,7 @@
 ## access, this, too, should not be shared with someone you don't 
 ## want to add/edit tasks.
 ## Use it like this example:
-#[workspace."#foo"]
+#[workspace."foo"]
 #read_key = "2bCqQTd8BJgeUzH7JQELZxjQuWS8aCmXZ9C6w7ktNS1v"
 #write_public_key = "Fgsc8tep4KX3Rb2drq8RxMyrHFWQ7wZaZPpF9F3GQYFG"
 #write_key = ""