Fixes TotalValueLocked out of sync in nomination pools#3052
Fixes TotalValueLocked out of sync in nomination pools#3052
TotalValueLocked out of sync in nomination pools#3052Conversation
TotalValueLocked out of sync in nomination pools
|
bot fmt |
|
@gpestana https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5024240 was started for your command Comment |
|
@gpestana Command |
rossbulat
left a comment
There was a problem hiding this comment.
This warning comment for EventListeners should probably be updated to reflect the additional on_withdraw use case.
| // Before calculating the `balance_to_unbond`, we call withdraw unbonded to ensure the | ||
| // `transferrable_balance` is correct. | ||
| let stash_killed = bonded_pool.withdraw_from_staking(num_slashing_spans)?; | ||
| let stash_killed = |
There was a problem hiding this comment.
Can we not update the TVL here, instead of needing the on_withdraw?
There was a problem hiding this comment.
That's what the fn withdraw_from_staking was doing. However that's insufficient because staking may withdraw unlocking chunks from a bonded pool account without an explicit request from pools. If that happens, the TVL in the pool is not updated.
This is the culprit code on the staking side: https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/staking/src/pallet/mod.rs#L1029-L1039.
Co-authored-by: Ross Bulat <[email protected]>
Co-authored-by: Ross Bulat <[email protected]>
Co-authored-by: Ross Bulat <[email protected]>
|
The CI pipeline was cancelled due to failure one of the required jobs. |
|
The CI pipeline was cancelled due to failure one of the required jobs. |
seadanda
left a comment
There was a problem hiding this comment.
LGTM - sorry for the grammatical tweaks 😀
substrate/frame/election-provider-multi-phase/test-staking-e2e/src/lib.rs
Outdated
Show resolved
Hide resolved
Co-authored-by: Dónal Murray <[email protected]>
…/src/lib.rs Co-authored-by: Dónal Murray <[email protected]>
Co-authored-by: Dónal Murray <[email protected]>
…3052) 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 paritytech#3055 --------- Co-authored-by: command-bot <> Co-authored-by: Ross Bulat <[email protected]> Co-authored-by: Dónal Murray <[email protected]>
The
TotalLockedValuestorage 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 theOnStakingUpdatetraits,on_withdraw, which allows the nomination pools pallet to adjust theTotalLockedValueevery 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 OnStakingUpdateIn order for staking to notify the nomination pools pallet that chunks where withdrew, we add a new method,
on_withdrawto theOnStakingUpdatetrait. The nomination pools pallet filters the withdraws that are related to bonded pool accounts and updates theTotalValueLockedaccordingly.Others
To-do
TotalValueLocked(run try-runtime)✅ Kusama:
Polkadot: TVL not released yet.
Closes #3055