mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 01:21:01 +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:
@@ -26,6 +26,7 @@ use polkadot_primitives::v2::{
|
||||
CommittedCandidateReceipt, Hash, HeadData, Id as ParaId, ValidationCode, ValidationCodeHash,
|
||||
ValidatorId,
|
||||
};
|
||||
pub use rand;
|
||||
use sp_application_crypto::sr25519;
|
||||
use sp_keyring::Sr25519Keyring;
|
||||
use sp_runtime::generic::Digest;
|
||||
@@ -224,3 +225,33 @@ impl TestCandidateBuilder {
|
||||
CandidateReceipt { descriptor, commitments_hash: self.commitments_hash }
|
||||
}
|
||||
}
|
||||
|
||||
/// A special `Rng` that always returns zero for testing something that implied
|
||||
/// to be random but should not be random in the tests
|
||||
pub struct AlwaysZeroRng;
|
||||
|
||||
impl Default for AlwaysZeroRng {
|
||||
fn default() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
impl rand::RngCore for AlwaysZeroRng {
|
||||
fn next_u32(&mut self) -> u32 {
|
||||
0_u32
|
||||
}
|
||||
|
||||
fn next_u64(&mut self) -> u64 {
|
||||
0_u64
|
||||
}
|
||||
|
||||
fn fill_bytes(&mut self, dest: &mut [u8]) {
|
||||
for element in dest.iter_mut() {
|
||||
*element = 0_u8;
|
||||
}
|
||||
}
|
||||
|
||||
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> {
|
||||
self.fill_bytes(dest);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user