mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 15:11:02 +00:00
update substrate reference (#249)
* update substrate reference * bump wasm
This commit is contained in:
committed by
Gavin Wood
parent
4e9fb2d2b5
commit
36dd42523d
@@ -47,15 +47,29 @@ decl_module! {
|
||||
if shuffle_period == 0 { return }
|
||||
|
||||
if block_number.as_() % shuffle_period == 0 {
|
||||
let mut seed = system::Module::<T>::random_seed().as_ref().to_vec();
|
||||
seed.extend(b"grandpa_shuffling");
|
||||
let mut seed = BlakeTwo256::hash(&seed);
|
||||
|
||||
let mut voters = grandpa::Module::<T>::grandpa_authorities();
|
||||
let voter_count = voters.len();
|
||||
|
||||
if voter_count == 0 { return }
|
||||
|
||||
let mut seed = {
|
||||
let phrase = b"grandpa_shuffling";
|
||||
let seed = system::Module::<T>::random(&phrase[..]);
|
||||
let seed_len = seed.as_ref().len();
|
||||
let needed_bytes = voter_count * 4;
|
||||
|
||||
// hash only the needed bits of the random seed.
|
||||
// if earlier bits are influencable, they will not factor into
|
||||
// the seed used here.
|
||||
let seed_off = if needed_bytes >= seed_len {
|
||||
0
|
||||
} else {
|
||||
seed_len - needed_bytes
|
||||
};
|
||||
|
||||
BlakeTwo256::hash(&seed.as_ref()[seed_off..])
|
||||
};
|
||||
|
||||
for i in 0..(voter_count - 1) {
|
||||
// 4 bytes of entropy used per cycle, 32 bytes entropy per hash
|
||||
let offset = (i * 4 % 32) as usize;
|
||||
|
||||
@@ -208,9 +208,24 @@ impl<T: Trait> Module<T> {
|
||||
_ => Chain::Relay,
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
let mut random_seed = system::Module::<T>::random_seed().as_ref().to_vec();
|
||||
random_seed.extend(b"validator_role_pairs");
|
||||
let mut seed = BlakeTwo256::hash(&random_seed);
|
||||
|
||||
let mut seed = {
|
||||
let phrase = b"validator_role_pairs";
|
||||
let seed = system::Module::<T>::random(&phrase[..]);
|
||||
let seed_len = seed.as_ref().len();
|
||||
let needed_bytes = validator_count * 4;
|
||||
|
||||
// hash only the needed bits of the random seed.
|
||||
// if earlier bits are influencable, they will not factor into
|
||||
// the seed used here.
|
||||
let seed_off = if needed_bytes >= seed_len {
|
||||
0
|
||||
} else {
|
||||
seed_len - needed_bytes
|
||||
};
|
||||
|
||||
BlakeTwo256::hash(&seed.as_ref()[seed_off..])
|
||||
};
|
||||
|
||||
// shuffle
|
||||
for i in 0..(validator_count - 1) {
|
||||
@@ -504,6 +519,7 @@ mod tests {
|
||||
impl Trait for Test {}
|
||||
|
||||
type Parachains = Module<Test>;
|
||||
type System = system::Module<Test>;
|
||||
|
||||
fn new_test_ext(parachains: Vec<(ParaId, Vec<u8>, Vec<u8>)>) -> TestExternalities<Blake2Hasher> {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
|
||||
@@ -653,17 +669,16 @@ mod tests {
|
||||
assert_eq!(duty_roster.validator_duty.iter().filter(|&&j| j == Chain::Relay).count(), 2);
|
||||
};
|
||||
|
||||
system::Module::<Test>::set_random_seed([0u8; 32].into());
|
||||
let duty_roster_0 = Parachains::calculate_duty_roster();
|
||||
check_roster(&duty_roster_0);
|
||||
|
||||
system::Module::<Test>::set_random_seed([1u8; 32].into());
|
||||
System::initialize(&1, &H256::from([1; 32]), &Default::default());
|
||||
let duty_roster_1 = Parachains::calculate_duty_roster();
|
||||
check_roster(&duty_roster_1);
|
||||
assert!(duty_roster_0 != duty_roster_1);
|
||||
|
||||
|
||||
system::Module::<Test>::set_random_seed([2u8; 32].into());
|
||||
System::initialize(&2, &H256::from([2; 32]), &Default::default());
|
||||
let duty_roster_2 = Parachains::calculate_duty_roster();
|
||||
check_roster(&duty_roster_2);
|
||||
assert!(duty_roster_0 != duty_roster_2);
|
||||
@@ -679,7 +694,6 @@ mod tests {
|
||||
];
|
||||
|
||||
with_externalities(&mut new_test_ext(parachains), || {
|
||||
system::Module::<Test>::set_random_seed([0u8; 32].into());
|
||||
let candidate = AttestedCandidate {
|
||||
validity_votes: vec![],
|
||||
candidate: CandidateReceipt {
|
||||
@@ -707,7 +721,6 @@ mod tests {
|
||||
];
|
||||
|
||||
with_externalities(&mut new_test_ext(parachains), || {
|
||||
system::Module::<Test>::set_random_seed([0u8; 32].into());
|
||||
let mut candidate_a = AttestedCandidate {
|
||||
validity_votes: vec![],
|
||||
candidate: CandidateReceipt {
|
||||
@@ -759,7 +772,6 @@ mod tests {
|
||||
];
|
||||
|
||||
with_externalities(&mut new_test_ext(parachains), || {
|
||||
system::Module::<Test>::set_random_seed([0u8; 32].into());
|
||||
let mut candidate = AttestedCandidate {
|
||||
validity_votes: vec![],
|
||||
candidate: CandidateReceipt {
|
||||
@@ -795,7 +807,6 @@ mod tests {
|
||||
];
|
||||
|
||||
with_externalities(&mut new_test_ext(parachains), || {
|
||||
system::Module::<Test>::set_random_seed([0u8; 32].into());
|
||||
let from_a = vec![(1.into(), [1; 32].into())];
|
||||
let mut candidate_a = AttestedCandidate {
|
||||
validity_votes: vec![],
|
||||
@@ -865,7 +876,6 @@ mod tests {
|
||||
];
|
||||
|
||||
with_externalities(&mut new_test_ext(parachains), || {
|
||||
system::Module::<Test>::set_random_seed([0u8; 32].into());
|
||||
// parachain 99 does not exist
|
||||
let non_existent = vec![(99.into(), [1; 32].into())];
|
||||
let mut candidate = new_candidate_with_egress_roots(non_existent);
|
||||
@@ -890,7 +900,6 @@ mod tests {
|
||||
];
|
||||
|
||||
with_externalities(&mut new_test_ext(parachains), || {
|
||||
system::Module::<Test>::set_random_seed([0u8; 32].into());
|
||||
// parachain 0 is self
|
||||
let to_self = vec![(0.into(), [1; 32].into())];
|
||||
let mut candidate = new_candidate_with_egress_roots(to_self);
|
||||
@@ -915,7 +924,6 @@ mod tests {
|
||||
];
|
||||
|
||||
with_externalities(&mut new_test_ext(parachains), || {
|
||||
system::Module::<Test>::set_random_seed([0u8; 32].into());
|
||||
// parachain 0 is self
|
||||
let out_of_order = vec![(1.into(), [1; 32].into()), ((0.into(), [1; 32].into()))];
|
||||
let mut candidate = new_candidate_with_egress_roots(out_of_order);
|
||||
@@ -940,7 +948,6 @@ mod tests {
|
||||
];
|
||||
|
||||
with_externalities(&mut new_test_ext(parachains), || {
|
||||
system::Module::<Test>::set_random_seed([0u8; 32].into());
|
||||
// parachain 0 is self
|
||||
let contains_empty_trie_root = vec![(1.into(), [1; 32].into()), ((2.into(), EMPTY_TRIE_ROOT.into()))];
|
||||
let mut candidate = new_candidate_with_egress_roots(contains_empty_trie_root);
|
||||
|
||||
Reference in New Issue
Block a user