-
Notifications
You must be signed in to change notification settings - Fork 704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extrinsic to restore corrupt staking ledgers #3706
Conversation
bot bench substrate-pallet --pallet=pallet_staking |
…=dev --target_dir=substrate --pallet=pallet_staking
@gpestana Command |
/// storage. | ||
/// * The ledger's controller and stash matches the associated `Bonded` tuple. | ||
/// * Staking locked funds for every bonded stash should be the same as its ledger's total. | ||
/// * Staking ledger and bond are not corrupted. | ||
fn check_ledgers() -> Result<(), TryRuntimeError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is the running time for this try state check? Don't mind putting this in release for now if it is not super long but want to point out that you are reading some storages multiple times and it can be optimized to be much faster.
Ideally we read any storage only once and keep it in memory for further checks.
bot bench polkadot-pallet --runtime=westend --pallet=pallet_staking |
@gpestana https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5671993 was started for your command Comment |
…=westend --target_dir=polkadot --pallet=pallet_staking
@gpestana Command |
This PR adds a new extrinsic `Call::restore_ledger ` gated by `StakingAdmin` origin that restores a corrupted staking ledger. This extrinsic will be used to recover ledgers that were affected by the issue discussed in paritytech#3245. The extrinsic will re-write the storage items associated with a stash account provided as input parameter. The data used to reset the ledger can be either i) fetched on-chain or ii) partially/totally set by the input parameters of the call. In order to use on-chain data to restore the staking locks, we need a way to read the current lock in the balances pallet. This PR adds a `InspectLockableCurrency` trait and implements it in the pallet balances. An alternative would be to tightly couple staking with the pallet balances but that's inelegant (an example of how it would look like in [this branch](https://github.com/paritytech/polkadot-sdk/tree/gpestana/ledger-badstate-clean_tightly)). More details on the type of corruptions and corresponding fixes https://hackmd.io/DLb5jEYWSmmvqXC9ae4yRg?view#/ We verified that the `Call::restore_ledger` does fix all current corrupted ledgers in Polkadot and Kusama. You can verify it here https://hackmd.io/v-XNrEoGRpe7APR-EZGhOA. **Changes introduced** - Adds `Call::restore_ledger ` extrinsic to recover a corrupted ledger; - Adds trait `frame_support::traits::currency::InspectLockableCurrency` to allow external pallets to read current locks given an account and lock ID; - Implements the `InspectLockableCurrency` in the pallet-balances. - Adds staking locks try-runtime checks (paritytech#3751) **Todo** - [x] benchmark `Call::restore_ledger` - [x] throughout testing of all ledger recovering cases - [x] consider adding the staking locks try-runtime checks to this PR (paritytech#3751) - [x] simulate restoring all ledgers (https://hackmd.io/Dsa2tvhISNSs7zcqriTaxQ?view) in Polkadot and Kusama using chopsticks -- https://hackmd.io/v-XNrEoGRpe7APR-EZGhOA Related to paritytech#3245 Closes paritytech#3751 --------- Co-authored-by: command-bot <>
This pull request has been mentioned on Polkadot Forum. There might be relevant details there: https://forum.polkadot.network/t/recover-corrupted-staking-ledgers-in-polkadot-and-kusama/9796/1 |
This PR adds a new extrinsic
Call::restore_ledger
gated byStakingAdmin
origin that restores a corrupted staking ledger. This extrinsic will be used to recover ledgers that were affected by the issue discussed in #3245.The extrinsic will re-write the storage items associated with a stash account provided as input parameter. The data used to reset the ledger can be either i) fetched on-chain or ii) partially/totally set by the input parameters of the call.
In order to use on-chain data to restore the staking locks, we need a way to read the current lock in the balances pallet. This PR adds a
InspectLockableCurrency
trait and implements it in the pallet balances. An alternative would be to tightly couple staking with the pallet balances but that's inelegant (an example of how it would look like in this branch).More details on the type of corruptions and corresponding fixes https://hackmd.io/DLb5jEYWSmmvqXC9ae4yRg?view#/
We verified that the
Call::restore_ledger
does fix all current corrupted ledgers in Polkadot and Kusama. You can verify it here https://hackmd.io/v-XNrEoGRpe7APR-EZGhOA.Changes introduced
Call::restore_ledger
extrinsic to recover a corrupted ledger;frame_support::traits::currency::InspectLockableCurrency
to allow external pallets to read current locks given an account and lock ID;InspectLockableCurrency
in the pallet-balances.Todo
Call::restore_ledger
Related to #3245
Closes #3751