Przeglądaj źródła

consensus: fixed initial sync

Since protocol to receive finalized slots/blocks was already attached, when a node was syncing if a finalization occured, the block was stored and the node was thinking that it was synced.
aggstam 3 lat temu
rodzic
commit
92e2457f2c

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

@@ -150,6 +150,15 @@ impl ProtocolSync {
                 }
             };
 
+            // Check if node has finished syncing its blockchain
+            if !self.state.read().await.synced {
+                debug!(
+                    target: "consensus::protocol_sync::handle_receive_block()",
+                    "Node still syncing blockchain, skipping..."
+                );
+                continue
+            }
+
             // Check if node started participating in consensus.
             // Consensus-mode enabled nodes have already performed these steps,
             // during proposal finalization. They still listen to this sub,
@@ -289,6 +298,15 @@ impl ProtocolSync {
                 }
             };
 
+            // Check if node has finished syncing its blockchain
+            if !self.state.read().await.synced {
+                debug!(
+                    target: "consensus::protocol_sync::handle_receive_slot_checkpoint()",
+                    "Node still syncing blockchain, skipping..."
+                );
+                continue
+            }
+
             // Check if node started participating in consensus.
             // Consensus-mode enabled nodes have already performed these steps,
             // during proposal finalization. They still listen to this sub,

+ 9 - 0
src/consensus/proto/protocol_tx.rs

@@ -91,6 +91,15 @@ impl ProtocolTx {
                 }
             };
 
+            // Check if node has finished syncing its blockchain
+            if !self.state.read().await.synced {
+                debug!(
+                    target: "consensus::protocol_tx::handle_receive_tx()",
+                    "Node still syncing blockchain, skipping..."
+                );
+                continue
+            }
+
             let tx_copy = (*tx).clone();
 
             // Nodes use unconfirmed_txs vector as seen_txs pool.

+ 1 - 0
src/consensus/task/block_sync.rs

@@ -118,6 +118,7 @@ pub async fn block_sync_task(p2p: net::P2pPtr, state: ValidatorStatePtr) -> Resu
         None => warn!(target: "consensus::block_sync", "Node is not connected to other nodes"),
     };
 
+    state.write().await.synced = true;
     info!(target: "consensus::block_sync", "Blockchain synced!");
     Ok(())
 }

+ 3 - 0
src/consensus/validator.rs

@@ -86,6 +86,8 @@ pub struct ValidatorState {
     pub verifying_keys: VerifyingKeyMap,
     /// Wallet interface
     pub wallet: WalletPtr,
+    /// Flag signalling node has finished initial sync
+    pub synced: bool,
     /// Flag to enable single-node mode
     pub single_node: bool,
 }
@@ -227,6 +229,7 @@ impl ValidatorState {
             subscribers,
             verifying_keys: Arc::new(RwLock::new(verifying_keys)),
             wallet,
+            synced: false,
             single_node,
         }));