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

darkfid: purge current forks on network dc

skoupidi 2 лет назад
Родитель
Сommit
235ba3f644
3 измененных файлов с 13 добавлено и 2 удалено
  1. 1 0
      bin/darkfid/src/task/consensus.rs
  2. 2 2
      bin/darkfid/src/task/sync.rs
  3. 10 0
      src/validator/consensus.rs

+ 1 - 0
bin/darkfid/src/task/consensus.rs

@@ -147,6 +147,7 @@ pub async fn consensus_init_task(
             Err(Error::NetworkNotConnected) => {
             Err(Error::NetworkNotConnected) => {
                 // Sync node again
                 // Sync node again
                 *node.validator.synced.write().await = false;
                 *node.validator.synced.write().await = false;
+                node.validator.consensus.purge_forks().await?;
                 if !config.skip_sync {
                 if !config.skip_sync {
                     sync_task(&node, checkpoint).await?;
                     sync_task(&node, checkpoint).await?;
                 } else {
                 } else {

+ 2 - 2
bin/darkfid/src/task/sync.rs

@@ -204,8 +204,8 @@ async fn synced_peers(
         let _ = subscription.receive().await;
         let _ = subscription.receive().await;
         subscription.unsubscribe().await;
         subscription.unsubscribe().await;
 
 
-        info!(target: "darkfid::task::sync::synced_peers", "Sleeping a bit to allow for more nodes to connect...");
-        sleep(node.p2p.settings().outbound_connect_timeout).await;
+        info!(target: "darkfid::task::sync::synced_peers", "Sleeping for {comms_timeout} to allow for more nodes to connect...");
+        sleep(comms_timeout).await;
     }
     }
 
 
     Ok(tips)
     Ok(tips)

+ 10 - 0
src/validator/consensus.rs

@@ -492,6 +492,16 @@ impl Consensus {
 
 
         Ok(())
         Ok(())
     }
     }
+
+    /// Auxiliary function to fully purge current forks and leave only a new empty fork.
+    pub async fn purge_forks(&self) -> Result<()> {
+        debug!(target: "validator::consensus::purge_forks", "Purging current forks...");
+        let mut forks = self.forks.write().await;
+        *forks = vec![Fork::new(self.blockchain.clone(), self.module.read().await.clone()).await?];
+        drop(forks);
+        debug!(target: "validator::consensus::purge_forks", "Forks purged!");
+        Ok(())
+    }
 }
 }
 
 
 /// This struct represents a block proposal, used for consensus.
 /// This struct represents a block proposal, used for consensus.