Skip to content

EPMB: Improve Emergency and manage scenarios #10141

@kianenigma

Description

@kianenigma

See:

/// Manage this pallet.
///
/// The origin of this call must be [`Config::AdminOrigin`].
///
/// See [`AdminOperation`] for various operations that are possible.
#[pallet::weight(T::WeightInfo::manage())]
#[pallet::call_index(0)]
pub fn manage(origin: OriginFor<T>, op: AdminOperation<T>) -> DispatchResultWithPostInfo {
use crate::verifier::Verifier;
use sp_npos_elections::EvaluateSupport;
let _ = T::AdminOrigin::ensure_origin(origin);
match op {
AdminOperation::EmergencyFallback => {
ensure!(Self::current_phase() == Phase::Emergency, Error::<T>::UnexpectedPhase);
// note: for now we run this on the msp, but we can make it configurable if need
// be.
let voters = Snapshot::<T>::voters(Self::msp()).ok_or(Error::<T>::Snapshot)?;
let targets = Snapshot::<T>::targets().ok_or(Error::<T>::Snapshot)?;
let desired_targets =
Snapshot::<T>::desired_targets().ok_or(Error::<T>::Snapshot)?;
let fallback = T::Fallback::instant_elect(
voters.into_inner(),
targets.into_inner(),
desired_targets,
)
.map_err(|e| {
log!(warn, "Fallback failed: {:?}", e);
Error::<T>::Fallback
})?;
let score = fallback.evaluate();
T::Verifier::force_set_single_page_valid(fallback, 0, score);
Ok(().into())
},
AdminOperation::EmergencySetSolution(supports, score) => {
ensure!(Self::current_phase() == Phase::Emergency, Error::<T>::UnexpectedPhase);
// TODO: hardcoding zero here doesn't make a lot of sense
T::Verifier::force_set_single_page_valid(*supports, 0, score);
Ok(().into())
},
AdminOperation::ForceSetPhase(phase) => {
Self::phase_transition(phase);
Ok(().into())
},
AdminOperation::ForceRotateRound => {
Self::rotate_round();
Ok(().into())
},
AdminOperation::SetMinUntrustedScore(score) => {
T::Verifier::set_minimum_score(score);
Ok(().into())
},
}
}

Some initial code is here, but it is not very well thought out.

The main scenario that we should be able to support is:

  • Election is not succeeding for whatever reason.
  • Governance wants to set a manual solution, and make it go through.
  • They would have to:
    • ForceSetPhase(Emergency)
    • EmergencySetSolution for multiple pages (not possible now)
    • ForceSetPhase(Done) (signaling staking to be complete)
  • This scenario should be well tested.
  • If the rest of the scenarios remain, they should also be fully tested and their side effects understood. e.g. Fix origin check in EPMB's manage extrinsic #10248 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions