Try to fix out of view statements (#5177)

This issue happens when some peer sends a good but already known Seconded statement and the statement-distribution code does not update the statements_received field in the peer_knowledge structure. Subsequently, a Valid statement causes out-of-view message that is incorrectly emitted and causes reputation lose.

This PR also introduces a concept of passing the specific pseudo-random generator to subsystems to make it easier to write deterministic tests. This functionality is not really necessary for the specific issue and unit test but it can be useful for other tests and subsystems.
This commit is contained in:
Vsevolod Stakhov
2022-03-24 20:18:43 +00:00
committed by GitHub
parent b424e5e741
commit af94fc9534
10 changed files with 474 additions and 46 deletions
@@ -346,7 +346,7 @@ async fn relay_message<Context>(
let _span = span.child("interested-peers");
// pass on the bitfield distribution to all interested peers
let interested_peers = peer_views
let mut interested_peers = peer_views
.iter()
.filter_map(|(peer, view)| {
// check interest in the peer in this message's relay parent
@@ -363,9 +363,9 @@ async fn relay_message<Context>(
}
})
.collect::<Vec<PeerId>>();
let interested_peers = util::choose_random_subset(
util::choose_random_subset(
|e| gossip_peers.contains(e),
interested_peers,
&mut interested_peers,
MIN_GOSSIP_PEERS,
);
interested_peers.iter().for_each(|peer| {