1. 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
  2. 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
  3. Jul 18, 2023
  4. May 15, 2023
  5. May 03, 2023
  6. Mar 16, 2023
    • Gonçalo Pestana's avatar
      Integration tests for staking + election-provider-multi-phase (#12972) · ce08e135
      Gonçalo Pestana authored
      
      
      * EPM and staking pallets: Adds new crate for integration tests
      
      a
      
      * Adds ExtBuilder and helpers with initial conditions assertions
      
      * removes account helpers; adds staking, session, etc genesis
      
      * Adds kusama incident test case
      
      * Prepare for slashing test
      
      * Adds solution submission
      
      * slash_through_offending_threshold
      
      * Renames e2e integration tests dir and crate
      
      * consistently slash 10% of validator set
      
      * finishes continous_slashes_below_offending_threshold test
      
      * Update frame/election-provider-multi-phase/test-staking-e2e/src/lib.rs
      
      Co-authored-by: default avatarAnkan <[email protected]>
      
      * Update frame/election-provider-multi-phase/test-staking-e2e/src/lib.rs
      
      Co-authored-by: default avatarAnkan <[email protected]>
      
      * Update frame/election-provider-multi-phase/test-staking-e2e/src/lib.rs
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      
      * Update frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      
      * Update frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      
      * Update frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      
      * mock fixes
      
      * Additional checks to delayed solution eras and mock fixes
      
      * nits and addresses review comments; splits ext_builder into one per pallet
      
      * helper to set balances ext builder
      
      * bring up mock.rs to master
      
      * integration test fixes and additions
      
      ---------
      
      Co-authored-by: default avatarAnkan <[email protected]>
      Co-authored-by: default avatarKian Paimani <[email protected]>
      ce08e135