mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 10:17:57 +00:00
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:
@@ -25,7 +25,7 @@ use polkadot_node_subsystem::{
|
||||
};
|
||||
use polkadot_node_subsystem_test_helpers::{self as test_helpers, make_subsystem_context};
|
||||
use polkadot_primitives::v2::Hash;
|
||||
use polkadot_primitives_test_helpers::{dummy_candidate_receipt, dummy_hash};
|
||||
use polkadot_primitives_test_helpers::{dummy_candidate_receipt, dummy_hash, AlwaysZeroRng};
|
||||
use std::{
|
||||
pin::Pin,
|
||||
sync::{
|
||||
@@ -248,11 +248,23 @@ fn tick_tack_metronome() {
|
||||
|
||||
#[test]
|
||||
fn subset_generation_check() {
|
||||
let values = (0_u8..=25).collect::<Vec<_>>();
|
||||
let mut values = (0_u8..=25).collect::<Vec<_>>();
|
||||
// 12 even numbers exist
|
||||
let mut chosen = choose_random_subset::<u8, _>(|v| v & 0x01 == 0, values, 12);
|
||||
chosen.sort();
|
||||
for (idx, v) in dbg!(chosen).into_iter().enumerate() {
|
||||
choose_random_subset::<u8, _>(|v| v & 0x01 == 0, &mut values, 12);
|
||||
values.sort();
|
||||
for (idx, v) in dbg!(values).into_iter().enumerate() {
|
||||
assert_eq!(v as usize, idx * 2);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subset_predefined_generation_check() {
|
||||
let mut values = (0_u8..=25).collect::<Vec<_>>();
|
||||
choose_random_subset_with_rng::<u8, _, _>(|_| false, &mut values, &mut AlwaysZeroRng, 12);
|
||||
assert_eq!(values.len(), 12);
|
||||
for (idx, v) in dbg!(values).into_iter().enumerate() {
|
||||
// Since shuffle actually shuffles the indexes from 1..len, then
|
||||
// our PRG that returns zeroes will shuffle 0 and 1, 1 and 2, ... len-2 and len-1
|
||||
assert_eq!(v as usize, idx + 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user