Approval-distribution: Fix out-of-view messages caused by a race condition in view updates (#5089)

* Try to fix out-of-view messages in approval distribution

Suggested by: @ordian

* Cargo fmt

* Add a unit test for the proposed fix

* Spelling fix

* Use a simplier approach to fix the race condition as suggested by @rphmeier

* Cargo fmt run
This commit is contained in:
Vsevolod Stakhov
2022-03-14 16:07:32 +00:00
committed by GitHub
parent c18e804c3d
commit 55b38b2b8f
2 changed files with 93 additions and 15 deletions
@@ -294,6 +294,20 @@ impl State {
);
{
for (peer_id, view) in self.peer_views.iter() {
let intersection = view.iter().filter(|h| new_hashes.contains(h));
let view_intersection = View::new(intersection.cloned(), view.finalized_number);
Self::unify_with_peer(
ctx,
&self.gossip_peers,
metrics,
&mut self.blocks,
peer_id.clone(),
view_intersection,
)
.await;
}
let pending_now_known = self
.pending_known
.keys()
@@ -348,20 +362,6 @@ impl State {
}
}
}
for (peer_id, view) in self.peer_views.iter() {
let intersection = view.iter().filter(|h| new_hashes.contains(h));
let view_intersection = View::new(intersection.cloned(), view.finalized_number);
Self::unify_with_peer(
ctx,
&self.gossip_peers,
metrics,
&mut self.blocks,
peer_id.clone(),
view_intersection,
)
.await;
}
}
async fn process_incoming_peer_message(