Quellcode durchsuchen

consensus:proposal_task(): sync duration added to reset retries counter

aggstam vor 3 Jahren
Ursprung
Commit
40313cd6f5
2 geänderte Dateien mit 12 neuen und 0 gelöschten Zeilen
  1. 3 0
      src/consensus/constants.rs
  2. 9 0
      src/consensus/task/proposal.rs

+ 3 - 0
src/consensus/constants.rs

@@ -76,6 +76,9 @@ pub const SLOT_TIME: u64 = 90;
 /// Finalization sync period duration (should be >=2/3 of slot time)
 pub const FINAL_SYNC_DUR: u64 = 60;
 
+/// Max resync retries duration in epochs
+pub const SYNC_RETRIES_DURATION: u64 = 2;
+
 /// Max resync retries
 pub const SYNC_MAX_RETRIES: u64 = 10;
 

+ 9 - 0
src/consensus/task/proposal.rs

@@ -224,9 +224,18 @@ pub async fn proposal_task2(
             Err(e) => error!("consensus: Failed to set participation slot: {}", e),
         }
 
+        // Record epoch we start the consensus loop
+        let start_epoch = state.read().await.consensus.current_epoch();
+
         // Start executing consensus
         consensus_loop(consensus_p2p.clone(), sync_p2p.clone(), state.clone(), ex.clone()).await;
 
+        // Reset retries counter if more epochs have passed than sync retries duration
+        let break_epoch = state.read().await.consensus.current_epoch();
+        if (break_epoch - start_epoch) > constants::SYNC_RETRIES_DURATION {
+            retries = 0;
+        }
+
         // Increase retries count on consensus loop break
         retries += 1;
     }