darkfid: purge current forks on network dc

This commit is contained in:
skoupidi
2024-06-25 16:00:38 +03:00
parent df95f854a7
commit 235ba3f644
3 changed files with 13 additions and 2 deletions

View File

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

View File

@@ -204,8 +204,8 @@ async fn synced_peers(
let _ = subscription.receive().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)

View File

@@ -492,6 +492,16 @@ impl Consensus {
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.