Crate pallet_capacity

source ·
Expand description

Managages staking to the network for Capacity

Capacity Pallet

The Capacity Pallet manages the staking and balances for Capacity, an alternative payment system on Frequency.

Summary

Capacity is an alternative to paying with tokens for a limited set of calls. These Capacity eligible extrinsics are noted in each pallet’s documentation with “Capacity” in the Payment column of the extrinsics section. Tokens can be staked to generate Capacity for a targeted Provider. The generated Capacity renews each Epoch. Learn more about Capacity.

Staking & Unstaking

Currently, the token to Capacity ratio is 50:1. For example, for a 5 token stake, a Provider would receive 0.1 Capacity. Staking and unstaking affect available Capacity immediately.

Capacity Epoch

A Capacity Epoch is a period consisting of a specific number of blocks, during which a Provider’s utilization of network Capacity is capped at the amount of generated Capacity targeted to that Provider. At the start of each new Epoch, the available Capacity is renewed for each Provider, regardless of how much they consumed in the prior Epoch. The duration of a Capacity Epoch is determined by Governance, and is currently set to 7200 blocks. With the current average block time of approximately 12 seconds, one Capacity Epoch lasts around 24 hours on Mainnet.

Thaw Period

After unstaking, the tokens will still be frozen for a set amount of time before they are unencumbered and able to be transferred. The UnstakingThawPeriod constant defines the number of Epochs that must pass before the tokens may be reclaimed for any use via withdrawUnstaked(). Currently it is set to 30 Epochs or ~30 days after unstaking.

Actions

The Capacity Pallet provides for:

  • Staking to receive Capacity
  • Unstaking & Thaw Period
  • Capacity Epoch management

Interactions

Extrinsics

Name/DescriptionCallerPaymentKey EventsRuntime Added
stake
Lock tokens to grant Capacity to a Provider
Token AccountTokensStaked1
unstake
Begin the process of unlocking tokens by unstaking currently staked tokens
Token AccountTokensUnStaked1
withdraw_unstaked
Complete the process of unlocking tokens staked by releasing locks on expired unlock chunks
Token AccountTokensStakeWithdrawn1

See Rust Docs for more details.

State Queries

NameDescriptionQueryRuntime Added
Get Capacity LedgerReturns the Capacity balance details for a Provider’s MSA IdcapacityLedger1
Get Current EpochReturns the current Capacity Epoch numbercurrentEpoch1
Get Current Epoch InfoReturns information about the current Capacity Epoch such as the starting block numbercurrentEpochInfo1
Get Staking Account LedgerReturns information about an account’s current staking detailsstakingAccountLedger1
Staking Target LedgerReturns information about an account’s current staking details for a specific target Provider MSA IdstakingTargetLedger1
Get Unstake InformationReturns the information about an account’s current unstaking details and the unlocking chunksunstakeUnlocks1

See the Rust Docs for additional state queries and details.

Lazy Capacity Refill

Capacity is refilled on an as needed basis. Thus, the provider’s capacity balance retains the information of the last epoch. Upon use, if the last Epoch is less than the current Epoch, the balance is assumed to be the maximum as the reload “has” happened. Thus, the first use of Capacity in an Epoch will update the last Epoch number to match the current Epoch. If a provider does not use any Capacity in an Epoch, the provider’s capacity balance information is never updated for that Epoch.

Re-exports

Modules

  • storage migrations
  • The pallet module in each FRAME pallet hosts the most important items needed to construct this pallet.
  • Types for the Capacity Pallet
  • Autogenerated weights for pallet_capacity

Traits

Functions

  • Wraps PREFIX and POSTFIX around a Vec<u8> Returns PREFIX ++ data ++ POSTFIX

Type Aliases

  • Message Source Id or msaId is the unique identifier for Message Source Accounts