parazyd 4 лет назад
Родитель
Сommit
09e8db29aa
3 измененных файлов с 18 добавлено и 15 удалено
  1. 1 1
      bin/faucetd/src/main.rs
  2. 5 1
      src/consensus2/proto/protocol_vote.rs
  3. 12 13
      src/consensus2/state.rs

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

@@ -327,7 +327,7 @@ async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
     registry
         .register(!net::SESSION_SEED, move |channel, p2p| {
             let state = _state.clone();
-            async move { ProtocolSync::init(channel, state, p2p).await.unwrap() }
+            async move { ProtocolSync::init(channel, state, p2p, false).await.unwrap() }
         })
         .await;
 

+ 5 - 1
src/consensus2/proto/protocol_vote.rs

@@ -57,11 +57,15 @@ impl ProtocolVote {
                 // Broadcast finalized blocks info, if any
                 match to_broadcast {
                     Some(blocks) => {
+                        debug!("handle_receive_vote(): Broadcasting finalized blocks");
                         for info in blocks {
                             self.sync_p2p.broadcast(info).await?;
                         }
                     }
-                    None => continue,
+                    None => {
+                        debug!("handle_receive_vote(): No finalized blocks to broadcast");
+                        continue
+                    }
                 }
             }
         }

+ 12 - 13
src/consensus2/state.rs

@@ -214,24 +214,23 @@ impl ValidatorState {
     /// Finds the longest fully notarized blockchain the node holds and
     /// returns the last block hash and the chain index.
     pub fn longest_notarized_chain_last_hash(&self) -> Result<(blake3::Hash, i64)> {
-        let mut longest_notarized_chain = &self.consensus.proposals[0];
-        let mut length = longest_notarized_chain.proposals.len();
+        let mut longest_notarized_chain: Option<ProposalChain> = None;
+        let mut length = 0;
         let mut index = -1;
 
-        let hash = if !self.consensus.proposals.is_empty() {
-            if self.consensus.proposals.len() > 1 {
-                for (i, chain) in self.consensus.proposals.iter().enumerate() {
-                    if chain.notarized() && chain.proposals.len() > length {
-                        length = chain.proposals.len();
-                        longest_notarized_chain = chain;
-                        index = i as i64;
-                    }
+        if !self.consensus.proposals.is_empty() {
+            for (i, chain) in self.consensus.proposals.iter().enumerate() {
+                if chain.notarized() && chain.proposals.len() > length {
+                    longest_notarized_chain = Some(chain.clone());
+                    length = chain.proposals.len();
+                    index = i as i64;
                 }
             }
+        }
 
-            longest_notarized_chain.proposals.last().unwrap().hash()
-        } else {
-            self.blockchain.last()?.unwrap().1
+        let hash = match longest_notarized_chain {
+            Some(chain) => chain.proposals.last().unwrap().hash(),
+            None => self.blockchain.last()?.unwrap().1,
         };
 
         Ok((hash, index))