pub fn add_response(
        &mut self,
        from_addr: &SocketAddr,
        response_slot_hashes: Vec<(Slot, Hash)>,
        blockstore: &Blockstore,
    ) -> Option<DuplicateAncestorDecision> {
        if let Some(did_get_response) = self.sampled_validators.get_mut(from_addr) {
            if *did_get_response {
                // If we've already received a response from this validator, return.
                return None;
            }
            // Mark we got a response from this validator already
            *did_get_response = true;
            self.num_responses += 1;
        } else {
            // If this is not a response from one of the sampled validators, return.
            return None;
        }

        let validators_with_same_response = self
            .ancestor_request_responses
            .entry(response_slot_hashes.clone())
            .or_default();
        validators_with_same_response.push(*from_addr);

        // If we got enough of the sampled validators to respond, we are confident
        // this is the correct set of ancestors
        if validators_with_same_response.len()
            == MINIMUM_ANCESTOR_AGREEMENT_SIZE.min(self.sampled_validators.len())
        {
            // When we reach MINIMUM_ANCESTOR_AGREEMENT_SIZE of the same responses,
            // check for mismatches.
            return Some(
                self.handle_sampled_validators_reached_agreement(blockstore, response_slot_hashes),
            );
        }

        // If everyone responded and we still haven't agreed upon a set of
        // ancestors, that means there was a lot of disagreement and we sampled
        // a bad set of validators.
        if self.num_responses == ANCESTOR_HASH_REPAIR_SAMPLE_SIZE.min(self.sampled_validators.len())
        {
            info!(
                "{} return invalid sample no agreement",
                self.requested_mismatched_slot
            );
            return Some(DuplicateAncestorDecision::InvalidSample);
        }

        None
    }
/// Record the response from `from_addr`. Returns Some(DuplicateAncestorDecision)
/// if we have finalized a decision based on the responses. We can finalize a decision when
/// one of the following conditions is met:
/// 1) We have heard from all the validators, OR
/// 2) >= MINIMUM_ANCESTOR_AGREEMENT_SIZE have agreed that we have the correct versions
/// of nth ancestor, for some `n>0`, AND >= MINIMUM_ANCESTOR_AGREEMENT_SIZE have
/// agreed we have the wrong version of the `n-1` ancestor.
Record the response from `from_addr`. Returns Some(DuplicateAncestorDecision)
if we have finalized a decision based on the responses. We can finalize a decision when
one of the following conditions is met:
1) We have heard from all the validators, OR
2) >= MINIMUM_ANCESTOR_AGREEMENT_SIZE have agreed that we have the correct versions
of nth ancestor, for some `n>0`, AND >= MINIMUM_ANCESTOR_AGREEMENT_SIZE have
agreed we have the wrong version of the `n-1` ancestor.
Record the response from ` from_addr ` . Returns Some ( DuplicateAncestorDecision ) if we have finalized a decision based on the responses . We can finalize a decision when one of the following conditions is met : 1 ) We have heard from all the validators OR 2 ) > = MINIMUM_ANCESTOR_AGREEMENT_SIZE have agreed that we have the correct versions of nth ancestor for some ` n > 0 ` AND > = MINIMUM_ANCESTOR_AGREEMENT_SIZE have agreed we have the wrong version of the ` n - 1 ` ancestor .
pub fn add_response(
        &mut self,
        from_addr: &SocketAddr,
        response_slot_hashes: Vec<(Slot, Hash)>,
        blockstore: &Blockstore,
    ) -> Option<DuplicateAncestorDecision> {
        if let Some(did_get_response) = self.sampled_validators.get_mut(from_addr) {
            if *did_get_response {
                // If we've already received a response from this validator, return.
                return None;
            }
            // Mark we got a response from this validator already
            *did_get_response = true;
            self.num_responses += 1;
        } else {
            // If this is not a response from one of the sampled validators, return.
            return None;
        }
        let validators_with_same_response = self
            .ancestor_request_responses
            .entry(response_slot_hashes.clone())
            .or_default();
        validators_with_same_response.push(*from_addr);
        // If we got enough of the sampled validators to respond, we are confident
        // this is the correct set of ancestors
        if validators_with_same_response.len()
            == MINIMUM_ANCESTOR_AGREEMENT_SIZE.min(self.sampled_validators.len())
        {
            // When we reach MINIMUM_ANCESTOR_AGREEMENT_SIZE of the same responses,
            // check for mismatches.
            return Some(
                self.handle_sampled_validators_reached_agreement(blockstore, response_slot_hashes),
            );
        }
        // If everyone responded and we still haven't agreed upon a set of
        // ancestors, that means there was a lot of disagreement and we sampled
        // a bad set of validators.
        if self.num_responses == ANCESTOR_HASH_REPAIR_SAMPLE_SIZE.min(self.sampled_validators.len())
        {
            info!(
                "{} return invalid sample no agreement",
                self.requested_mismatched_slot
            );
            return Some(DuplicateAncestorDecision::InvalidSample);
        }
        None
    }
pub fn add_response ( & mut self , from_addr : & SocketAddr , response_slot_hashes : Vec < ( Slot , Hash ) > , blockstore : & Blockstore , ) -> Option < DuplicateAncestorDecision > { if let Some ( did_get_response ) = self . sampled_validators . get_mut ( from_addr ) { if * did_get_response { // If we've already received a response from this validator, return. return None ; } // Mark we got a response from this validator already * did_get_response = true ; self . num_responses += 1 ; } else { // If this is not a response from one of the sampled validators, return. return None ; } let validators_with_same_response = self . ancestor_request_responses . entry ( response_slot_hashes . clone ( ) ) . or_default ( ) ; validators_with_same_response . push ( * from_addr ) ; // If we got enough of the sampled validators to respond, we are confident // this is the correct set of ancestors if validators_with_same_response . len ( ) == MINIMUM_ANCESTOR_AGREEMENT_SIZE . min ( self . sampled_validators . len ( ) ) { // When we reach MINIMUM_ANCESTOR_AGREEMENT_SIZE of the same responses, // check for mismatches. return Some ( self . handle_sampled_validators_reached_agreement ( blockstore , response_slot_hashes ) , ) ; } // If everyone responded and we still haven't agreed upon a set of // ancestors, that means there was a lot of disagreement and we sampled // a bad set of validators. if self . num_responses == ANCESTOR_HASH_REPAIR_SAMPLE_SIZE . min ( self . sampled_validators . len ( ) ) { info ! ( " " self requested_mismatched_slot ) ; return Some ( DuplicateAncestorDecision :: InvalidSample ) ; } None }
Record the response from `from_addr`.
Record the response from ` from_addr ` .
&mut self
from_addr
&SocketAddr
response_slot_hashes
Vec<(Slot, Hash)>
blockstore
&Blockstore