Enable Offchain Equalise (#5683)

* Master.into()

* Remove debug stuff

* Better license

* Migrate away from SimpleDispatchInfo

* Fix test

* Revert "Migrate away from SimpleDispatchInfo"

This reverts commit dbdd27fa19948f16bd17defdc01d3dd32986df11.

* Move to offchain randomness

* Fix tests

* Fix tests more
This commit is contained in:
Kian Paimani
2020-04-27 18:51:46 +02:00
committed by GitHub
parent 33d00692d8
commit ee54eff488
20 changed files with 635 additions and 373 deletions
+16
View File
@@ -64,6 +64,7 @@ thread_local! {
static SLASH_DEFER_DURATION: RefCell<EraIndex> = RefCell::new(0);
static ELECTION_LOOKAHEAD: RefCell<BlockNumber> = RefCell::new(0);
static PERIOD: RefCell<BlockNumber> = RefCell::new(1);
static MAX_ITERATIONS: RefCell<u32> = RefCell::new(0);
}
/// Another session handler struct to test on_disabled.
@@ -143,6 +144,13 @@ impl Get<EraIndex> for SlashDeferDuration {
}
}
pub struct MaxIterations;
impl Get<u32> for MaxIterations {
fn get() -> u32 {
MAX_ITERATIONS.with(|v| *v.borrow())
}
}
impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
}
@@ -310,6 +318,7 @@ impl Trait for Test {
type NextNewSession = Session;
type ElectionLookahead = ElectionLookahead;
type Call = Call;
type MaxIterations = MaxIterations;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type UnsignedPriority = UnsignedPriority;
}
@@ -337,6 +346,7 @@ pub struct ExtBuilder {
num_validators: Option<u32>,
invulnerables: Vec<AccountId>,
has_stakers: bool,
max_offchain_iterations: u32,
}
impl Default for ExtBuilder {
@@ -355,6 +365,7 @@ impl Default for ExtBuilder {
num_validators: None,
invulnerables: vec![],
has_stakers: true,
max_offchain_iterations: 0,
}
}
}
@@ -412,6 +423,10 @@ impl ExtBuilder {
self.has_stakers = has;
self
}
pub fn max_offchain_iterations(mut self, iterations: u32) -> Self {
self.max_offchain_iterations = iterations;
self
}
pub fn offchain_phragmen_ext(self) -> Self {
self.session_per_era(4)
.session_length(5)
@@ -423,6 +438,7 @@ impl ExtBuilder {
SESSION_PER_ERA.with(|v| *v.borrow_mut() = self.session_per_era);
ELECTION_LOOKAHEAD.with(|v| *v.borrow_mut() = self.election_lookahead);
PERIOD.with(|v| *v.borrow_mut() = self.session_length);
MAX_ITERATIONS.with(|v| *v.borrow_mut() = self.max_offchain_iterations);
}
pub fn build(self) -> sp_io::TestExternalities {
let _ = env_logger::try_init();