Type Alias parachain_staking::pallet::Module

source ·
pub type Module<T> = Pallet<T>;
👎Deprecated: use Pallet instead
Expand description

Type alias to Pallet, to be used by construct_runtime.

Generated by pallet attribute macro.

Aliased Type§

struct Module<T>(/* private fields */);

Implementations§

source§

impl<T: Config> Pallet<T>

source

pub fn get_unclaimed_staking_rewards( acc: &T::AccountId ) -> <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance

Calculates the staking rewards for a given account address.

Subtracts the number of rewarded blocks from the number of authored blocks by the collator and multiplies that with the current stake as well as reward rate.

At least used in Runtime API.

source

pub fn get_staking_rates() -> StakingRates

Calculates the current staking and reward rates for collators and delegators.

At least used in Runtime API.

source§

impl<T: Config> Pallet<T>

source

pub fn force_new_round(origin: OriginFor<T>) -> DispatchResult

Forces the start of the new round in the next block.

The new round will be enforced via <T as ShouldEndSession<_>>::should_end_session.

The dispatch origin must be Root.

source

pub fn set_inflation( origin: OriginFor<T>, collator_max_rate_percentage: Perquintill, collator_annual_reward_rate_percentage: Perquintill, delegator_max_rate_percentage: Perquintill, delegator_annual_reward_rate_percentage: Perquintill ) -> DispatchResultWithPostInfo

Set the annual inflation rate to derive per-round inflation.

The inflation details are considered valid if the annual reward rate is approximately the per-block reward rate multiplied by the estimated* total number of blocks per year.

The estimated average block time is twelve seconds.

NOTE: Iterates over CandidatePool and for each candidate over their delegators to update their rewards before the reward rates change. Needs to be improved when scaling up MaxTopCandidates.

The dispatch origin must be Root.

Emits RoundInflationSet.

source

pub fn set_max_selected_candidates( origin: OriginFor<T>, new: u32 ) -> DispatchResultWithPostInfo

Set the maximum number of collator candidates that can be selected at the beginning of each validation round.

Changes are not applied until the start of the next round.

The new value must be higher than the minimum allowed as set in the pallet’s configuration.

The dispatch origin must be Root.

Emits MaxSelectedCandidatesSet.

source

pub fn set_blocks_per_round( origin: OriginFor<T>, new: BlockNumberFor<T> ) -> DispatchResult

Set the number of blocks each validation round lasts.

If the new value is less than the length of the current round, the system will immediately move to the next round in the next block.

The new value must be higher than the minimum allowed as set in the pallet’s configuration.

The dispatch origin must be Root.

Emits BlocksPerRoundSet.

source

pub fn set_max_candidate_stake( origin: OriginFor<T>, new: <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance ) -> DispatchResult

Set the maximal amount a collator can stake. Existing stakes are not changed.

The dispatch origin must be Root.

Emits MaxCandidateStakeChanged.

source

pub fn force_remove_candidate( origin: OriginFor<T>, collator: <T::Lookup as StaticLookup>::Source ) -> DispatchResultWithPostInfo

Forcedly removes a collator candidate from the TopCandidates and clears all associated storage for the candidate and their delegators.

Prepares unstaking of the candidates and their delegators stake which can be unfreezed via unlock_unstaked after waiting at least StakeDuration many blocks. Also increments rewards for the collator and their delegators.

Increments rewards of candidate and their delegators.

Emits CandidateRemoved.

source

pub fn join_candidates( origin: OriginFor<T>, stake: <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance ) -> DispatchResultWithPostInfo

Join the set of collator candidates.

In the next blocks, if the collator candidate has enough funds staked to be included in any of the top MaxSelectedCandidates positions, it will be included in the set of potential authors that will be selected by the stake-weighted random selection function.

The staked funds of the new collator candidate are added to the total stake of the system.

The total amount of funds staked must be within the allowed range as set in the pallet’s configuration.

The dispatch origin must not be already part of the collator candidates nor of the delegators set.

Emits JoinedCollatorCandidates.

source

pub fn init_leave_candidates(origin: OriginFor<T>) -> DispatchResultWithPostInfo

Request to leave the set of collator candidates.

On success, the account is immediately removed from the candidate pool to prevent selection as a collator in future validation rounds, but unstaking of the funds is executed with a delay of StakeDuration blocks.

The exit request can be reversed by calling cancel_leave_candidates.

This operation affects the pallet’s total stake amount. It is updated even though the funds of the candidate who signaled to leave are still locked for ExitDelay + StakeDuration more blocks.

NOTE 1: Upon starting a new session_i in new_session, the current top candidates are selected to be block authors for session_i+1. Any changes to the top candidates afterwards do not effect the set of authors for session_i+1. Thus, we have to make sure none of these collators can leave before session_i+1 ends by delaying their exit for ExitDelay many blocks.

NOTE 2: We do not increment rewards in this extrinsic as the candidate could still author blocks, and thus be eligible to receive rewards, until the end of the next session.

Emits CollatorScheduledExit.

source

pub fn execute_leave_candidates( origin: OriginFor<T>, collator: <T::Lookup as StaticLookup>::Source ) -> DispatchResultWithPostInfo

Execute the network exit of a candidate who requested to leave at least ExitQueueDelay rounds ago. Prepares unstaking of the candidates and their delegators stake which can be unfreezed via unlock_unstaked after waiting at least StakeDuration many blocks.

Requires the candidate to previously have called init_leave_candidates.

The exit request can be reversed by calling cancel_leave_candidates.

NOTE: Iterates over CandidatePool for each candidate over their delegators to set rewards. Needs to be improved when scaling up MaxTopCandidates.

Emits CollatorLeft.

source

pub fn cancel_leave_candidates( origin: OriginFor<T> ) -> DispatchResultWithPostInfo

Revert the previously requested exit of the network of a collator candidate. On success, adds back the candidate to the TopCandidates and updates the collators.

Requires the candidate to previously have called init_leave_candidates.

Emits CollatorCanceledExit.

source

pub fn candidate_stake_more( origin: OriginFor<T>, more: <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance ) -> DispatchResultWithPostInfo

Stake more funds for a collator candidate.

If not in the set of candidates, staking enough funds allows the account to be added to it. The larger amount of funds, the higher chances to be selected as the author of the next block.

This operation affects the pallet’s total stake amount.

The resulting total amount of funds staked must be within the allowed range as set in the pallet’s configuration.

Emits CollatorStakedMore.

source

pub fn candidate_stake_less( origin: OriginFor<T>, less: <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance ) -> DispatchResultWithPostInfo

Stake less funds for a collator candidate.

If the new amount of staked fund is not large enough, the account could be removed from the set of collator candidates and not be considered for authoring the next blocks.

This operation affects the pallet’s total stake amount.

The unstaked funds are not released immediately to the account, but they will be available after StakeDuration blocks.

The resulting total amount of funds staked must be within the allowed range as set in the pallet’s configuration.

Emits CollatorStakedLess.

source

pub fn join_delegators( origin: OriginFor<T>, collator: <T::Lookup as StaticLookup>::Source, amount: <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance ) -> DispatchResultWithPostInfo

Join the set of delegators by delegating to a collator candidate.

The account that wants to delegate cannot be part of the collator candidates set as well.

The caller must not have a delegation. If that is the case, they are required to first remove the delegation.

The amount staked must be larger than the minimum required to become a delegator as set in the pallet’s configuration.

As only MaxDelegatorsPerCollator are allowed to delegate a given collator, the amount staked must be larger than the lowest one in the current set of delegator for the operation to be meaningful.

The collator’s total stake as well as the pallet’s total stake are increased accordingly.

Emits Delegation. Emits DelegationReplaced if the candidate has MaxDelegatorsPerCollator many delegations but this delegator staked more than one of the other delegators of this candidate.

source

pub fn leave_delegators(origin: OriginFor<T>) -> DispatchResultWithPostInfo

Leave the set of delegators and, by implication, revoke the ongoing delegation.

All staked funds are not unlocked immediately, but they are added to the queue of pending unstaking, and will effectively be released after StakeDuration blocks from the moment the delegator leaves.

This operation reduces the total stake of the pallet as well as the stakes of all collators that were delegated, potentially affecting their chances to be included in the set of candidates in the next rounds.

Automatically increments the accumulated rewards of the origin of the current delegation.

Emits DelegatorLeft.

source

pub fn delegator_stake_more( origin: OriginFor<T>, more: <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance ) -> DispatchResultWithPostInfo

Increase the stake for delegating a collator candidate.

If not in the set of candidates, staking enough funds allows the collator candidate to be added to it.

Emits DelegatorStakedMore.

source

pub fn delegator_stake_less( origin: OriginFor<T>, less: <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance ) -> DispatchResultWithPostInfo

Reduce the stake for delegating a collator candidate.

If the new amount of staked fund is not large enough, the collator could be removed from the set of collator candidates and not be considered for authoring the next blocks.

The unstaked funds are not release immediately to the account, but they will be available after StakeDuration blocks.

The remaining staked funds must still be larger than the minimum required by this pallet to maintain the status of delegator.

The resulting total amount of funds staked must be within the allowed range as set in the pallet’s configuration.

Emits DelegatorStakedLess.

source

pub fn unlock_unstaked( origin: OriginFor<T>, target: <T::Lookup as StaticLookup>::Source ) -> DispatchResultWithPostInfo

Unlock all previously staked funds that are now available for unlocking by the origin account after StakeDuration blocks have elapsed.

source

pub fn claim_rewards(origin: OriginFor<T>) -> DispatchResult

Claim block authoring rewards for the target address.

Requires Rewards to be set beforehand, which can by triggered by any of the following options

  • Calling increment_{collator, delegator}_rewards (active)
  • Altering your stake (active)
  • Leaving the network as a collator (active)
  • Revoking a delegation as a delegator (active)
  • Being a delegator whose collator left the network, altered their stake or incremented rewards (passive)

The dispatch origin can be any signed one, e.g., anyone can claim for anyone.

Emits Rewarded.

source

pub fn increment_collator_rewards(origin: OriginFor<T>) -> DispatchResult

Actively increment the rewards of a collator.

The same effect is triggered by changing the stake or leaving the network.

The dispatch origin must be a collator.

source

pub fn increment_delegator_rewards(origin: OriginFor<T>) -> DispatchResult

Actively increment the rewards of a delegator.

The same effect is triggered by changing the stake or revoking delegations.

The dispatch origin must be a delegator.

source

pub fn execute_scheduled_reward_change( origin: OriginFor<T> ) -> DispatchResultWithPostInfo

Executes the annual reduction of the reward rates for collators and delegators.

Moreover, sets rewards for all collators and delegators before adjusting the inflation.

The dispatch origin can be any signed one because we bail if called too early.

Emits RoundInflationSet.

source§

impl<T: Config> Pallet<T>

source

pub fn is_delegator(acc: &T::AccountId) -> bool

Check whether an account is currently delegating.

source

pub fn is_active_candidate(acc: &T::AccountId) -> Option<bool>

Check whether an account is currently a collator candidate and whether their state is CollatorStatus::Active.

Returns Some(is_active) if the account is a candidate, else None.

source

pub fn selected_candidates() -> BoundedVec<T::AccountId, T::MaxTopCandidates>

Return the best MaxSelectedCandidates many candidates.

In case a collator from last round was replaced by a candidate with the same total stake during sorting, we revert this swap to prioritize collators over candidates.

source§

impl<T: Config> Pallet<T>

source

pub fn max_selected_candidates() -> u32

An auto-generated getter for MaxSelectedCandidates.

source§

impl<T: Config> Pallet<T>

source

pub fn round() -> RoundInfo<BlockNumberFor<T>>

An auto-generated getter for Round.

source§

impl<T: Config> Pallet<T>

source

pub fn last_delegation<KArg>(k: KArg) -> DelegationCounterwhere KArg: EncodeLike<T::AccountId>,

An auto-generated getter for LastDelegation.

source§

impl<T: Config> Pallet<T>

source

pub fn delegator_state<KArg>( k: KArg ) -> Option<Stake<T::AccountId, <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance>>where KArg: EncodeLike<T::AccountId>,

An auto-generated getter for DelegatorState.

source§

impl<T: Config> Pallet<T>

source

pub fn candidate_pool<KArg>( k: KArg ) -> Option<Candidate<T::AccountId, <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance, T::MaxDelegatorsPerCollator>>where KArg: EncodeLike<T::AccountId>,

An auto-generated getter for CandidatePool.

source§

impl<T: Config> Pallet<T>

source

pub fn total_collator_stake( ) -> TotalStake<<<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance>

An auto-generated getter for TotalCollatorStake.

source§

impl<T: Config> Pallet<T>

source

pub fn top_candidates( ) -> OrderedSet<Stake<T::AccountId, <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance>, T::MaxTopCandidates>

An auto-generated getter for TopCandidates.

source§

impl<T: Config> Pallet<T>

source

pub fn inflation_config() -> InflationInfo

An auto-generated getter for InflationConfig.

source§

impl<T: Config> Pallet<T>

source

pub fn unstaking<KArg>( k: KArg ) -> BoundedBTreeMap<BlockNumberFor<T>, <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance, T::MaxUnstakeRequests>where KArg: EncodeLike<T::AccountId>,

An auto-generated getter for Unstaking.

source§

impl<T: Config> Pallet<T>

source

pub fn max_candidate_stake( ) -> <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance

An auto-generated getter for MaxCollatorCandidateStake.

source§

impl<T: Config> Pallet<T>

source

pub fn last_reward_reduction() -> BlockNumberFor<T>

An auto-generated getter for LastRewardReduction.

source§

impl<T: Config> Pallet<T>

source

pub fn blocks_authored<KArg>(k: KArg) -> BlockNumberFor<T>where KArg: EncodeLike<T::AccountId>,

An auto-generated getter for BlocksAuthored.

source§

impl<T: Config> Pallet<T>

source

pub fn blocks_rewarded<KArg>(k: KArg) -> BlockNumberFor<T>where KArg: EncodeLike<T::AccountId>,

An auto-generated getter for BlocksRewarded.

source§

impl<T: Config> Pallet<T>

source

pub fn rewards<KArg>( k: KArg ) -> <<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balancewhere KArg: EncodeLike<T::AccountId>,

An auto-generated getter for Rewards.

source§

impl<T: Config> Pallet<T>

source

pub fn new_round_forced() -> bool

An auto-generated getter for ForceNewRound.

Trait Implementations§

source§

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

source§

fn before_all_runtime_migrations() -> Weight

Something that should happen before runtime migrations are executed.
source§

impl<T> Benchmarking for Pallet<T>where T: Config + Config, u64: Into<BlockNumberFor<T>>, <T as Config>::Currency: Mutate<T::AccountId>,

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> EstimateNextSessionRotation<<<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for Pallet<T>

source§

fn average_session_length() -> BlockNumberFor<T>

Return the average length of a session. Read more
source§

fn estimate_current_session_progress( now: BlockNumberFor<T> ) -> (Option<Permill>, Weight)

Return an estimate of the current session progress. Read more
source§

fn estimate_next_session_rotation( _now: BlockNumberFor<T> ) -> (Option<BlockNumberFor<T>>, Weight)

Return the block number at which the next session rotation is estimated to happen. Read more
source§

impl<T> EventHandler<<T as Config>::AccountId, <<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for Pallet<T>where T: Config + Config + Config,

source§

fn note_author(author: T::AccountId)

Increments the reward counter of the block author by the current number of collators in the session.

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 try_state(_n: BlockNumberFor<T>) -> Result<(), TryRuntimeError>

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

fn on_finalize(_n: BlockNumber)

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

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
§

fn on_runtime_upgrade() -> Weight

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

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

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

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

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

fn offchain_worker(_n: BlockNumber)

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
§

fn integrity_test()

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

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

source§

fn integrity_test()

See [Hooks::integrity_test].
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§

fn on_finalize(n: BlockNumberFor<T>)

See [Hooks::on_finalize].
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

See [Hooks::on_idle].
source§

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

source§

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

See [Hooks::on_initialize].
source§

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

source§

fn on_runtime_upgrade() -> Weight

See [Hooks::on_runtime_upgrade].
source§

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

See [Hooks::pre_upgrade].
source§

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

See [Hooks::post_upgrade].
§

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 name_hash() -> [u8; 16]

Two128 hash of name.
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> SessionManager<<T as Config>::AccountId> for Pallet<T>

source§

fn new_session(new_index: SessionIndex) -> Option<Vec<T::AccountId>>

  1. A new session starts.
  2. In hook new_session: Read the current top n candidates from the TopCandidates and assign this set to author blocks for the next session.
  3. AuRa queries the authorities from the session pallet for this session and picks authors on round-robin-basis from list of authorities.
source§

fn end_session(_end_index: SessionIndex)

End the session. Read more
source§

fn start_session(_start_index: SessionIndex)

Start an already planned session. Read more
§

fn new_session_genesis(new_index: u32) -> Option<Vec<ValidatorId, Global>>

Same as new_session, but it this should only be called at genesis. Read more
source§

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

source§

fn should_end_session(now: BlockNumberFor<T>) -> bool

Return true if the session should be ended.
source§

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

source§

fn storage_info() -> Vec<StorageInfo>

source§

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

source§

fn try_decode_entire_state() -> Result<usize, Vec<TryDecodeEntireStorageError>>

Decode the entire data under the given storage, returning Ok(bytes_decoded) if success.
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> 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>