-
Notifications
You must be signed in to change notification settings - Fork 769
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
Refactors the OnStakingUpdate
trait
#2839
Conversation
bot fmt |
@gpestana https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/4828478 was started for your command Comment |
@gpestana Command |
OnStakingUpdate
OnStakingUpdate
trait
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.
LGTM, useful additions.
@@ -123,15 +133,15 @@ pub trait OnStakingUpdate<AccountId, Balance> { | |||
/// Fired when someone sets their intention to validate. | |||
/// | |||
/// Note validator preference changes are not communicated, but could be added if needed. | |||
fn on_validator_add(_who: &AccountId) {} | |||
fn on_validator_add(_who: &AccountId, _self_stake: Option<Stake<Balance>>) {} | |||
|
|||
/// Fired when an existing validator updates their preferences. | |||
/// | |||
/// Note validator preference changes are not communicated, but could be added if needed. | |||
fn on_validator_update(_who: &AccountId) {} |
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.
Wouldn't this also need old and new self stake params?
fn on_stake_update(_who: &AccountId, _prev_stake: Option<Stake<Balance>>) {} | ||
fn on_stake_update( | ||
_who: &AccountId, | ||
_prev_stake: Option<Stake<Balance>>, |
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.
Should we have both _prev_stake
and _stake
as same type? Either Stake<Balance>
or Option<Stake<Balance>>
. If Stake<Balance>
, we can pass a zero value.
Closing as these changes have been included in the stake tracker PR #1933 and only make sense in that context. |
* fix on-demand parachain relay behavior during target chain reorgs * fix compilation
This PR refactors the
OnStakingUpdate
trait to make its usage simpler and less error prone in the context of pallet-staking and the pallet-stake-tracker. The main goal is to make readily available more information/data required by theOnStakingUpdate
listener (e.g. new stake onon_stake_update
) through the interface methods.With this refactor, the event emitter needs to explicitly call the events with more information about the event. The advantage is that this new interface design prevents potential issues with data sync, e.g. the event emitter does not necessarily need to update the staking state before emitting the events and the
OnStakingUpdate
implementor does not need to rely as much on the staking interface, making the interface less error prone.Examples
Currently, on the
OnStakingUpdate
implemetor, we havewith the new interface design, the implementor will have all the most important information implicitly in the method interface:
Although the new design is less error prone, it is more opinionated and the design is highly affected by how the staking pallet will use this interface. Evidently, it is not possible to cover all the inputs that all the
OnStakingUpdate
implementors may need (depending on the use case), but the refactor aims at striking a good balance between safety for the usage in the context of staking and generality.