Просмотр исходного кода

consensus: fixed proposal broadcasting loop

aggstam 3 лет назад
Родитель
Сommit
0ba46d1421
2 измененных файлов с 19 добавлено и 3 удалено
  1. 17 1
      src/consensus/proto/protocol_proposal.rs
  2. 2 2
      src/consensus/state.rs

+ 17 - 1
src/consensus/proto/protocol_proposal.rs

@@ -62,8 +62,24 @@ impl ProtocolProposal {
             debug!("ProtocolProposal::handle_receive_proposal(): Full proposal: {:?}", proposal);
 
             let proposal_copy = (*proposal).clone();
+            
+            let mut state = self.state.write().await;
+            
+            // Verify we have the proposal already
+            match state.find_proposal(&proposal_copy.block.header.headerhash()) {
+                Ok(p) => {
+                    if let Some(_) = p {
+                        debug!("ProtocolProposal::handle_receive_proposal(): Proposal already received.");
+                        continue
+                    }
+                },
+                Err(e) => {
+                    error!("ProtocolProposal::handle_receive_proposal(): find_proposal() failed: {}", e);
+                    continue
+                }
+            };
 
-            if let Err(e) = self.state.write().await.receive_proposal(&proposal_copy).await {
+            if let Err(e) = state.receive_proposal(&proposal_copy).await {
                 error!(
                     "ProtocolProposal::handle_receive_proposal(): receive_proposal error: {}",
                     e

+ 2 - 2
src/consensus/state.rs

@@ -506,12 +506,12 @@ impl ValidatorState {
     /// Search the chains we're holding for the given proposal.
     pub fn find_proposal(
         &mut self,
-        vote_proposal: &blake3::Hash,
+        input_proposal: &blake3::Hash,
     ) -> Result<Option<(&mut BlockProposal, i64)>> {
         for (index, chain) in &mut self.consensus.proposals.iter_mut().enumerate() {
             for proposal in chain.proposals.iter_mut().rev() {
                 let proposal_hash = proposal.block.header.headerhash();
-                if vote_proposal == &proposal_hash {
+                if input_proposal == &proposal_hash {
                     return Ok(Some((proposal, index as i64)))
                 }
             }