-
Notifications
You must be signed in to change notification settings - Fork 699
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
pallet-staking: track total unstaking amount #441
Comments
Thinking about this, do you want to do this in a separate pallet or within the tracker? |
Having thought about it more, I am leaning toward it being in staking. But the final verdict can probably come after a bit of prototyping. |
I was thinking about this. It's indeed not very useful to do this in an EventHandler, because all of this is going to happen in |
This is easier said that done. Once I see us executing it successfully for something else, I would happily consider it as "just another migration". |
About freezing the calls of a pallet, the But even if this works, the overhead of it is probably waaaay too much. Better just do it in the pallet. |
I wanna help out if it’s ok. Trying to make sense of this. The balance of an account that is being unstaked is stored on chain, but not the sum. We could either calculate it on the fly, or store the sum somewhere and update it on change of the unlocking queue. I guess it depends on when and how ofter the value is read, also how often the queue is updated. I don’t see the whole picture so I can’t tell. Either way, it seems like it should be done in
Judging from this part (if the statement is still applicable), I assume you want to store the sum on chain. I imagine the tricky part is to somehow freeze the unlocking queue until after the initial value is calculated, right? Overall, the migration part is still vague to me. I’m brand new to Substrate, so what’s obvious for you guys may not be so obvious for me. Care to elaborate a bit on these if it’s not too much trouble? :)) |
We have individual ledgers and we want to store the global sum of unbonding stake as a separate storage item. From top of my head, we will need to modify this value everytime there is a new
The tricky part is, we need to initialise this value which does not exist right now. The calculation of this might not be possible in one block (since we need to iterate through all ledgers and its unlocking queue), and if we do across multiple blocks, we need to make sure the values of unbonding do not change while we are still calculating this (hence a need to freeze unbonding/withdraw or more simply all staking operations). The PR I linked above did a similar thing in one block and I would suggest to implement it similarly (single block migration). Once you have that, we could try benchmarking and see if it is feasible with one block or to try converting it into a multi-block. We also have a multi-block migration PR hopefully soon to be merged that can help with it. Lmk if you have further questions. |
There're two states after unbonding: being-unlocked and unlocked. From your explanation, I presume the new value should take account of both cases, correct? If so, would the name |
Once its unlocked, it is free balance and does not need to be tracked (or in other words removed from our tracker when unlock happens). |
Sorry for the inaccurate terms. 😉 After unstaking some amount, it enters the unbonding period, during which we couldn't withdraw yet, let's call the total of this X. After the unbonding period, then we could withdraw, let's call the total of what haven't been withdrawn Y. I presume the new value should track X+Y, correct? |
I agree with @Ank4n that the tricky part in this task is to ensure the migrations are done correctly and if done in a multi-block fashion, the final values do not get out of sync.
This seems correct to me but probably it is unnecessarily complicated to separate the unlocking pre and post unbounding period. The goal is keep a storage map with all updated sum of |
In staking, we have a mapping as such:
AccountId -> Ledger
wherebyLedger { active, total }
. What we need is a tracker over thesum(Ledger::active)
andsum(Ledger::total)
in the entire map. Subtracting the two should give the total unbonding amount.As for the implementation, once #1654 is done, staking will have fully implement the
OnStakingUpdate
. This can be implemented as a component that is implementingOnStakingUpdate
and using that.I prefer an implementation that is actually just a
stuct
implementing the types, which can easily be embedded in a pallet. Then, we can decide to position this in the existing staking pallet or elsewhere.I imagine we can use it to:
The text was updated successfully, but these errors were encountered: