-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[Feature] StakeTracker P1 - VotersList #13079
Conversation
@kianenigma This does not have dedicated tests for StakeTracker yet, but it runs Staking tests against StakeTracker and it all works. Separate unit-tests for tracker are going to be introduced, however I think we shall retain the Staking part of those tests too as Staking relies on the outcome of the VotersList. There is one test that is failing: https://github.com/paritytech/substrate/pull/13079/files#diff-64c049b4e94a55bdeaf757c725cf7d1df623b754557af4ced157024a943c4703R5145 that I think has to be removed. |
bot rebase |
Rebased |
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. |
bot rebase |
Rebased |
bot rebase |
Rebased |
} | ||
|
||
impl<T: Config> OnStakingUpdate<T::AccountId, BalanceOf<T>> for Pallet<T> { | ||
fn on_stake_update(who: &T::AccountId, _: Option<Stake<T::AccountId, BalanceOf<T>>>) { |
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.
is who
controller or stash? We decided to try and move all things in the StakingApi
and OnStakingUpdate
to use stash.
This also makes me wonder: T::Staking::stake
is queried by the stash, and return the stash to you as well? that does not seem reasonable.
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.
Yes, who
is a stash. Indeed, it does not make a whole lot of sense. stash
can indeed be removed from Stake
struct as it's redundant.
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.
Gave this a good review again, the logic seems good, but I am still not content with some of the testing details, and given that this is among the "critical" work in staking, I don't want to sacrifice it.
- The testing setup is both partially wrong and unnecessarily complex. We are keeping track of balances, which is irrelevant entirely.
- We are registering some accounts as validators and nominators notionally, but we are actually not making them go through the real code path.
- The way that the accounts is setup could be made better.
I've demonstrated this in https://github.com/paritytech/substrate/compare/ru/feature/stake-tracker-voter...kiz-voter-list-stuff?expand=1
Other than the bot, another testing idea is to use #12896 in the companion, and make sure that we can produce enough blocks to create the snapshot for the next election. This is a pretty good use case of the fast-forward
subcommand.
} | ||
} | ||
|
||
/// A wrapper for a given `SortedListProvider` that introduces defensive checks for insert, update |
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.
/// A wrapper for a given `SortedListProvider` that introduces defensive checks for insert, update | |
/// A wrapper for a given `SortedListProvider` that introduces defensive checks for insert, update |
} | ||
|
||
/// A wrapper for a given `SortedListProvider` that introduces defensive checks for insert, update | ||
/// and remove operations, suggesting that it's read-only, except for unsafe operations. |
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.
Maybe you could elaborate more what are unsafe operations and why we need them here? It sounds important
|
||
// It is the caller's problem to make sure each of events is emitted in the right context, therefore | ||
// we test each event for all the stakers (validators + nominators). | ||
|
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.
bot rebase |
Error: Response error (status 404 Not Found):
|
I will re-open this from a new PR, based on your commits. Thank you Roman for your contribution 💯 |
@kianenigma I'm planning to finish this up in a new PR coming from my fork sometime soon. |
Original issue: paritytech/polkadot-sdk#443
Splitting up #12744
polkadot companion: paritytech/polkadot#6527
Terminology
Approval stake - a sum of all the nominator/nomination pools stakes that are backing this validator + self-stake.
Goals
The original goal of this series of PR's is to introduce a list of validators sorted by their approval stake, therefore eliminating the need for Max Validator Intentions parameter. This way we'll be able to look into top x validators in the list to get a set of electable ones.
While doing that we also introduce a concept of EventListeners into Staking, that would allow us to hook into various staking methods acting upon emitted events. In this particular case this allows us to delegate the sorted list maintenance to a 3rd party EventListener.
Technical details
This PR introduces a new Staking-related abstraction called
OnStakingUpdate
that basically provides the ability to subscribe to certain events that Staking fires and act upon them.The first event listener implementing this interface, also introduced in this PR, is called
pallet-stake-tracker
which currently takes care of maintainingVoterList
(a sorted list of nominators and validator's self-stake), effectively moving this logic out of Staking. It's also supplying Staking with a read-only version of this list, which is currently implemented by adding some defensive checks intoinsert/updated/remove
methods.Some other things that were introduced in this PR include:
OnStakingUpdate
events are being fired with the right arguments.update/insert/remove
methods and only leavesunsafe
methods to allow for easier benchmarking/testing/migrations.CurrencyToVote
moved fromframe_support
toprimitives/staking
.