mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
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:
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user