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.
This commit is contained in:
aggstam
2023-02-06 18:47:37 +02:00
parent 6486cff4c7
commit 92e2457f2c
4 changed files with 31 additions and 0 deletions

View File

@@ -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,

View File

@@ -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.

View File

@@ -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(())
}

View File

@@ -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,
}));