Commit f58cb8bc authored by Ashley's avatar Ashley Committed by Bastian Köcher
Browse files

Changes for substrate#3699 (#466)

* change upstream and branch

* Fix build

* remove doc renamings

* Fix tests

* .

* Revert changing fork and branch

* Update Cargo.toml

* Update parachains.rs
parent ad2f6e2b
Pipeline #53684 passed with stages
in 19 minutes and 55 seconds
This diff is collapsed.
...@@ -42,6 +42,7 @@ im-online = { package = "srml-im-online", git = "https://github.com/paritytech/s ...@@ -42,6 +42,7 @@ im-online = { package = "srml-im-online", git = "https://github.com/paritytech/s
indices = { package = "srml-indices", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" } indices = { package = "srml-indices", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
membership = { package = "srml-membership", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" } membership = { package = "srml-membership", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
offences = { package = "srml-offences", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" } offences = { package = "srml-offences", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
randomness-collective-flip = { package = "srml-randomness-collective-flip", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
session = { package = "srml-session", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" } session = { package = "srml-session", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
srml-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" } srml-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
staking = { package = "srml-staking", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" } staking = { package = "srml-staking", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
......
...@@ -521,6 +521,7 @@ construct_runtime!( ...@@ -521,6 +521,7 @@ construct_runtime!(
{ {
// Basic stuff; balances is uncallable initially. // Basic stuff; balances is uncallable initially.
System: system::{Module, Call, Storage, Config, Event}, System: system::{Module, Call, Storage, Config, Event},
RandomnessCollectiveFlip: randomness_collective_flip::{Module, Storage},
// Must be before session. // Must be before session.
Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)}, Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
...@@ -629,7 +630,7 @@ impl_runtime_apis! { ...@@ -629,7 +630,7 @@ impl_runtime_apis! {
} }
fn random_seed() -> <Block as BlockT>::Hash { fn random_seed() -> <Block as BlockT>::Hash {
System::random_seed() RandomnessCollectiveFlip::random_seed()
} }
} }
......
...@@ -538,7 +538,7 @@ impl<T: Trait> Module<T> { ...@@ -538,7 +538,7 @@ impl<T: Trait> Module<T> {
let mut seed = { let mut seed = {
let phrase = b"validator_role_pairs"; let phrase = b"validator_role_pairs";
let seed = system::Module::<T>::random(&phrase[..]); let seed = randomness_collective_flip::Module::<T>::random(&phrase[..]);
let seed_len = seed.as_ref().len(); let seed_len = seed.as_ref().len();
let needed_bytes = validator_count * 4; let needed_bytes = validator_count * 4;
...@@ -887,7 +887,7 @@ mod tests { ...@@ -887,7 +887,7 @@ mod tests {
use substrate_trie::NodeCodec; use substrate_trie::NodeCodec;
use sr_primitives::{ use sr_primitives::{
Perbill, Perbill,
traits::{BlakeTwo256, IdentityLookup, ConvertInto}, traits::{BlakeTwo256, IdentityLookup, ConvertInto, OnInitialize},
testing::{UintAuthorityId, Header}, testing::{UintAuthorityId, Header},
curve::PiecewiseLinear, curve::PiecewiseLinear,
}; };
...@@ -1056,6 +1056,7 @@ mod tests { ...@@ -1056,6 +1056,7 @@ mod tests {
type Parachains = Module<Test>; type Parachains = Module<Test>;
type System = system::Module<Test>; type System = system::Module<Test>;
type RandomnessCollectiveFlip = randomness_collective_flip::Module<Test>;
fn new_test_ext(parachains: Vec<(ParaId, Vec<u8>, Vec<u8>)>) -> TestExternalities<Blake2Hasher> { fn new_test_ext(parachains: Vec<(ParaId, Vec<u8>, Vec<u8>)>) -> TestExternalities<Blake2Hasher> {
use staking::StakerStatus; use staking::StakerStatus;
...@@ -1540,16 +1541,18 @@ mod tests { ...@@ -1540,16 +1541,18 @@ mod tests {
check_roster(&duty_roster_0); check_roster(&duty_roster_0);
System::initialize(&1, &H256::from([1; 32]), &Default::default(), &Default::default()); System::initialize(&1, &H256::from([1; 32]), &Default::default(), &Default::default());
RandomnessCollectiveFlip::on_initialize(1);
let duty_roster_1 = Parachains::calculate_duty_roster().0; let duty_roster_1 = Parachains::calculate_duty_roster().0;
check_roster(&duty_roster_1); check_roster(&duty_roster_1);
assert!(duty_roster_0 != duty_roster_1); assert_ne!(duty_roster_0, duty_roster_1);
System::initialize(&2, &H256::from([2; 32]), &Default::default(), &Default::default()); System::initialize(&2, &H256::from([2; 32]), &Default::default(), &Default::default());
RandomnessCollectiveFlip::on_initialize(2);
let duty_roster_2 = Parachains::calculate_duty_roster().0; let duty_roster_2 = Parachains::calculate_duty_roster().0;
check_roster(&duty_roster_2); check_roster(&duty_roster_2);
assert!(duty_roster_0 != duty_roster_2); assert_ne!(duty_roster_0, duty_roster_2);
assert!(duty_roster_1 != duty_roster_2); assert_ne!(duty_roster_1, duty_roster_2);
}); });
} }
......
...@@ -437,7 +437,7 @@ impl<T: Trait> Module<T> { ...@@ -437,7 +437,7 @@ impl<T: Trait> Module<T> {
if early_end + T::EndingPeriod::get() == now { if early_end + T::EndingPeriod::get() == now {
// Just ended! // Just ended!
let ending_period = T::EndingPeriod::get(); let ending_period = T::EndingPeriod::get();
let offset = T::BlockNumber::decode(&mut<system::Module<T>>::random_seed().as_ref()) let offset = T::BlockNumber::decode(&mut<randomness_collective_flip::Module<T>>::random_seed().as_ref())
.expect("secure hashes always bigger than block numbers; qed") % ending_period; .expect("secure hashes always bigger than block numbers; qed") % ending_period;
let res = <Winning<T>>::get(offset).unwrap_or_default(); let res = <Winning<T>>::get(offset).unwrap_or_default();
let mut i = T::BlockNumber::zero(); let mut i = T::BlockNumber::zero();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment