1. Apr 26, 2024
  2. Apr 20, 2024
    • Ankan's avatar
      Allow privileged virtual bond in Staking pallet (#3889) · e504c41a
      Ankan authored
      This is the first PR in preparation for
      https://github.com/paritytech/polkadot-sdk/issues/454.
      
      ## Follow ups:
      - https://github.com/paritytech/polkadot-sdk/pull/3904.
      - https://github.com/paritytech/polkadot-sdk/pull/3905.
      
      Overall changes are documented here (lot more visual 😍):
      https://hackmd.io/@ak0n/454-np-governance
      
      [Maybe followup](https://github.com/paritytech/polkadot-sdk/issues/4217)
      with migration of storage item `VirtualStakers` as a bool or enum in
      `Ledger`.
      
      ## Context
      We want to achieve a way for a user (`Delegator`) to delegate their
      funds to another account (`Agent`). Delegate implies the funds are
      locked in delegator account itself. Agent can act on behalf of delegator
      to stake directly on Staking pallet.
      
      The delegation feature is added to Staking via another pallet
      `delegated-staking` worked on
      [here](https://github.com/paritytech/polkadot-sdk/pull/3904).
      
      ## Introduces:
      ### StakingUnchecked Trait
      As the name implies, this trait allows unchecked (non-locked) mutation
      of staking ledger. These apis are only meant to be used by other pallets
      in the runtime and should not be exposed directly to user code path.
      Also related: https://github.com/paritytech/polkadot-sdk/issues/3888.
      
      ### Virtual Bond
      Allows other pallets to stake via staking pallet while managing the
      locks on these accounts themselves. Introduces another storage
      `VirtualStakers` that whitelist these accounts.
      
      We also restrict virtual stakers to set reward account as themselves.
      Since the account has no locks, we cannot support compounding of
      rewards. Conservatively, we require them to set a separate account
      different from the staker. Since these are code managed, it should be
      easy for another pallet to redistribute reward and rebond them.
      
      ### Slashes
      Since there is no actual lock maintained by staking-pallet for virtual
      stakers, this pallet does not apply any slashes. It is then important
      for pallets managing virtual stakers to listen to slashing events and
      apply necessary slashes.
      e504c41a
  3. Apr 02, 2024
  4. Mar 26, 2024
    • Dcompoze's avatar
      Fix spelling mistakes across the whole repository (#3808) · 002d9260
      Dcompoze authored
      **Update:** Pushed additional changes based on the review comments.
      
      **This pull request fixes various spelling mistakes in this
      repository.**
      
      Most of the changes are contained in the first **3** commits:
      
      - `Fix spelling mistakes in comments and docs`
      
      - `Fix spelling mistakes in test names`
      
      - `Fix spelling mistakes in error messages, panic messages, logs and
      tracing`
      
      Other source code spelling mistakes are separated into individual
      commits for easier reviewing:
      
      - `Fix the spelling of 'authority'`
      
      - `Fix the spelling of 'REASONABLE_HEADERS_IN_JUSTIFICATION_ANCESTRY'`
      
      - `Fix the spelling of 'prev_enqueud_messages'`
      
      - `Fix the spelling of 'endpoint'`
      
      - `Fix the spelling of 'children'`
      
      - `Fix the spelling of 'PenpalSiblingSovereignAccount'`
      
      - `Fix the spelling of 'PenpalSudoAccount'`
      
      - `Fix the spelling of 'insufficient'`
      
      - `Fix the spelling of 'PalletXcmExtrinsicsBenchmark'`
      
      - `Fix the spelling of 'subtracted'`
      
      - `Fix the spelling of 'CandidatePendingAvailability'`
      
      - `Fix the spelling of 'exclusive'`
      
      - `Fix the spelling of 'until'`
      
      - `Fix the spelling of 'discriminator'`
      
      - `Fix the spelling of 'nonexistent'`
      
      - `Fix the spelling of 'subsystem'`
      
      - `Fix the spelling of 'indices'`
      
      - `Fix the spelling of 'committed'`
      
      - `Fix the spelling of 'topology'`
      
      - `Fix the spelling of 'response'`
      
      - `Fix the spelling of 'beneficiary'`
      
      - `Fix the spelling of 'formatted'`
      
      - `Fix the spelling of 'UNKNOWN_PROOF_REQUEST'`
      
      - `Fix the spelling of 'succeeded'`
      
      - `Fix the spelling of 'reopened'`
      
      - `Fix the spelling of 'proposer'`
      
      - `Fix the spelling of 'InstantiationNonce'`
      
      - `Fix the spelling of 'depositor'`
      
      - `Fix the spelling of 'expiration'`
      
      - `Fix the spelling of 'phantom'`
      
      - `Fix the spelling of 'AggregatedKeyValue'`
      
      - `Fix the spelling of 'randomness'`
      
      - `Fix the spelling of 'defendant'`
      
      - `Fix the spelling of 'AquaticMammal'`
      
      - `Fix the spelling of 'transactions'`
      
      - `Fix the spelling of 'PassingTracingSubscriber'`
      
      - `Fix the spelling of 'TxSignaturePayload'`
      
      - `Fix the spelling of 'versioning'`
      
      - `Fix the spelling of 'descendant'`
      
      - `Fix the spelling of 'overridden'`
      
      - `Fix the spelling of 'network'`
      
      Let me know if this structure is adequate.
      
      **Note:** The usage of the words `Merkle`, `Merkelize`, `Merklization`,
      `Merkelization`, `Merkleization`, is somewhat inconsistent but I left it
      as it is.
      
      ~~**Note:** In some places the term `Receival` is used to refer to
      message reception, IMO `Reception` is the correct word here, but I left
      it as it is.~~
      
      ~~**Note:** In some places the term `Overlayed` is used instead of the
      more acceptable version `Overlaid` but I also left it as it is.~~
      
      ~~**Note:** In some places the term `Applyable` is used instead of the
      correct version `Applicable` but I also left it as it is.~~
      
      **Note:** Some usage of British vs American english e.g. `judgement` vs
      `judgment`, `initialise` vs `initialize`, `optimise` vs `optimize` etc.
      are both present in different places, but I suppose that's
      understandable given the number of contributors.
      
      ~~**Note:** There is a spelling mistake in `.github/CODEOWNERS` but it
      triggers errors in CI when I make changes to it, so I left it as it
      is.~~
      002d9260
  5. Mar 18, 2024
    • Squirrel's avatar
      sp-std removal from substrate/primitives (#3274) · 1b5f4243
      Squirrel authored
      
      
      This PR removes sp-std crate from substrate/primitives sub-directories.
      
      For now crates that have `pub use` of sp-std or export macros that would
      necessitate users of the macros to `extern crate alloc` have been
      excluded from this PR.
      
      There should be no breaking changes in this PR.
      
      ---------
      
      Co-authored-by: default avatarKoute <[email protected]>
      1b5f4243
  6. Feb 20, 2024
    • Oliver Tale-Yazdi's avatar
      Lift dependencies to the workspace (Part 2/x) (#3366) · e89d0fca
      Oliver Tale-Yazdi authored
      
      
      Lifting some more dependencies to the workspace. Just using the
      most-often updated ones for now.
      It can be reproduced locally.
      
      ```sh
      # First you can check if there would be semver incompatible bumps (looks good in this case):
      $ zepter transpose dependency lift-to-workspace --ignore-errors syn quote thiserror "regex:^serde.*"
      
      # Then apply the changes:
      $ zepter transpose dependency lift-to-workspace --version-resolver=highest syn quote thiserror "regex:^serde.*" --fix
      
      # And format the changes:
      $ taplo format --config .config/taplo.toml
      ```
      
      ---------
      
      Signed-off-by: default avatarOliver Tale-Yazdi <[email protected]>
      e89d0fca
  7. Feb 16, 2024
  8. Feb 08, 2024
    • Gonçalo Pestana's avatar
      Fixes `TotalValueLocked` out of sync in nomination pools (#3052) · aac07af0
      Gonçalo Pestana authored
      The `TotalLockedValue` storage value in nomination pools pallet may get
      out of sync if the staking pallet does implicit withdrawal of unlocking
      chunks belonging to a bonded pool stash. This fix is based on a new
      method in the `OnStakingUpdate` traits, `on_withdraw`, which allows the
      nomination pools pallet to adjust the `TotalLockedValue` every time
      there is an implicit or explicit withdrawal from a bonded pool's stash.
      
      This PR also adds a migration that checks and updates the on-chain TVL
      if it got out of sync due to the bug this PR fixes.
      
      **Changes to `trait OnStakingUpdate`**
      
      In order for staking to notify the nomination pools pallet that chunks
      where withdrew, we add a new method, `on_withdraw` to the
      `OnStakingUpdate` trait. The nomination pools pallet filters the
      withdraws that are related to bonded pool accounts and updates the
      `TotalValueLocked` accordingly.
      
      **Others**
      - Adds try-state checks to the EPM/staking e2e tests
      - Adds tests for auto withdrawing in the context of nomination pools
      
      **To-do**
      - [x] check if we need a migration to fix the current `TotalValueLocked`
      (run try-runtime)
      - [x] migrations to fix the current on-chain TVL value 
      
        **Kusama**:
      ```
      TotalValueLocked: 99.4559 kKSM
      TotalValueLocked (calculated) 99.4559 kKSM
      ```
      ️ **Westend**:
      ```
      TotalValueLocked: 18.4060 kWND
      TotalValueLocked (calculated) 18.4050 kWND
      ```
      **Polkadot**: TVL not released yet.
      
      Closes https://github.com/paritytech/polkadot-sdk/issues/3055
      
      
      
      ---------
      
      Co-authored-by: command-bot <>
      Co-authored-by: default avatarRoss Bulat <[email protected]>
      Co-authored-by: default avatarDónal Murray <[email protected]>
      aac07af0
  9. Jan 26, 2024
  10. Jan 07, 2024
  11. Jan 04, 2024
  12. Dec 13, 2023
  13. Dec 01, 2023
  14. Nov 30, 2023
  15. Nov 01, 2023
    • Ankan's avatar
      [NPoS] Paging reward payouts in order to scale rewardable nominators (#1189) · 00b85c51
      Ankan authored
      helps https://github.com/paritytech/polkadot-sdk/issues/439.
      closes https://github.com/paritytech/polkadot-sdk/issues/473.
      
      PR link in the older substrate repository:
      https://github.com/paritytech/substrate/pull/13498.
      
      # Context
      Rewards payout is processed today in a single block and limited to
      `MaxNominatorRewardedPerValidator`. This number is currently 512 on both
      Kusama and Polkadot.
      
      This PR tries to scale the nominators payout to an unlimited count in a
      multi-block fashion. Exposures are stored in pages, with each page
      capped to a certain number (`MaxExposurePageSize`). Starting out, this
      number would be the same as `MaxNominatorRewardedPerValidator`, but
      eventually, this number can be lowered through new runtime upgrades to
      limit the rewardeable nominators per dispatched call instruction.
      
      The changes in the PR are backward compatible.
      
      ## How payouts would work like after this change
      Staking exposes two calls, 1) the existing `payout_stakers` and 2)
      `payout_stakers_by_page`.
      
      ### payout_stakers
      This remains backward compatible with no signature change. If for a
      given era a validator has multiple pages, they can call `payout_stakers`
      multiple times. The pages are executed in an ascending sequence and the
      runtime takes care of preventing double claims.
      
      ### payout_stakers_by_page
      Very similar to `payout_stakers` but also accepts an extra param
      `page_index`. An account can choose to payout rewards only for an
      explicitly passed `page_index`.
      
      **Lets look at an example scenario**
      Given an active validator on Kusama had 1100 nominators,
      `MaxExposurePageSize` set to 512 for Era e. In order to pay out rewards
      to all nominators, the caller would need to call `payout_stakers` 3
      times.
      
      - `payout_stakers(origin, stash, e)` => will pay the first 512
      nominators.
      - `payout_stakers(origin, stash, e)` => will pay the second set of 512
      nominators.
      - `payout_stakers(origin, stash, e)` => will pay the last set of 76
      nominators.
      ...
      - `payout_stakers(origin, stash, e)` => calling it the 4th time would
      return an error `InvalidPage`.
      
      The above calls can also be replaced by `payout_stakers_by_page` and
      passing a `page_index` explicitly.
      
      ## Commission note
      Validator commission is paid out in chunks across all the pages where
      each commission chunk is proportional to the total stake of the current
      page. This implies higher the total stake of a page, higher will be the
      commission. If all the pages of a validator's single era are paid out,
      the sum of commission paid to the validator across all pages should be
      equal to what the commission would have been if we had a non-paged
      exposure.
      
      ### Migration Note
      Strictly speaking, we did not need to bump our storage version since
      there is no migration of storage in this PR. But it is still useful to
      mark a storage upgrade for the following reasons:
      
      - New storage items are introduced in this PR while some older storage
      items are deprecated.
      - For the next `HistoryDepth` eras, the exposure would be incrementally
      migrated to its corresponding paged storage item.
      - Runtimes using staking pallet would strictly need to wait at least
      `HistoryDepth` eras with current upgraded version (14) for the migration
      to complete. At some era `E` such that `E >
      era_at_which_V14_gets_into_effect + HistoryDepth`, we will upgrade to
      version X which will remove the deprecated storage items.
      In other words, it is a strict requirement that E<sub>x</sub> -
      E<sub>14</sub> > `HistoryDepth`, where
      E<sub>x</sub> = Era at which deprecated storages are removed from
      runtime,
      E<sub>14</sub> = Era at which runtime is upgraded to version 14.
      - For Polkadot and Kusama, there is a [tracker
      ticket](https://github.com/paritytech/polkadot-sdk/issues/433) to clean
      up the deprecated storage items.
      
      ### Storage Changes
      
      #### Added
      - ErasStakersOverview
      - ClaimedRewards
      - ErasStakersPaged
      
      #### Deprecated
      The following can be cleaned up after 84 eras which is tracked
      [here](https://github.com/paritytech/polkadot-sdk/issues/433).
      
      - ErasStakers.
      - ErasStakersClipped.
      - StakingLedger.claimed_rewards, renamed to
      StakingLedger.legacy_claimed_rewards.
      
      ### Config Changes
      - Renamed MaxNominatorRewardedPerValidator to MaxExposurePageSize.
      
      ### TODO
      - [x] Tracker ticket for cleaning up the old code after 84 eras.
      - [x] Add companion.
      - [x] Redo benchmarks before merge.
      - [x] Add Changelog for pallet_staking.
      - [x] Pallet should be configurable to enable/disable paged rewards.
      - [x] Commission payouts are distributed across pages.
      - [x] Review documentation thoroughly.
      - [x] Rename `MaxNominatorRewardedPerValidator` ->
      `MaxExposurePageSize`.
      - [x] NMap for `ErasStakersPaged`.
      - [x] Deprecate ErasStakers.
      - [x] Integrity tests.
      
      ### Followup issues
      [Runtime api for deprecated ErasStakers storage
      item](https://github.com/paritytech/polkadot-sdk/issues/426
      
      )
      
      ---------
      
      Co-authored-by: default avatarJavier Viola <[email protected]>
      Co-authored-by: default avatarRoss Bulat <[email protected]>
      Co-authored-by: command-bot <>
      00b85c51
  16. Oct 20, 2023
    • Bastian Köcher's avatar
      `xcm`: Change `TypeInfo::path` to not include `staging` (#1948) · f3bf5c1a
      Bastian Köcher authored
      The `xcm` crate was renamed to `staging-xcm` to be able to publish it to
      crates.io as someone as squatted `xcm`. The problem with this rename is
      that the `TypeInfo` includes the crate name which ultimately lands in
      the metadata. The metadata is consumed by downstream users like
      `polkadot-js` or people building on top of `polkadot-js`. These people
      are using the entire `path` to find the type in the type registry. Thus,
      their code would break as the type path would now be [`staging_xcm`,
      `VersionedXcm`] instead of [`xcm`, `VersionedXcm`]. This pull request
      fixes this by renaming the path segment `staging_xcm` to `xcm`.
      
      This requires: https://github.com/paritytech/scale-info/pull/197
      
      
      
      ---------
      
      Co-authored-by: default avatarFrancisco Aguirre <[email protected]>
      f3bf5c1a
  17. Oct 15, 2023
    • Gonçalo Pestana's avatar
      Refactor staking ledger (#1484) · 8ee4042c
      Gonçalo Pestana authored
      This PR refactors the staking ledger logic to encapsulate all reads and
      mutations of `Ledger`, `Bonded`, `Payee` and stake locks within the
      `StakingLedger` struct implementation.
      
      With these changes, all the reads and mutations to the `Ledger`, `Payee`
      and `Bonded` storage map should be done through the methods exposed by
      StakingLedger to ensure the data and lock consistency of the operations.
      The new introduced methods that mutate and read Ledger are:
      
      - `ledger.update()`: inserts/updates a staking ledger in storage;
      updates staking locks accordingly (and ledger.bond(), which is synthatic
      sugar for ledger.update())
      - `ledger.kill()`: removes all Bonded and StakingLedger related data for
      a given ledger; updates staking locks accordingly;
      `StakingLedger::get(account)`: queries both the `Bonded` and `Ledger`
      storages and returns a `Option<StakingLedger>`. The pallet impl exposes
      fn ledger(account) as synthatic sugar for `StakingLedger::get(account)`.
      
      Retrieving a ledger with `StakingLedger::get()` can be done by providing
      either a stash or controller account. The input must be wrapped in a
      `StakingAccount` variant (Stash or Controller) which is treated
      accordingly. This simplifies the caller API but will eventually be
      deprecated once we completely get rid of the controller account in
      staking. However, this refactor will help with the work necessary when
      completely removing the controller.
      
      Other goals:
      
      - No logical changes have been introduced in this PR;
      - No breaking changes or updates in wallets required;
      - No new storage items or need to perform storage migrations;
      - Centralise the changes to bonds and ledger updates to simplify the
      OnStakingUpdate updates to the target list (related to
      https://github.com/paritytech/polkadot-sdk/issues/443)
      
      Note: it would be great to prevent or at least raise a warning if
      `Ledger<T>`, `Payee<T>` and `Bonded<T>` storage types are accessed
      outside the `StakingLedger` implementation. This PR should not get
      blocked by that feature, but there's a tracking issue here
      https://github.com/paritytech/polkadot-sdk/issues/149
      
      Related and step towards
      https://github.com/paritytech/polkadot-sdk/issues/443
      8ee4042c
  18. Oct 01, 2023
  19. Sep 04, 2023
    • Chevdor's avatar
      Markdown linter (#1309) · a30092ab
      Chevdor authored
      
      
      * Add markdown linting
      
      - add linter default rules
      - adapt rules to current code
      - fix the code for linting to pass
      - add CI check
      
      fix #1243
      
      * Fix markdown for Substrate
      * Fix tooling install
      * Fix workflow
      * Add documentation
      * Remove trailing spaces
      * Update .github/.markdownlint.yaml
      
      Co-authored-by: default avatarOliver Tale-Yazdi <[email protected]>
      * Fix mangled markdown/lists
      * Fix captalization issues on known words
      a30092ab
  20. Aug 30, 2023
  21. Aug 29, 2023
  22. Aug 25, 2023
  23. Aug 23, 2023
  24. Aug 01, 2023
  25. Jul 09, 2023
  26. Jun 29, 2023
  27. Jun 21, 2023
  28. Jun 01, 2023
    • Michal Kucharczyk's avatar
      frame: support for serde added (#14261) · dc716127
      Michal Kucharczyk authored
      
      
      * frame: support for serde added
      
      - enabled `serde` features in dependent crates, no gate feature introduced, linker should do the job and strip unused code.
      
      - frame::staking: added impl of `serde::Serialize, serde::Deserialize` for `enum Forcing`
      
      - primitives::runtime: impl_opaque_keys macro provides `Serialize/Deserialize` impl if `serde` is enabled
      
      - primitives::staking: added impl of `serde::Serialize`, `serde::Deserialize` for `enum StakerStatus`
      
      * frame::support: serde for pallets' GenesisConfig enabled in no-std
      
      * Cargo.lock updated
      
      * Update primitives/staking/Cargo.toml
      
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      
      * fix
      
      * Cargo.lock update + missed serde/std in beefy
      
      ---------
      
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      dc716127
  29. May 31, 2023
  30. May 29, 2023
  31. Apr 27, 2023
  32. Apr 15, 2023
  33. Apr 12, 2023
  34. Mar 07, 2023
    • Davide Galassi's avatar
      Offences report system rework (#13425) · 9dd10d13
      Davide Galassi authored
      * Experiments with common equivocation trait
      
      * Improved equivocation trait
      
      * Fix grandpa equivocation implementation
      
      * Remove some cruft
      
      * Remove some more cruft
      
      * More generic naming
      
      * Simplification of offences manipilation
      
      * More refactory
      
      * Some prograss with the encapsulation of offence report system
      
      * Finally unit type works as a universal null report system
      
      * Align substrate node code
      
      * Further simplification
      
      * Fix test utils
      
      * Remove not required associated type
      
      * Fix benches
      
      * Rollback to prev field name
      
      * Box big params
      
      * Fix typo
      
      * Remove new tag computation
      
      * Remove default implementations
      
      * Better docs
      
      * Return 'Result' instead of bool
      
      * Change offence report system return types
      
      * Some renaming and documentation
      
      * Improve documentation
      
      * More abstract offence report system
      
      * Rename 'consume_evidence' to 'process_evidence'
      
      * Further docs refinements
      
      * Doc for dummy offence report
      
      * Fix rustdoc
      
      * Fix after master merge
      
      * Apply code review suggestions
      
      * Improve docs
      9dd10d13
  35. Feb 21, 2023
    • Vivek Pandya's avatar
      Remove years from copyright notes. (#13415) · bc53b9a0
      Vivek Pandya authored
      * Change copyright year to 2023 from 2022
      
      * Fix incorrect update of copyright year
      
      * Remove years from copy right header
      
      * Fix remaining files
      
      * Fix typo in a header and remove update-copyright.sh
      bc53b9a0
  36. Jan 19, 2023
  37. Dec 13, 2022
    • Bastian Köcher's avatar
      Fixup some wrong dependencies (#12899) · c0c8d630
      Bastian Köcher authored
      * Fixup some wrong dependencies
      
      Dev dependencies should not appear in the feature list. If features are required, they should be
      directly enabled for the `dev-dependency`.
      
      * More fixups
      
      * Fix fix
      
      * Remove deprecated feature
      
      * Make all work properly and nice!!
      
      * FMT
      
      * Fix formatting
      c0c8d630
  38. Nov 15, 2022