consensus/task/proposal.rs: leader broadcasting finalized blocks added

This commit is contained in:
aggstam
2022-04-28 15:21:59 +03:00
parent 341635f12b
commit e03904f435
4 changed files with 28 additions and 6 deletions

View File

@@ -410,7 +410,7 @@ async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
.detach();
info!("Starting consensus protocol task");
ex.spawn(proposal_task(consensus_p2p.unwrap(), state)).detach();
ex.spawn(proposal_task(consensus_p2p.unwrap(), sync_p2p.unwrap(), state)).detach();
} else {
info!("Not starting consensus P2P network");
}

View File

@@ -1,4 +1,4 @@
use log::warn;
use log::debug;
use sled::Batch;
use crate::{
@@ -130,7 +130,7 @@ impl BlockOrderStore {
ret.push(Some(hash));
} else {
if strict {
warn!("BlockOrderStore::get() Slot {} not found", i);
debug!("BlockOrderStore::get() Slot {} not found", i);
return Err(Error::SlotNotFound(*i))
}
ret.push(None);

View File

@@ -78,7 +78,7 @@ impl ProtocolSync {
debug!("ProtocolSync::handle_receive_block() received block");
// Node stores finalized flock, if it doesn't exist (checking by slot),
// Node stores finalized block, if it doesn't exist (checking by slot),
// and removes its transactions from the unconfirmed_txs vector.
// Consensus-mode enabled nodes have already performed these steps,
// during proposal finalization.

View File

@@ -10,7 +10,7 @@ use crate::{
};
/// async task used for participating in the consensus protocol
pub async fn proposal_task(p2p: net::P2pPtr, state: ValidatorStatePtr) {
pub async fn proposal_task(p2p: net::P2pPtr, sync_p2p: net::P2pPtr, state: ValidatorStatePtr) {
// Node waits just before the current or next epoch end,
// so it can start syncing latest state.
let mut seconds_until_next_epoch = state.read().await.next_epoch_start();
@@ -89,7 +89,29 @@ pub async fn proposal_task(p2p: net::P2pPtr, state: ValidatorStatePtr) {
let vote = v.unwrap();
let result = state.write().await.receive_vote(&vote);
match result {
Ok(_) => info!(target: "consensus", "Vote saved successfully."),
Ok((_, to_broadcast)) => {
info!(target: "consensus", "Vote saved successfully.");
// Broadcast finalized blocks info, if any
match to_broadcast {
Some(blocks) => {
debug!("handle_receive_vote(): Broadcasting finalized blocks");
for info in blocks {
let result = sync_p2p.broadcast(info).await;
match result {
Ok(()) => {
info!(target: "consensus", "Finalized block broadcasted successfully.")
}
Err(e) => {
error!(target: "consensus", "Failed broadcasting finalized block: {}", e)
}
}
}
}
None => {
debug!("handle_receive_vote(): No finalized blocks to broadcast");
}
}
}
Err(e) => {
error!(target: "consensus", "Vote save failed: {}", e)
}