-
Notifications
You must be signed in to change notification settings - Fork 709
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
nomination-pools try-state hook fails on Kusama #158
Comments
cc @Szegoo |
I think ED was actually changed 10x at some point recently. I think this one paritytech/polkadot#6372, but it needs a bit closer investigation first. @rossbulat |
So the hypothesis is that because ED on Kusama has increased 10x, pool if this is correct, I imagine an OpenGov referendum to inject balance from the treasury into each pool would fix this? Reached out to @liamaharon, easiest way to check this (i think) would be to send a small amount of KSM to pool 40's reward pool (first one on logs), re-run try-state, & verify pool 40 no longer contains the warning. |
Verified your transfer of 0.1 KSM fixed nom pool 40 @rossbulat. We could fix this by OpenGov or in a runtime upgrade, either is fine I think. |
I sent all the reward pools the ED amount: https://kusama.subscan.io/extrinsic/0x74dcbb20df2d8e2548cbe93d251ed290259506d146c145d04841fdea7b6bff7b Hopefully this will resolve the runtime errors, please let me know. |
Ah perhaps that once was missed, just topped it up. |
The underlying issue, if real and something beyond the change to ED should be looked into by @paritytech/staking-core. |
For the hypothesis that this might be due to ED increase, if we add 300_000_000 or 0.0003 KSM (the increase in ED) to the reward account, the remaining should go above the pending rewards. Ross's top up should have fixed this. Funny thing is the difference between pending rewards and remaining balance comes up to |
I have reproduced this issue in a test here. Would appreciate if someone can review this and make sure everything looks good and makes sense. Why this happened?Pending reward calculation of a delegator depends on the current_reward_counter of the pool. Due to a bug in the logic (affected by ED increase), the pool thinks it has not paid some rewards (equal or less than the ED diff) while it has already been paid earlier. Subsequently, the
What was the bug?The current_reward_counter is calculated from two parts, the Both these values, The culprit that caused this discrepancy was this line which roughly does the following:
Since the min_balance increases in our case, the last_recorded_total_payouts is overwritten and could decrease unless new free_balance has arrived since the ED increase in form of staking rewards that can cover the ED difference. The current_reward_counter is calculated using following formulas. As you can see, decrease in
Note: Above formulas is simplified and ignores commission. None of the affected pools has commission so we can safely ignore it. Would topping up the reward account help?No. Any top up can be seen equivalent to staking rewards for a pool and will be distributed equally among all delegators of the pool leaving roughly the same deficit as before. This is shown in the test as well. What's the fixIncreasing the last_recorded_total_payouts to the amount of deficit would fix this issue. Demonstrated in the test. We should also fix how If ED is decreased, would that also cause an issue?Decrease is fine since the difference is treated as extra rewards for the pool and is distributed among all delegators. |
Zoomed out view of the issueThe increase in ED (min_balance) decreases the rewardable balance for every pool, the balance that pool thinks has already been rewarded. For some pools where we don't see this error, it would happen if new staking reward (or manual top-up by Ross) covered it before the reward pool was updated post the increase in ED. In ideal scenario, the ED balance is covered by the creator while creating the pool. The manual top up also does not work if reward counter has already been updated since the ED change resulting in deficit. Proposed fix
Good thing about this is future increases in ED could be handled gracefully via this without any genuine reward lost by pool members.
Bad thing about this: We are essentially claiming part of rewards of the pool without it being distributed to the pool members.
|
hey @Ank4n any progress on this? If we're not sure which approach maybe we can ask in element or the next frame steering |
I am in favour of the runtime upgrade fix 👍 |
None of the proposed solution is perfect tbh. I am waiting to discuss this with the Staking team, but great suggestion, I can bring this up in the next frame steering. |
A runtime upgrade is a one-off fix, and will require us to do more work the next time ED changes. Given this, I am in favor of a permissionelss transaction that can be executed with bots.
Note that the ED that is put into any reward account is technically the responsibility of the pool operator to keep in there. So, regardless of the approach, the right flow, assuming you make the permissionless transaction
In principle, this is similar to |
Part of deficit was repaid by the staking rewards (depending on when the pool points changed after ED update). Technically this means even pools which are not showing deficit, should get a top up that comes from the pool operator. It might be difficult to do now since we don't track the original ED when the pool was created. But the real fix should start tracking it for future changes. It should also allow unbonding the difference by the depositor if ED has decreased. For the existing pools that have some deficit, may be we don't have to get the perfect solution out and just get the current deficit fixed. This could be a dispatchable function doing what try state is doing, calculate reward of each pool member and hence the deficit in the reward account and allow a permissionless topup. Does that make sense? I agree this is in principal needs similar solution as MinCreateBond. |
Also note that there is another way to fix the issue for future (which I personally like) but it won't fix the deficits of the existing pools. If we never allow |
We certainly cannot iterate over all pool members of a pool in a dispatchable. |
This is an interesting fix and one that we can explore. If this is the long term approach, I agree that a one-off migration might be better and then we won't deal with this ever again. If not, I am still of the opinion that a one-off migration is too short sighted. |
Closes paritytech/polkadot-sdk#158 In our last FRAME call it was discussed that a likely solution to the ED imbalances is lazily fixing the pools as they are interacted with. So, we should add some tiny tolerance to the try-state checks so next time there's an ED change they don't start failing until they've all been interacted with. ### Update 12 Sept Rather than adding tolerance, have replaced the `ensure` with a warning. --------- Co-authored-by: Ankan <[email protected]>
closes #158. partially addresses #226. Instead of fragile calculation of current balance by looking at `free balance - ED`, Nomination Pool now freezes ED in the pool reward account to restrict an account from going below minimum balance. This also has a nice side effect that if ED changes, we know how much is the imbalance in ED frozen in the pool and the current required ED. A pool operator can diligently top up the pool with the deficit in ED or vice versa, withdraw the excess they transferred to the pool. ## Notable changes - New call `adjust_pool_deposit`: Allows to top up the deficit or withdraw the excess deposited funds to the pool. - Uses Fungible trait (instead of Currency trait). Since NP was not doing any locking/reserving previously, no migration is needed for this. - One time migration of freezing ED from each of the existing pools (not very PoV friendly but fine for relay chain).
Closes paritytech#158 In our last FRAME call it was discussed that a likely solution to the ED imbalances is lazily fixing the pools as they are interacted with. So, we should add some tiny tolerance to the try-state checks so next time there's an ED change they don't start failing until they've all been interacted with. ### Update 12 Sept Rather than adding tolerance, have replaced the `ensure` with a warning. --------- Co-authored-by: Ankan <[email protected]>
closes paritytech#158. partially addresses paritytech#226. Instead of fragile calculation of current balance by looking at `free balance - ED`, Nomination Pool now freezes ED in the pool reward account to restrict an account from going below minimum balance. This also has a nice side effect that if ED changes, we know how much is the imbalance in ED frozen in the pool and the current required ED. A pool operator can diligently top up the pool with the deficit in ED or vice versa, withdraw the excess they transferred to the pool. ## Notable changes - New call `adjust_pool_deposit`: Allows to top up the deficit or withdraw the excess deposited funds to the pool. - Uses Fungible trait (instead of Currency trait). Since NP was not doing any locking/reserving previously, no migration is needed for this. - One time migration of freezing ED from each of the existing pools (not very PoV friendly but fine for relay chain).
* exchange benchmarks: framework * updated comment about tx size Co-authored-by: Tomasz Drwięga <[email protected]>
* exchange benchmarks: framework * updated comment about tx size Co-authored-by: Tomasz Drwięga <[email protected]>
* exchange benchmarks: framework * updated comment about tx size Co-authored-by: Tomasz Drwięga <[email protected]>
* exchange benchmarks: framework * updated comment about tx size Co-authored-by: Tomasz Drwięga <[email protected]>
* exchange benchmarks: framework * updated comment about tx size Co-authored-by: Tomasz Drwięga <[email protected]>
* exchange benchmarks: framework * updated comment about tx size Co-authored-by: Tomasz Drwięga <[email protected]>
* exchange benchmarks: framework * updated comment about tx size Co-authored-by: Tomasz Drwięga <[email protected]>
* exchange benchmarks: framework * updated comment about tx size Co-authored-by: Tomasz Drwięga <[email protected]>
* exchange benchmarks: framework * updated comment about tx size Co-authored-by: Tomasz Drwięga <[email protected]>
* exchange benchmarks: framework * updated comment about tx size Co-authored-by: Tomasz Drwięga <[email protected]>
* exchange benchmarks: framework * updated comment about tx size Co-authored-by: Tomasz Drwięga <[email protected]>
Description of bug
A try-state check is failing on Kusama
Failing invariant:
https://github.com/paritytech/substrate/blob/9e8b2f63fb57c5d0fd45da1478508a4509d530e6/frame/nomination-pools/src/lib.rs#L3135-L3139
Polkadot also has a failing invariant:
https://github.com/paritytech/substrate/blob/9e8b2f63fb57c5d0fd45da1478508a4509d530e6/frame/collective/src/lib.rs#L1038-L1041
Reproduce
Clone
polkadot
andsubstrate
into the same dirSync Kusama (or use a remote node on the next step)
Execute
TODO
The text was updated successfully, but these errors were encountered: