Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,11 @@ pub mod pallet {
compute: ElectionCompute::Emergency,
};

Self::deposit_event(Event::SolutionStored {
election_compute: ElectionCompute::Emergency,
prev_ejected: QueuedSolution::<T>::exists(),
});

<QueuedSolution<T>>::put(solution);
Ok(())
}
Expand Down Expand Up @@ -1057,6 +1062,11 @@ pub mod pallet {
compute: ElectionCompute::Fallback,
};

Self::deposit_event(Event::SolutionStored {
election_compute: ElectionCompute::Fallback,
prev_ejected: QueuedSolution::<T>::exists(),
});

<QueuedSolution<T>>::put(solution);
Ok(())
}
Expand Down Expand Up @@ -1792,7 +1802,7 @@ mod tests {
use crate::{
mock::{
multi_phase_events, roll_to, AccountId, ExtBuilder, MockWeightInfo, MockedWeightInfo,
MultiPhase, Runtime, SignedMaxSubmissions, System, TargetIndex, Targets,
MultiPhase, Origin, Runtime, SignedMaxSubmissions, System, TargetIndex, Targets,
},
Phase,
};
Expand Down Expand Up @@ -2038,6 +2048,50 @@ mod tests {
})
}

#[test]
fn governance_fallback_works() {
ExtBuilder::default().onchain_fallback(false).build_and_execute(|| {
roll_to(25);
assert_eq!(MultiPhase::current_phase(), Phase::Unsigned((true, 25)));

// Zilch solutions thus far.
assert!(MultiPhase::queued_solution().is_none());
assert_eq!(MultiPhase::elect().unwrap_err(), ElectionError::Fallback("NoFallback."));

// phase is now emergency.
assert_eq!(MultiPhase::current_phase(), Phase::Emergency);
assert!(MultiPhase::queued_solution().is_none());

// no single account can trigger this
assert_noop!(
MultiPhase::governance_fallback(Origin::signed(99), None, None),
DispatchError::BadOrigin
);

// only root can
assert_ok!(MultiPhase::governance_fallback(Origin::root(), None, None));
// something is queued now
assert!(MultiPhase::queued_solution().is_some());
// next election call with fix everything.;
assert!(MultiPhase::elect().is_ok());
assert_eq!(MultiPhase::current_phase(), Phase::Off);

assert_eq!(
multi_phase_events(),
vec![
Event::SignedPhaseStarted { round: 1 },
Event::UnsignedPhaseStarted { round: 1 },
Event::ElectionFinalized { election_compute: None },
Event::SolutionStored {
election_compute: ElectionCompute::Fallback,
prev_ejected: false
},
Event::ElectionFinalized { election_compute: Some(ElectionCompute::Fallback) }
]
);
})
}

#[test]
fn snapshot_too_big_failure_onchain_fallback() {
// the `MockStaking` is designed such that if it has too many targets, it simply fails.
Expand Down
6 changes: 4 additions & 2 deletions frame/election-provider-multi-phase/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
use super::*;
use crate::{self as multi_phase, unsigned::MinerConfig};
use frame_election_provider_support::{
data_provider, onchain, ElectionDataProvider, NposSolution, SequentialPhragmen,
data_provider,
onchain::{self, UnboundedExecution},
ElectionDataProvider, NposSolution, SequentialPhragmen,
};
pub use frame_support::{assert_noop, assert_ok, pallet_prelude::GetDefault};
use frame_support::{
Expand Down Expand Up @@ -379,7 +381,7 @@ impl crate::Config for Runtime {
type WeightInfo = ();
type BenchmarkingConfig = TestBenchmarkingConfig;
type Fallback = MockFallback;
type GovernanceFallback = NoFallback<Self>;
type GovernanceFallback = UnboundedExecution<OnChainSeqPhragmen>;
type ForceOrigin = frame_system::EnsureRoot<AccountId>;
type MaxElectingVoters = MaxElectingVoters;
type MaxElectableTargets = MaxElectableTargets;
Expand Down