-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Radically simplify staking logic #2312
Comments
Some ideas for main ideas to classify by: In the case of a new validator, we have a separate function for "pushing the cliff validator down", and etc. I think alot of the bugs come through because the functions aren't small things that are easy to verify independently. |
All for it - I think the conceptualization of staking has expanded dramatically several times - many times we've tended to tack on new thinking without refactoring.. Misc thoughts:
^ this is not a fully conceptualized idea, however I think something a little bit more lazy and along these lines may help A LOT! - what y'all think?? We should setup a call probs Side thought: |
I agree, perhaps we can change alot of the "cliff validator" paradigm. Its unclear to me why the following categorization doesn't suffice: "bonded", "unbonded", "jailed". I don't see a need for the cliff validator abstraction, as long as we keep "bonded" and "unbonded" sorted by power, which shouldn't be expensive. Inserting into a sorted list is logarithmic worst case, if we want to do some fancy predictive stuff #postlaunch, we may even be able to get it to log(log(n)). (Basically rob the idea from https://en.wikipedia.org/wiki/Interpolation_search, and come up with a decent predictor for location within the sorted list) |
(side point we also need to have "unbonding" in that list - important for slashing right) Yeah there is definitely a way to not have the cliff validator term at all without changing much, I think it just means that we need to have a bunch more iterating - which may be okay, maybe a much of the inefficiently that may come from having to iterate over a bunch of records (only retrieve one of them) can be solved on the store side of things. For instance, As far as I can tell there is not easy way to retrieve the "100th" record from the store without iterating over it, but I bet that's a piece of functionality which wouldn't be to difficult to build into the store.
|
During the past few weeks of debugging this code, I can personally say that iteration and the notion of cliff validators are the biggest pain points for debugging. I found the following troublesome when debugging
|
Ideas from the meeting:
|
Its also interesting to note, that doing the lazy evaluation at end block will probably speed up execution under periods of high load. This is because if there are multiple validator set updates, you only have to do one iteration through it. Whereas before the number of iterations may not have been well bounded (e.g. 1 per message in the block), but in the simplest case there wouldn't be any iterations. However, we can easily add a boolean "was there a stake related update this block", and only run through that iteration accordingly. (This is an easy #if-have-time-prelaunch optimization though) |
@ValarDragon - great idea to add an optimization bool for if there was an update or not |
Can we consider removing redelegation as part of this? It seems like pretty clearly non-MVP requirement and just adds complexity. |
I think instant redelegation is a requirement for having a proper decentralized Proof of Stake. Without it, delegation becomes so sticky and the initial validator set gets entrenched. We've also publicly stated on multiple occasions that this is one of the defining unique features of our Proof of Stake implementation. |
I'm going to second @sunnya97 for this, not to mention it's actually a fairly straightforward implementation, which doesn't need to change is already complete - there are very few edge cases. I think by removing and adding it back in later, we are going to generate more work for ourselves in |
Most has been done, closing in favor of the remaining #1402. |
Many of the state machine bugs we've found so far are in the staking module, particularly the
UpdateValidators
iteration cases and the cliff validator optimization logic. The stake keeper (x/stake/keeper
) is generally difficult to understand and reason through - as demonstrated by our inability to catch these issues when writing the code or in review. In part this may be due to writing the code in stages and changing the underlying model several times.Let's first discuss the clearest layout - maintaining the current performance (which is fine) but splitting up the logic much more clearly between self-contained functions with well-defined pre-conditions and post-conditions (most of which ideally can be defensively asserted). In parallel with this we should make sure to compare our code to the staking/slashing spec, which may have fallen a bit behind the implementation in a few places.
cc @rigelrozanski @alexanderbez @ValarDragon
Ref #2298 (comment)
Ref general discussion in #2173
The text was updated successfully, but these errors were encountered: