diff --git a/bin/darkfid2/src/main.rs b/bin/darkfid2/src/main.rs index 91cc19b14..2b871f24c 100644 --- a/bin/darkfid2/src/main.rs +++ b/bin/darkfid2/src/main.rs @@ -410,7 +410,7 @@ async fn realmain(args: Args, ex: Arc>) -> 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"); } diff --git a/src/blockchain/blockstore.rs b/src/blockchain/blockstore.rs index e3bba4609..2f473568b 100644 --- a/src/blockchain/blockstore.rs +++ b/src/blockchain/blockstore.rs @@ -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); diff --git a/src/consensus/proto/protocol_sync.rs b/src/consensus/proto/protocol_sync.rs index 681410760..e45b09334 100644 --- a/src/consensus/proto/protocol_sync.rs +++ b/src/consensus/proto/protocol_sync.rs @@ -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. diff --git a/src/consensus/task/proposal.rs b/src/consensus/task/proposal.rs index 963fa3969..0da1e7a79 100644 --- a/src/consensus/task/proposal.rs +++ b/src/consensus/task/proposal.rs @@ -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) }