Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

submit emergency solution #11703

Closed
wants to merge 27 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5771803
submit emergency solution
Szegoo Jun 18, 2022
d3c0705
tests & configurable punishment
Szegoo Jun 21, 2022
54746ca
fix
Szegoo Jun 21, 2022
72f6d4d
better naming
Szegoo Jun 22, 2022
345e1a4
documentation
Szegoo Jun 22, 2022
704d73b
Merge branch 'paritytech:master' into submit-emergency-solution
Szegoo Jun 25, 2022
e7a2afb
Merge branch 'paritytech:master' into submit-emergency-solution
Szegoo Jun 30, 2022
9b2ef3b
Update frame/election-provider-multi-phase/src/lib.rs
Szegoo Jun 30, 2022
9946a3f
renaming
Szegoo Jun 30, 2022
3ce6710
Update frame/election-provider-multi-phase/src/lib.rs
kianenigma Jun 30, 2022
c51a51d
Update frame/election-provider-multi-phase/src/lib.rs
kianenigma Jun 30, 2022
28a93a6
fix
Szegoo Jun 30, 2022
340c65b
fmt
Szegoo Jun 30, 2022
3f125fd
test for events
Szegoo Jun 30, 2022
a176c1c
line wrapping fix
Szegoo Jun 30, 2022
8a29e94
Merge branch 'paritytech:master' into submit-emergency-solution
Szegoo Jun 30, 2022
32cf700
Merge branch 'paritytech:master' into submit-emergency-solution
Szegoo Jul 5, 2022
405dd34
Merge branch 'paritytech:master' into submit-emergency-solution
Szegoo Jul 15, 2022
1c38c68
fix inaccurate weight
Szegoo Jul 20, 2022
0c1932f
fix inaccurate weight
Szegoo Jul 20, 2022
d801649
fix inaccurate weight
Szegoo Jul 20, 2022
87f55d0
Merge branch 'paritytech:master' into submit-emergency-solution
Szegoo Jul 20, 2022
48c72de
Update frame/election-provider-multi-phase/src/lib.rs
Szegoo Jul 23, 2022
8dbc1ad
use solution_weight
Szegoo Jul 23, 2022
71fd834
use solution_weight
Szegoo Jul 23, 2022
6a362f5
fix
Szegoo Jul 23, 2022
c12cfa9
Merge branch 'paritytech:master' into submit-emergency-solution
Szegoo Jul 23, 2022
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
53 changes: 51 additions & 2 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
//!
//! ## Error types
//!
//! This pallet provides a verbose error system to ease future debugging and debugging. The overall
//! This pallet provides a verbose error system to ease future debugging. The overall
//! hierarchy of errors is as follows:
//!
//! 1. [`pallet::Error`]: These are the errors that can be returned in the dispatchables of the
Expand Down Expand Up @@ -957,9 +957,58 @@ pub mod pallet {
Ok(())
}

/// Submit a signed solution during the emergency phase.
/// It will go through the `feasibility_check` right away.
///
/// The dispatch origin for this call must be __signed__.
///
/// The deposit that is reserved might be rewarded or slashed based on
Szegoo marked this conversation as resolved.
Show resolved Hide resolved
/// the outcome.
#[pallet::weight(T::DbWeight::get().reads_writes(1, 1))]
pub fn submit_emergency_solution(
Szegoo marked this conversation as resolved.
Show resolved Hide resolved
origin: OriginFor<T>,
raw_solution: Box<RawSolution<SolutionOf<T::MinerConfig>>>,
) -> DispatchResult {
let who = ensure_signed(origin)?;

ensure!(Self::current_phase().is_emergency(), <Error<T>>::CallNotAllowed);

let size = Self::snapshot_metadata().ok_or(Error::<T>::MissingSnapshotMetadata)?;
kianenigma marked this conversation as resolved.
Show resolved Hide resolved

ensure!(
Self::solution_weight_of(&raw_solution, size) < T::SignedMaxWeight::get(),
Error::<T>::SignedTooMuchWeight
);

let deposit = Self::deposit_for(&raw_solution, size);

kianenigma marked this conversation as resolved.
Show resolved Hide resolved
T::Currency::reserve(&who, deposit).map_err(|_| Error::<T>::SignedCannotPayDeposit)?;

let call_fee = {
let call = Call::submit { raw_solution: raw_solution.clone() };
T::EstimateCallFee::estimate_call_fee(&call, None.into())
};

match Self::feasibility_check(*raw_solution.clone(), ElectionCompute::Signed) {
Szegoo marked this conversation as resolved.
Show resolved Hide resolved
Ok(ready_solution) => {
Self::finalize_signed_phase_accept_solution(
ready_solution,
&who,
deposit,
call_fee,
);
},
Err(_) => {
Self::finalize_signed_phase_reject_solution(&who, deposit);
},
}

Ok(())
}

/// Submit a solution for the signed phase.
///
/// The dispatch origin fo this call must be __signed__.
/// The dispatch origin for this call must be __signed__.
///
/// The solution is potentially queued, based on the claimed score and processed at the end
/// of the signed phase.
Expand Down