Browse Source

consensus: consensus nodes stop listenning for finalized blocks/slots after started participating

aggstam 3 years ago
parent
commit
941f52ad9d
1 changed files with 20 additions and 18 deletions
  1. 20 18
      src/consensus/proto/protocol_sync.rs

+ 20 - 18
src/consensus/proto/protocol_sync.rs

@@ -112,15 +112,6 @@ impl ProtocolSync {
     }
     }
 
 
     async fn handle_receive_block(self: Arc<Self>) -> Result<()> {
     async fn handle_receive_block(self: Arc<Self>) -> Result<()> {
-        // Consensus-mode enabled nodes have already performed these steps,
-        // during proposal finalization.
-        if self.consensus_mode && self.state.read().await.consensus.participating.is_some() {
-            debug!(
-                "ProtocolSync::handle_receive_block(): node runs in consensus mode, skipping..."
-            );
-            return Ok(())
-        }
-
         debug!("ProtocolSync::handle_receive_block() [START]");
         debug!("ProtocolSync::handle_receive_block() [START]");
         let exclude_list = vec![self.channel.address()];
         let exclude_list = vec![self.channel.address()];
         loop {
         loop {
@@ -132,6 +123,16 @@ impl ProtocolSync {
                 }
                 }
             };
             };
 
 
+            // Check if node started participating in consensus.
+            // Consensus-mode enabled nodes have already performed these steps,
+            // during proposal finalization.
+            if self.consensus_mode && self.state.read().await.consensus.participating.is_some() {
+                debug!(
+                    "ProtocolSync::handle_receive_block(): node runs in consensus mode, skipping..."
+                );
+                return Ok(())
+            }
+
             info!("ProtocolSync::handle_receive_block(): Received block: {}", info.blockhash());
             info!("ProtocolSync::handle_receive_block(): Received block: {}", info.blockhash());
 
 
             debug!("ProtocolSync::handle_receive_block(): Processing received block");
             debug!("ProtocolSync::handle_receive_block(): Processing received block");
@@ -204,15 +205,6 @@ impl ProtocolSync {
     }
     }
 
 
     async fn handle_receive_slot_checkpoint(self: Arc<Self>) -> Result<()> {
     async fn handle_receive_slot_checkpoint(self: Arc<Self>) -> Result<()> {
-        // Consensus-mode enabled nodes have already performed these steps,
-        // during proposal finalization.
-        if self.consensus_mode && self.state.read().await.consensus.participating.is_some() {
-            debug!(
-                "ProtocolSync::handle_receive_slot_checkpoint(): node runs in consensus mode, skipping..."
-            );
-            return Ok(())
-        }
-
         debug!("ProtocolSync::handle_receive_slot_checkpoint() [START]");
         debug!("ProtocolSync::handle_receive_slot_checkpoint() [START]");
         let exclude_list = vec![self.channel.address()];
         let exclude_list = vec![self.channel.address()];
         loop {
         loop {
@@ -224,6 +216,16 @@ impl ProtocolSync {
                 }
                 }
             };
             };
 
 
+            // Check if node started participating in consensus.
+            // Consensus-mode enabled nodes have already performed these steps,
+            // during proposal finalization.
+            if self.consensus_mode && self.state.read().await.consensus.participating.is_some() {
+                debug!(
+                    "ProtocolSync::handle_receive_slot_checkpoint(): node runs in consensus mode, skipping..."
+                );
+                return Ok(())
+            }
+
             info!(
             info!(
                 "ProtocolSync::handle_receive_slot_checkpoint(): Received slot checkpoint: {}",
                 "ProtocolSync::handle_receive_slot_checkpoint(): Received slot checkpoint: {}",
                 slot_checkpoint.slot
                 slot_checkpoint.slot