pub struct Pallet<T>(_);
Expand description

The Pallet struct, the main type that implements traits and standalone functions within the pallet.

Implementations§

source§

impl<T: Config> Pallet<T>

source

pub fn signed_submissions() -> SignedSubmissions<T>

Self accessor for SignedSubmission<T>.

source

pub fn finalize_signed_phase() -> bool

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.

source

pub fn finalize_signed_phase_accept_solution( ready_solution: ReadySolution<T::AccountId, T::MaxWinners>, who: &T::AccountId, deposit: BalanceOf<T>, call_fee: BalanceOf<T> )

Helper function for the case where a solution is accepted in the signed phase.

Extracted to facilitate with weight calculation.

Infallible

source

pub fn finalize_signed_phase_reject_solution( who: &T::AccountId, deposit: BalanceOf<T> )

Helper function for the case where a solution is accepted in the rejected phase.

Extracted to facilitate with weight calculation.

Infallible

source

pub fn solution_weight_of( raw_solution: &RawSolution<SolutionOf<T::MinerConfig>>, size: SolutionOrSnapshotSize ) -> Weight

The weight of the given raw solution.

source

pub fn deposit_for( raw_solution: &RawSolution<SolutionOf<T::MinerConfig>>, size: SolutionOrSnapshotSize ) -> BalanceOf<T>

Collect a sufficient deposit to store this solution.

The deposit is composed of 3 main elements:

  1. base deposit, fixed for all submissions.
  2. a per-byte deposit, for renting the state usage.
  3. a per-weight deposit, for the potential weight usage in an upcoming on_initialize
source§

impl<T: Config> Pallet<T>

source

pub fn mine_solution( ) -> Result<(RawSolution<SolutionOf<T::MinerConfig>>, SolutionOrSnapshotSize), MinerError>

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.

source

pub fn restore_or_compute_then_maybe_submit() -> Result<(), MinerError>

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.

source

pub fn mine_check_save_submit() -> Result<(), MinerError>

Mine a new solution, cache it, and submit it back to the chain as an unsigned transaction.

source

pub fn mine_checked_call() -> Result<Call<T>, MinerError>

Mine a new solution as a call. Performs all checks.

source

pub fn basic_checks( raw_solution: &RawSolution<SolutionOf<T::MinerConfig>>, solution_type: &str ) -> Result<(), MinerError>

source

pub fn mine_and_check( ) -> Result<(RawSolution<SolutionOf<T::MinerConfig>>, SolutionOrSnapshotSize), MinerError>

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.

source

pub fn ensure_offchain_repeat_frequency( now: BlockNumberFor<T> ) -> Result<(), MinerError>

Checks if an execution of the offchain worker is permitted at the given block number, or not.

This makes sure that

  1. we don’t run on previous blocks in case of a re-org
  2. 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.

source

pub fn unsigned_pre_dispatch_checks( raw_solution: &RawSolution<SolutionOf<T::MinerConfig>> ) -> 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.

source§

impl<T: Config> Pallet<T>

source

pub fn submit_unsigned( origin: OriginFor<T>, raw_solution: Box<RawSolution<SolutionOf<T::MinerConfig>>>, witness: SolutionOrSnapshotSize ) -> DispatchResult

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.

source

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.

source

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).

source

pub fn submit( origin: OriginFor<T>, raw_solution: Box<RawSolution<SolutionOf<T::MinerConfig>>> ) -> 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.

source

pub fn governance_fallback( origin: OriginFor<T>, maybe_max_voters: Option<u32>, maybe_max_targets: Option<u32> ) -> DispatchResult

Trigger the governance fallback.

This can only be called when Phase::Emergency is enabled, as an alternative to calling Call::set_emergency_election_result.

source§

impl<T: Config> Pallet<T>

source

pub fn round() -> u32

An auto-generated getter for Round.

source§

impl<T: Config> Pallet<T>

source

pub fn current_phase() -> Phase<BlockNumberFor<T>>

An auto-generated getter for CurrentPhase.

source§

impl<T: Config> Pallet<T>

source

pub fn queued_solution() -> Option<ReadySolution<T::AccountId, T::MaxWinners>>

An auto-generated getter for QueuedSolution.

source§

impl<T: Config> Pallet<T>

source

pub fn snapshot() -> Option<RoundSnapshot<T::AccountId, VoterOf<T>>>

An auto-generated getter for Snapshot.

source§

impl<T: Config> Pallet<T>

source

pub fn desired_targets() -> Option<u32>

An auto-generated getter for DesiredTargets.

source§

impl<T: Config> Pallet<T>

source

pub fn snapshot_metadata() -> Option<SolutionOrSnapshotSize>

An auto-generated getter for SnapshotMetadata.

source§

impl<T: Config> Pallet<T>

source

pub fn minimum_untrusted_score() -> Option<ElectionScore>

An auto-generated getter for MinimumUntrustedScore.

source§

impl<T: Config> Pallet<T>

source

pub fn create_snapshot() -> Result<(), ElectionError<T>>

Creates the snapshot. Writes new data to:

  1. SnapshotMetadata
  2. RoundSnapshot
  3. DesiredTargets

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.

source

pub fn kill_snapshot()

Kill everything created by Pallet::create_snapshot.

source

pub fn feasibility_check( raw_solution: RawSolution<SolutionOf<T::MinerConfig>>, compute: ElectionCompute ) -> Result<ReadySolution<T::AccountId, T::MaxWinners>, FeasibilityError>

Checks the feasibility of a solution.

Trait Implementations§

source§

impl<T> Benchmarking for Pallet<T>where T: Config + Config,

source§

fn benchmarks(extra: bool) -> Vec<BenchmarkMetadata>

Get the benchmarks available for this pallet. Generally there is one benchmark per extrinsic, so these are sometimes just called “extrinsics”. Read more
source§

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.
source§

impl<T: Config> Callable<T> for Pallet<T>

source§

impl<T> Clone for Pallet<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> Debug for Pallet<T>

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Config> ElectionProvider for Pallet<T>

source§

fn ongoing() -> bool

Indicate if this election provider is currently ongoing an asynchronous election or not.
source§

fn elect() -> Result<BoundedSupportsOf<Self>, Self::Error>

Performs the election. This should be implemented as a self-weighing function. The implementor should register its appropriate weight at the end of execution with the system pallet directly.
source§

impl<T: Config> ElectionProviderBase for Pallet<T>

§

type AccountId = <T as Config>::AccountId

The account identifier type.
§

type BlockNumber = <<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number

The block number type.
§

type Error = ElectionError<T>

The error type that is returned by the provider.
§

type MaxWinners = <T as Config>::MaxWinners

The upper bound on election winners that can be returned. Read more
§

type DataProvider = <T as Config>::DataProvider

The data provider of the election.
§

fn desired_targets_checked() -> Result<u32, &'static str>

checked call to Self::DataProvider::desired_targets() ensuring the value never exceeds [Self::MaxWinners].
source§

impl<T: Config> GetStorageVersion for Pallet<T>

§

type CurrentStorageVersion = StorageVersion

This will be filled out by the pallet macro. Read more
source§

fn current_storage_version() -> Self::CurrentStorageVersion

Returns the current storage version as supported by the pallet.
source§

fn on_chain_storage_version() -> StorageVersion

Returns the on-chain storage version of the pallet as stored in the storage.
source§

impl<T: Config> Hooks<<<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for Pallet<T>

source§

fn on_initialize(now: BlockNumberFor<T>) -> Weight

Block initialization hook. This is called at the very beginning of block execution. Read more
source§

fn offchain_worker(now: BlockNumberFor<T>)

Implementing this function on a pallet allows you to perform long-running tasks that are dispatched as separate threads, and entirely independent of the main wasm runtime. Read more
source§

fn integrity_test()

Check the integrity of this pallet’s configuration. Read more
source§

fn try_state(_n: BlockNumberFor<T>) -> Result<(), TryRuntimeError>

Execute the sanity checks of this pallet, per block. Read more
source§

fn on_finalize(_n: BlockNumber)

Block finalization hook. This is called at the very end of block execution. Read more
source§

fn on_idle(_n: BlockNumber, _remaining_weight: Weight) -> Weight

Hook to consume a block’s idle time. This will run when the block is being finalized (before Hooks::on_finalize). Read more
source§

fn on_runtime_upgrade() -> Weight

Hook executed when a code change (aka. a “runtime upgrade”) is detected by FRAME. Read more
source§

fn pre_upgrade() -> Result<Vec<u8, Global>, DispatchError>

Execute some pre-checks prior to a runtime upgrade. Read more
source§

fn post_upgrade(_state: Vec<u8, Global>) -> Result<(), DispatchError>

Execute some post-checks after a runtime upgrade. Read more
source§

impl<T: Config> IntegrityTest for Pallet<T>

source§

impl<T: Config> OffchainWorker<<<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for Pallet<T>

source§

fn offchain_worker(n: BlockNumberFor<T>)

This function is being called after every block import (when fully synced). Read more
source§

impl<T: Config> OnFinalize<<<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for Pallet<T>

source§

impl<T: Config> OnGenesis for Pallet<T>

source§

fn on_genesis()

Something that should happen at genesis.
source§

impl<T: Config> OnIdle<<<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for Pallet<T>

source§

fn on_idle(n: BlockNumberFor<T>, remaining_weight: Weight) -> Weight

source§

impl<T: Config> OnInitialize<<<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for Pallet<T>

source§

impl<T: Config> OnRuntimeUpgrade for Pallet<T>

source§

fn on_runtime_upgrade() -> Weight

source§

fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError>

source§

fn post_upgrade(state: Vec<u8>) -> Result<(), TryRuntimeError>

source§

fn try_on_runtime_upgrade(checks: bool) -> Result<Weight, DispatchError>

The expected and default behavior of this method is to handle executing pre_upgrade -> on_runtime_upgrade -> post_upgrade hooks for a migration. Read more
source§

impl<T: Config> PalletInfoAccess for Pallet<T>

source§

fn index() -> usize

Index of the pallet as configured in the runtime.
source§

fn name() -> &'static str

Name of the pallet as configured in the runtime.
source§

fn module_name() -> &'static str

Name of the Rust module containing the pallet.
source§

fn crate_version() -> CrateVersion

Version of the crate containing the pallet.
source§

impl<T: Config> PalletsInfoAccess for Pallet<T>

source§

fn count() -> usize

The number of pallets’ information that this type represents. Read more
source§

fn infos() -> Vec<PalletInfoData>

All of the pallets’ information that this type represents.
source§

impl<T> PartialEq<Pallet<T>> for Pallet<T>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Config> StorageInfoTrait for Pallet<T>

source§

impl<T: Config> TryState<<<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for Pallet<T>

source§

fn try_state( n: BlockNumberFor<T>, _s: TryStateSelect ) -> Result<(), TryRuntimeError>

Execute the state checks.
source§

impl<T: Config> ValidateUnsigned for Pallet<T>

§

type Call = Call<T>

The call to validate
source§

fn validate_unsigned( source: TransactionSource, call: &Self::Call ) -> TransactionValidity

Return the validity of the call Read more
source§

fn pre_dispatch(call: &Self::Call) -> Result<(), TransactionValidityError>

Validate the call right before dispatch. Read more
source§

impl<T: Config> WhitelistedStorageKeys for Pallet<T>

source§

fn whitelisted_storage_keys() -> Vec<TrackedStorageKey>

Returns a Vec<TrackedStorageKey> indicating the storage keys that should be whitelisted during benchmarking. This means that those keys will be excluded from the benchmarking performance calculation.
source§

impl<T> Eq for Pallet<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Pallet<T>where T: RefUnwindSafe,

§

impl<T> Send for Pallet<T>where T: Send,

§

impl<T> Sync for Pallet<T>where T: Sync,

§

impl<T> Unpin for Pallet<T>where T: Unpin,

§

impl<T> UnwindSafe for Pallet<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CheckedConversion for T

source§

fn checked_from<T>(t: T) -> Option<Self>where Self: TryFrom<T>,

Convert from a value of T into an equivalent instance of Option<Self>. Read more
source§

fn checked_into<T>(self) -> Option<T>where Self: TryInto<T>,

Consume self to return Some equivalent value of Option<T>. Read more
source§

impl<T> DynClone for Twhere T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IsType<T> for T

source§

fn from_ref(t: &T) -> &T

Cast reference.
source§

fn into_ref(&self) -> &T

Cast reference.
source§

fn from_mut(t: &mut T) -> &mut T

Cast mutable reference.
source§

fn into_mut(&mut self) -> &mut T

Cast mutable reference.
source§

impl<T, Outer> IsWrappedBy<Outer> for Twhere Outer: AsRef<T> + AsMut<T> + From<T>, T: From<Outer>,

source§

fn from_ref(outer: &Outer) -> &T

Get a reference to the inner from the outer.

source§

fn from_mut(outer: &mut Outer) -> &mut T

Get a mutable reference to the inner from the outer.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatedConversion for T

source§

fn saturated_from<T>(t: T) -> Selfwhere Self: UniqueSaturatedFrom<T>,

Convert from a value of T into an equivalent instance of Self. Read more
source§

fn saturated_into<T>(self) -> Twhere Self: UniqueSaturatedInto<T>,

Consume self to return an equivalent value of T. Read more
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<S, T> UncheckedInto<T> for Swhere T: UncheckedFrom<S>,

source§

fn unchecked_into(self) -> T

The counterpart to unchecked_from.
source§

impl<T, S> UniqueSaturatedInto<T> for Swhere T: Bounded, S: TryInto<T>,

source§

fn unique_saturated_into(self) -> T

Consume self to return an equivalent value of T.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> JsonSchemaMaybe for T

§

impl<T> MaybeDebug for Twhere T: Debug,

source§

impl<T> MaybeRefUnwindSafe for Twhere T: RefUnwindSafe,

source§

impl<T> Member for Twhere T: Send + Sync + Debug + Eq + PartialEq<T> + Clone + 'static,

source§

impl<T> Scalar for Twhere T: 'static + Clone + PartialEq<T> + Debug,