fix freshness calculations in statement distribution (#5151)

* fix freshness calculations in statement distribution

* Fix logic.

Co-authored-by: Robert Klotzner <robert.klotzner@gmx.at>
This commit is contained in:
asynchronous rob
2022-03-18 09:40:44 -05:00
committed by GitHub
parent 6e3b5f1888
commit d76583cd3b
@@ -269,7 +269,9 @@ impl PeerRelayParentKnowledge {
CompactStatement::Seconded(ref h) => { CompactStatement::Seconded(ref h) => {
self.seconded_counts.entry(fingerprint.1).or_default().note_local(h.clone()); self.seconded_counts.entry(fingerprint.1).or_default().note_local(h.clone());
self.sent_candidates.insert(h.clone()) let was_known = self.is_known_candidate(h);
self.sent_candidates.insert(h.clone());
!was_known
}, },
CompactStatement::Valid(_) => false, CompactStatement::Valid(_) => false,
}; };
@@ -291,7 +293,7 @@ impl PeerRelayParentKnowledge {
match fingerprint.0 { match fingerprint.0 {
CompactStatement::Valid(ref h) => { CompactStatement::Valid(ref h) => {
// The peer can only accept Valid and Invalid statements for which it is aware // The peer can only accept Valid statements for which it is aware
// of the corresponding candidate. // of the corresponding candidate.
self.is_known_candidate(h) self.is_known_candidate(h)
}, },
@@ -326,7 +328,7 @@ impl PeerRelayParentKnowledge {
return Err(COST_DUPLICATE_STATEMENT) return Err(COST_DUPLICATE_STATEMENT)
} }
let candidate_hash = match fingerprint.0 { let (candidate_hash, fresh) = match fingerprint.0 {
CompactStatement::Seconded(ref h) => { CompactStatement::Seconded(ref h) => {
let allowed_remote = self let allowed_remote = self
.seconded_counts .seconded_counts
@@ -338,14 +340,14 @@ impl PeerRelayParentKnowledge {
return Err(COST_UNEXPECTED_STATEMENT_REMOTE) return Err(COST_UNEXPECTED_STATEMENT_REMOTE)
} }
h (h, !self.is_known_candidate(h))
}, },
CompactStatement::Valid(ref h) => { CompactStatement::Valid(ref h) => {
if !self.is_known_candidate(&h) { if !self.is_known_candidate(h) {
return Err(COST_UNEXPECTED_STATEMENT_UNKNOWN_CANDIDATE) return Err(COST_UNEXPECTED_STATEMENT_UNKNOWN_CANDIDATE)
} }
h (h, false)
}, },
}; };
@@ -361,7 +363,8 @@ impl PeerRelayParentKnowledge {
} }
self.received_statements.insert(fingerprint.clone()); self.received_statements.insert(fingerprint.clone());
Ok(self.received_candidates.insert(candidate_hash.clone())) self.received_candidates.insert(candidate_hash.clone());
Ok(fresh)
} }
/// Note a received large statement metadata. /// Note a received large statement metadata.