Struct pallet_election_provider_multi_phase::pallet::Pallet [−][src]
pub struct Pallet<T>(_);
Expand description
The pallet implementing the on-chain logic.
Implementations
Self
accessor for SignedSubmission<T>
.
Finish the signed phase. Process the signed submissions from best to worse until a valid one is found, rewarding the best one and slashing the invalid ones along the way.
Returns true if we have a good solution in the signed phase.
This drains the SignedSubmissions
, potentially storing the best valid one in
QueuedSolution
.
This is a self-weighing function, it automatically registers its weight internally when being called.
pub fn finalize_signed_phase_accept_solution(
ready_solution: ReadySolution<T::AccountId>,
who: &T::AccountId,
deposit: BalanceOf<T>,
reward: BalanceOf<T>
)
pub fn finalize_signed_phase_accept_solution(
ready_solution: ReadySolution<T::AccountId>,
who: &T::AccountId,
deposit: BalanceOf<T>,
reward: BalanceOf<T>
)
Helper function for the case where a solution is accepted in the signed phase.
Extracted to facilitate with weight calculation.
Infallible
Helper function for the case where a solution is accepted in the rejected phase.
Extracted to facilitate with weight calculation.
Infallible
pub fn feasibility_weight_of(
raw_solution: &RawSolution<SolutionOf<T>>,
size: SolutionOrSnapshotSize
) -> Weight
pub fn feasibility_weight_of(
raw_solution: &RawSolution<SolutionOf<T>>,
size: SolutionOrSnapshotSize
) -> Weight
The feasibility weight of the given raw solution.
pub fn deposit_for(
raw_solution: &RawSolution<SolutionOf<T>>,
size: SolutionOrSnapshotSize
) -> BalanceOf<T>
pub fn deposit_for(
raw_solution: &RawSolution<SolutionOf<T>>,
size: SolutionOrSnapshotSize
) -> BalanceOf<T>
Collect a sufficient deposit to store this solution.
The deposit is composed of 3 main elements:
- base deposit, fixed for all submissions.
- a per-byte deposit, for renting the state usage.
- a per-weight deposit, for the potential weight usage in an upcoming on_initialize
Attempt to restore a solution from cache. Otherwise, compute it fresh. Either way, submit if our call’s score is greater than that of the cached solution.
Mine a new solution, cache it, and submit it back to the chain as an unsigned transaction.
Mine a new solution as a call. Performs all checks.
pub fn basic_checks(
raw_solution: &RawSolution<SolutionOf<T>>,
solution_type: &str
) -> Result<(), MinerError<T>>
pub fn mine_and_check(
) -> Result<(RawSolution<SolutionOf<T>>, SolutionOrSnapshotSize), MinerError<T>>
pub fn mine_and_check(
) -> Result<(RawSolution<SolutionOf<T>>, SolutionOrSnapshotSize), MinerError<T>>
Mine a new npos solution, with all the relevant checks to make sure that it will be accepted to the chain.
If you want an unchecked solution, use Pallet::mine_solution
.
If you want a checked solution and submit it at the same time, use
Pallet::mine_check_save_submit
.
pub fn mine_solution<S>(
) -> Result<(RawSolution<SolutionOf<T>>, SolutionOrSnapshotSize), MinerError<T>> where
S: NposSolver<AccountId = T::AccountId, Error = SolverErrorOf<T>>,
pub fn mine_solution<S>(
) -> Result<(RawSolution<SolutionOf<T>>, SolutionOrSnapshotSize), MinerError<T>> where
S: NposSolver<AccountId = T::AccountId, Error = SolverErrorOf<T>>,
Mine a new npos solution.
The Npos Solver type, S
, must have the same AccountId and Error type as the
crate::Config::Solver
in order to create a unified return type.
pub fn prepare_election_result<Accuracy: PerThing128>(
election_result: ElectionResult<T::AccountId, Accuracy>
) -> Result<(RawSolution<SolutionOf<T>>, SolutionOrSnapshotSize), MinerError<T>>
pub fn prepare_election_result<Accuracy: PerThing128>(
election_result: ElectionResult<T::AccountId, Accuracy>
) -> Result<(RawSolution<SolutionOf<T>>, SolutionOrSnapshotSize), MinerError<T>>
Convert a raw solution from sp_npos_elections::ElectionResult
to RawSolution
, which
is ready to be submitted to the chain.
Will always reduce the solution as well.
pub fn trim_assignments_weight(
desired_targets: u32,
size: SolutionOrSnapshotSize,
max_weight: Weight,
assignments: &mut Vec<IndexAssignmentOf<T>>
)
pub fn trim_assignments_weight(
desired_targets: u32,
size: SolutionOrSnapshotSize,
max_weight: Weight,
assignments: &mut Vec<IndexAssignmentOf<T>>
)
Greedily reduce the size of the solution to fit into the block w.r.t. weight.
The weight of the solution is foremost a function of the number of voters (i.e.
assignments.len()
). Aside from this, the other components of the weight are invariant. The
number of winners shall not be changed (otherwise the solution is invalid) and the
ElectionSize
is merely a representation of the total number of stakers.
Thus, we reside to stripping away some voters from the assignments
.
Note that the solution is already computed, and the winners are elected based on the merit of the entire stake in the system. Nonetheless, some of the voters will be removed further down the line.
Indeed, the score must be computed after this step. If this step reduces the score too much or remove a winner, then the solution must be discarded after this step.
pub fn trim_assignments_length(
max_allowed_length: u32,
assignments: &mut Vec<IndexAssignmentOf<T>>,
encoded_size_of: impl Fn(&[IndexAssignmentOf<T>]) -> Result<usize, Error>
) -> Result<(), MinerError<T>>
pub fn trim_assignments_length(
max_allowed_length: u32,
assignments: &mut Vec<IndexAssignmentOf<T>>,
encoded_size_of: impl Fn(&[IndexAssignmentOf<T>]) -> Result<usize, Error>
) -> Result<(), MinerError<T>>
Greedily reduce the size of the solution to fit into the block w.r.t length.
The length of the solution is largely a function of the number of voters. The number of winners cannot be changed. Thus, to reduce the solution size, we need to strip voters.
Note that this solution is already computed, and winners are elected based on the merit of the total stake in the system. Nevertheless, some of the voters may be removed here.
Sometimes, removing a voter can cause a validator to also be implicitly removed, if that voter was the only backer of that winner. In such cases, this solution is invalid, which will be caught prior to submission.
The score must be computed after this step. If this step reduces the score too much, then the solution must be discarded.
pub fn maximum_voter_for_weight<W: WeightInfo>(
desired_winners: u32,
size: SolutionOrSnapshotSize,
max_weight: Weight
) -> u32
pub fn maximum_voter_for_weight<W: WeightInfo>(
desired_winners: u32,
size: SolutionOrSnapshotSize,
max_weight: Weight
) -> u32
Find the maximum len
that a solution can have in order to fit into the block weight.
This only returns a value between zero and size.nominators
.
Checks if an execution of the offchain worker is permitted at the given block number, or not.
This makes sure that
- we don’t run on previous blocks in case of a re-org
- we don’t run twice within a window of length
T::OffchainRepeat
.
Returns Ok(())
if offchain worker limit is respected, Err(reason)
otherwise. If Ok()
is returned, now
is written in storage and will be used in further calls as the baseline.
pub fn unsigned_pre_dispatch_checks(
raw_solution: &RawSolution<SolutionOf<T>>
) -> DispatchResult
pub fn unsigned_pre_dispatch_checks(
raw_solution: &RawSolution<SolutionOf<T>>
) -> DispatchResult
Do the basics checks that MUST happen during the validation and pre-dispatch of an unsigned transaction.
Can optionally also be called during dispatch, if needed.
NOTE: Ideally, these tests should move more and more outside of this and more to the miner’s code, so that we do less and less storage reads here.
pub fn submit_unsigned(
origin: OriginFor<T>,
raw_solution: Box<RawSolution<SolutionOf<T>>>,
witness: SolutionOrSnapshotSize
) -> DispatchResultWithPostInfo
pub fn submit_unsigned(
origin: OriginFor<T>,
raw_solution: Box<RawSolution<SolutionOf<T>>>,
witness: SolutionOrSnapshotSize
) -> DispatchResultWithPostInfo
Submit a solution for the unsigned phase.
The dispatch origin fo this call must be none.
This submission is checked on the fly. Moreover, this unsigned solution is only validated when submitted to the pool from the local node. Effectively, this means that only active validators can submit this transaction when authoring a block (similar to an inherent).
To prevent any incorrect solution (and thus wasted time/weight), this transaction will panic if the solution submitted by the validator is invalid in any way, effectively putting their authoring reward at risk.
No deposit or reward is associated with this submission.
pub fn set_minimum_untrusted_score(
origin: OriginFor<T>,
maybe_next_score: Option<ElectionScore>
) -> DispatchResult
pub fn set_minimum_untrusted_score(
origin: OriginFor<T>,
maybe_next_score: Option<ElectionScore>
) -> DispatchResult
Set a new value for MinimumUntrustedScore
.
Dispatch origin must be aligned with T::ForceOrigin
.
This check can be turned off by setting the value to None
.
pub fn set_emergency_election_result(
origin: OriginFor<T>,
supports: Supports<T::AccountId>
) -> DispatchResult
pub fn set_emergency_election_result(
origin: OriginFor<T>,
supports: Supports<T::AccountId>
) -> DispatchResult
Set a solution in the queue, to be handed out to the client of this pallet in the next
call to ElectionProvider::elect
.
This can only be set by T::ForceOrigin
, and only when the phase is Emergency
.
The solution is not checked for any feasibility and is assumed to be trustworthy, as any feasibility check itself can in principle cause the election process to fail (due to memory/weight constrains).
pub fn submit(
origin: OriginFor<T>,
raw_solution: Box<RawSolution<SolutionOf<T>>>,
num_signed_submissions: u32
) -> DispatchResult
pub fn submit(
origin: OriginFor<T>,
raw_solution: Box<RawSolution<SolutionOf<T>>>,
num_signed_submissions: u32
) -> DispatchResult
Submit a solution for the signed phase.
The dispatch origin fo this call must be signed.
The solution is potentially queued, based on the claimed score and processed at the end of the signed phase.
A deposit is reserved and recorded for the solution. Based on the outcome, the solution might be rewarded, slashed, or get all or a part of the deposit back.
Queue size must be provided as witness data.
Current phase.
Current best solution, signed or unsigned, queued to be returned upon elect
.
Snapshot data of the round.
This is created at the beginning of the signed phase and cleared upon calling elect
.
Desired number of targets to elect for this round.
Only exists when Snapshot
is present.
The metadata of the RoundSnapshot
Only exists when Snapshot
is present.
The minimum score that each ‘untrusted’ solution must attain in order to be considered feasible.
Can be set via set_minimum_untrusted_score
.
Logic for <Pallet as Hooks>::on_initialize
when signed phase is being opened.
Logic for <Pallet as Hooks<T>>::on_initialize
when unsigned phase is being opened.
Creates the snapshot. Writes new data to:
Returns Ok(())
if operation is okay.
This is a self-weighing function, it will register its own extra weight as
DispatchClass::Mandatory
with the system pallet.
Kill everything created by Pallet::create_snapshot
.
pub fn feasibility_check(
raw_solution: RawSolution<SolutionOf<T>>,
compute: ElectionCompute
) -> Result<ReadySolution<T::AccountId>, FeasibilityError>
pub fn feasibility_check(
raw_solution: RawSolution<SolutionOf<T>>,
compute: ElectionCompute
) -> Result<ReadySolution<T::AccountId>, FeasibilityError>
Checks the feasibility of a solution.
Trait Implementations
Get the benchmarks available for this pallet. Generally there is one benchmark per extrinsic, so these are sometimes just called “extrinsics”. Read more
fn run_benchmark(
extrinsic: &[u8],
c: &[(BenchmarkParameter, u32)],
whitelist: &[TrackedStorageKey],
verify: bool,
internal_repeats: u32
) -> Result<Vec<BenchmarkResult>, BenchmarkError>
fn run_benchmark(
extrinsic: &[u8],
c: &[(BenchmarkParameter, u32)],
whitelist: &[TrackedStorageKey],
verify: bool,
internal_repeats: u32
) -> Result<Vec<BenchmarkResult>, BenchmarkError>
Run the benchmarks for this pallet.
impl<T: Config> ElectionProvider<<T as Config>::AccountId, <T as Config>::BlockNumber> for Pallet<T>
impl<T: Config> ElectionProvider<<T as Config>::AccountId, <T as Config>::BlockNumber> for Pallet<T>
type Error = ElectionError<T>
type Error = ElectionError<T>
The error type that is returned by the provider.
type DataProvider = T::DataProvider
type DataProvider = T::DataProvider
The data provider of the election.
Returns the current storage version as supported by the pallet.
Returns the on-chain storage version of the pallet as stored in the storage.
The block is being initialized. Implement to have something happen. Read more
Implementing this function on a module allows you to perform long-running tasks that make (by default) validators generate transactions that feed results of those long-running computations back on chain. Read more
Run integrity test. Read more
The block is being finalized. Implement to have something happen.
This will be run when the block is being finalized (before on_finalize
).
Implement to have something happen using the remaining weight.
Will not fire if the remaining weight is 0.
Return the weight used, the hook will subtract it from current weight used
and pass the result to the next on_idle
hook if it exists. Read more
Perform a module upgrade. Read more
Run integrity test. Read more
This function is being called after every block import (when fully synced). Read more
The block is being finalized. Implement to have something happen. Read more
Something that should happen at genesis.
The block is being finalized.
Implement to have something happen in case there is leftover weight.
Check the passed remaining_weight
to make sure it is high enough to allow for
your pallet’s extra computation. Read more
The block is being initialized. Implement to have something happen. Read more
Perform a module upgrade. Read more
Name of the Rust module containing the pallet.
Version of the crate containing the pallet.
Extend the given vector by all of the pallets’ information that this type represents. Read more
All of the pallets’ information that this type represents.
Auto Trait Implementations
impl<T> RefUnwindSafe for Pallet<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Pallet<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
Compare self to key
and return true
if they are equal.
Causes self
to use its Binary
implementation when Debug
-formatted.
Causes self
to use its Display
implementation when
Debug
-formatted. Read more
Causes self
to use its LowerExp
implementation when
Debug
-formatted. Read more
Causes self
to use its LowerHex
implementation when
Debug
-formatted. Read more
Causes self
to use its Octal
implementation when Debug
-formatted.
Causes self
to use its Pointer
implementation when
Debug
-formatted. Read more
Causes self
to use its UpperExp
implementation when
Debug
-formatted. Read more
Causes self
to use its UpperHex
implementation when
Debug
-formatted. Read more
impl<T> PalletVersionToStorageVersionHelper for T where
T: GetStorageVersion + PalletInfoAccess,
impl<T> PalletVersionToStorageVersionHelper for T where
T: GetStorageVersion + PalletInfoAccess,
Pipes by value. This is generally the method you want to use. Read more
Borrows self
and passes that borrow into the pipe function. Read more
Mutably borrows self
and passes that borrow into the pipe function. Read more
Borrows self
, then passes self.borrow()
into the pipe function. Read more
Mutably borrows self
, then passes self.borrow_mut()
into the pipe
function. Read more
Borrows self
, then passes self.as_ref()
into the pipe function.
Mutably borrows self
, then passes self.as_mut()
into the pipe
function. Read more
Borrows self
, then passes self.deref()
into the pipe function.
fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: AsRef<T>,
T: 'a,
R: 'a,
fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: AsRef<T>,
T: 'a,
R: 'a,
Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Borrow<T>,
T: 'a,
R: 'a,
fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Borrow<T>,
T: 'a,
R: 'a,
Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R where
Self: Deref,
R: 'a,
fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R where
Self: Deref,
R: 'a,
Pipes a dereference into a function that cannot normally be called in suffix position. Read more
Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
Checks if self
is actually part of its subset T
(and can be converted to it).
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
The inclusion map: converts self
to the equivalent element of its superset.
Immutable access to the Borrow<B>
of a value. Read more
Mutable access to the BorrowMut<B>
of a value. Read more
Immutable access to the AsRef<R>
view of a value. Read more
Mutable access to the AsMut<R>
view of a value. Read more
Immutable access to the Deref::Target
of a value. Read more
Mutable access to the Deref::Target
of a value. Read more
Calls .tap()
only in debug builds, and is erased in release builds.
Calls .tap_mut()
only in debug builds, and is erased in release
builds. Read more
Calls .tap_borrow()
only in debug builds, and is erased in release
builds. Read more
Calls .tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more
Calls .tap_ref()
only in debug builds, and is erased in release
builds. Read more
Calls .tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more
Calls .tap_deref()
only in debug builds, and is erased in release
builds. Read more
Provides immutable access to the reference for inspection.
Calls tap_ref
in debug builds, and does nothing in release builds.
Provides mutable access to the reference for modification.
Calls tap_ref_mut
in debug builds, and does nothing in release builds.
Provides immutable access to the borrow for inspection. Read more
Calls tap_borrow
in debug builds, and does nothing in release builds.
fn tap_borrow_mut<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_borrow_mut<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
Provides mutable access to the borrow for modification.
Immutably dereferences self
for inspection.
fn tap_deref_dbg<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
fn tap_deref_dbg<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
Calls tap_deref
in debug builds, and does nothing in release builds.
fn tap_deref_mut<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
fn tap_deref_mut<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
Mutably dereferences self
for modification.
The counterpart to unchecked_from
.
Consume self to return an equivalent value of T
.
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more