فهرست منبع

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

aggstam 4 سال پیش
والد
کامیت
e03904f435
4فایلهای تغییر یافته به همراه28 افزوده شده و 6 حذف شده
  1. 1 1
      bin/darkfid2/src/main.rs
  2. 2 2
      src/blockchain/blockstore.rs
  3. 1 1
      src/consensus/proto/protocol_sync.rs
  4. 24 2
      src/consensus/task/proposal.rs

+ 1 - 1
bin/darkfid2/src/main.rs

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

+ 2 - 2
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);

+ 1 - 1
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.

+ 24 - 2
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)
                                 }