diff --git a/src/consensus/proto/protocol_sync.rs b/src/consensus/proto/protocol_sync.rs index 0a0d33877..328173aa1 100644 --- a/src/consensus/proto/protocol_sync.rs +++ b/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, diff --git a/src/consensus/proto/protocol_tx.rs b/src/consensus/proto/protocol_tx.rs index f895ecb6f..4821a6480 100644 --- a/src/consensus/proto/protocol_tx.rs +++ b/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. diff --git a/src/consensus/task/block_sync.rs b/src/consensus/task/block_sync.rs index d3c29a28e..a51bcf801 100644 --- a/src/consensus/task/block_sync.rs +++ b/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(()) } diff --git a/src/consensus/validator.rs b/src/consensus/validator.rs index 922aeb598..056930f6b 100644 --- a/src/consensus/validator.rs +++ b/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, }));