Quellcode durchsuchen

tau: DAG sync loops forever instead of exiting with an error after {sync_attempts} times

dasman vor 1 Jahr
Ursprung
Commit
78910e2780
3 geänderte Dateien mit 19 neuen und 36 gelöschten Zeilen
  1. 19 22
      bin/tau/taud/src/main.rs
  2. 0 8
      bin/tau/taud/src/settings.rs
  3. 0 6
      bin/tau/taud/taud_config.toml

+ 19 - 22
bin/tau/taud/src/main.rs

@@ -545,34 +545,31 @@ async fn realmain(settings: Args, executor: Arc<smol::Executor<'static>>) -> Res
     info!(target: "taud", "Starting P2P network");
     p2p.clone().start().await?;
 
-    info!(target: "taud", "Waiting for some P2P connections...");
-    sleep(5).await;
-
-    // We'll attempt to sync {sync_attempts} times
-    if !settings.skip_dag_sync {
-        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 == settings.sync_attempts {
-                        error!(target: "taud", "Failed syncing DAG. Exiting.");
-                        p2p.stop().await;
-                        return Err(Error::DagSyncFailed)
-                    } else {
+    let comms_timeout = p2p.settings().read().await.outbound_connect_timeout;
+
+    loop {
+        if p2p.is_connected() {
+            info!(target: "taud", "Got peer connection");
+            // We'll attempt to sync for ever
+            if !settings.skip_dag_sync {
+                info!(target: "taud", "Syncing event DAG");
+                match event_graph.dag_sync().await {
+                    Ok(()) => break,
+                    Err(e) => {
                         // TODO: Maybe at this point we should prune or something?
                         // TODO: Or maybe just tell the user to delete the DAG from FS.
-                        error!(
-                            "Failed syncing DAG ({}), retrying in {}s...",
-                            e, settings.sync_timeout
-                        );
-                        sleep(settings.sync_timeout.into()).await;
+                        error!(target: "taud", "Failed syncing DAG ({}), retrying in {}s...", e, comms_timeout);
+                        sleep(comms_timeout).await;
                     }
                 }
+            } else {
+                *event_graph.synced.write().await = true;
+                break
             }
+        } else {
+            info!(target: "taud", "Waiting for some P2P connections...");
+            sleep(comms_timeout).await;
         }
-    } else {
-        *event_graph.synced.write().await = true;
     }
 
     let seen = OnceLock::new();

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

@@ -50,14 +50,6 @@ 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,
 

+ 0 - 6
bin/tau/taud/taud_config.toml

@@ -20,12 +20,6 @@
 ## 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"