Skip to content
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

R4R: Rename hooks from Before -> Pre and On -> Post #3076

Merged
merged 5 commits into from
Jan 9, 2019

Conversation

jackzampolin
Copy link
Member

Fixes #2538

This PR renames the hooks in the SDK to match the agreed upon format in the linked issue.

cc @rigelrozanski @cwgoes

@jackzampolin jackzampolin changed the title Rename hooks from Before -> Pre and On -> Post R4R: Rename hooks from Before -> Pre and On -> Post Dec 10, 2018
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's a breaking SDK API change, I think this warrants a pending log update, otherwise, LGTM.

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These names aren't right, I think we want Pre/Post to reflect whether or not the store has been updated.

Also needs a PENDING.md update.

@@ -163,7 +163,7 @@ func handleMsgEditValidator(ctx sdk.Context, msg types.MsgEditValidator, k keepe
return err.Result()
}
validator.Commission = commission
k.OnValidatorModified(ctx, msg.ValidatorAddr)
k.PostValidatorModified(ctx, msg.ValidatorAddr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't post-modification? Changes haven't been written to the store yet (line 169).

@@ -398,9 +398,9 @@ func (k Keeper) Delegate(ctx sdk.Context, delAddr sdk.AccAddress, bondAmt sdk.Co

// call the appropriate hook if present
if found {
k.OnDelegationSharesModified(ctx, delAddr, validator.OperatorAddr)
k.PostDelegationSharesModified(ctx, delAddr, validator.OperatorAddr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't post-modification.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the hooks were On something. I'll have to read through the code in a bit more detail to figure out which ones are Pre.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the previous names were (are) wrong / misleading

} else {
k.OnDelegationCreated(ctx, delAddr, validator.OperatorAddr)
k.PostDelegationCreated(ctx, delAddr, validator.OperatorAddr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't post-modification either.

@fedekunze
Copy link
Collaborator

I only see On -> Post changes here. Maybe the others are missing ? Otherwise we need to change the title

@@ -122,7 +122,7 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k
k.SetValidatorByConsAddr(ctx, validator)
k.SetNewValidatorByPowerIndex(ctx, validator)

k.OnValidatorCreated(ctx, validator.OperatorAddr)
k.PostValidatorCreated(ctx, validator.OperatorAddr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this is post-modification, 👍 )

@@ -81,7 +81,7 @@ func (k Keeper) SetDelegation(ctx sdk.Context, delegation types.Delegation) {

// remove a delegation from store
func (k Keeper) RemoveDelegation(ctx sdk.Context, delegation types.Delegation) {
k.OnDelegationRemoved(ctx, delegation.DelegatorAddr, delegation.ValidatorAddr)
k.PostDelegationRemoved(ctx, delegation.DelegatorAddr, delegation.ValidatorAddr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't post-modification (as you can see by the store.Delete call two lines below)

@@ -431,7 +431,7 @@ func (k Keeper) unbond(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValA
return
}

k.OnDelegationSharesModified(ctx, delAddr, valAddr)
k.PostDelegationSharesModified(ctx, delAddr, valAddr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't post-modification (we set the delegation later in this function)

@@ -81,7 +81,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
// Assert that the validator had updated its ValidatorDistInfo.FeePoolWithdrawalHeight.
// This hook is extremely useful, otherwise lazy accum bugs will be difficult to solve.
if k.hooks != nil {
k.hooks.OnValidatorPowerDidChange(ctx, validator.ConsAddress(), valAddr)
k.hooks.PostValidatorPowerDidChange(ctx, validator.ConsAddress(), valAddr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is post-modification, 👍

@@ -197,7 +197,7 @@ func (k Keeper) bondValidator(ctx sdk.Context, validator types.Validator) types.

// call the bond hook if present
if k.hooks != nil {
k.hooks.OnValidatorBonded(ctx, validator.ConsAddress(), validator.OperatorAddr)
k.hooks.PostValidatorBonded(ctx, validator.ConsAddress(), validator.OperatorAddr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this is post-modification, 👍 )

@@ -232,7 +232,7 @@ func (k Keeper) beginUnbondingValidator(ctx sdk.Context, validator types.Validat

// call the unbond hook if present
if k.hooks != nil {
k.hooks.OnValidatorBeginUnbonding(ctx, validator.ConsAddress(), validator.OperatorAddr)
k.hooks.PostValidatorBeginUnbonding(ctx, validator.ConsAddress(), validator.OperatorAddr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this is post-modification, 👍 )

@@ -204,7 +204,7 @@ func (k Keeper) RemoveValidator(ctx sdk.Context, address sdk.ValAddress) {

// call hook if present
if k.hooks != nil {
k.hooks.OnValidatorRemoved(ctx, validator.ConsAddress(), validator.OperatorAddr)
k.hooks.PostValidatorRemoved(ctx, validator.ConsAddress(), validator.OperatorAddr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this is post-modification, 👍 )

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jackzampolin I've done a thorough review and labeled which hooks should be which, I think (always good to oonfirm - just look at where the store.Set calls are in relation to the hook invocation).

@codecov
Copy link

codecov bot commented Dec 12, 2018

Codecov Report

Merging #3076 into develop will increase coverage by <.01%.
The diff coverage is 50%.

@@             Coverage Diff             @@
##           develop    #3076      +/-   ##
===========================================
+ Coverage    54.85%   54.86%   +<.01%     
===========================================
  Files          133      133              
  Lines         9544     9546       +2     
===========================================
+ Hits          5235     5237       +2     
  Misses        3988     3988              
  Partials       321      321

@jackzampolin
Copy link
Member Author

I've addressed the comments here and properly named the functions (according to @cwgoes). Would be good to get 👀 from @rigelrozanski here

@cwgoes
Copy link
Contributor

cwgoes commented Dec 13, 2018

Merge develop; that should fix the sim.

@jaekwon
Copy link
Contributor

jaekwon commented Dec 19, 2018

Can we do "Before"/"After"? or "Will"/"Did". "Pre"/"Post" seems like they would be overloaded terms in general.

@jackzampolin
Copy link
Member Author

@jaekwon Done. I think this is ready to go in after that.

@cwgoes
Copy link
Contributor

cwgoes commented Dec 21, 2018

LGTM, this needs another review still.

Copy link
Contributor

@rigelrozanski rigelrozanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good - still a few comments which I'd like addressed

Co-Authored-By: jackzampolin <[email protected]>
@jackzampolin
Copy link
Member Author

Is this PR waiting on anything @cwgoes @rigelrozanski ? Looks like I've addressed the comments?

@cwgoes
Copy link
Contributor

cwgoes commented Jan 8, 2019

LGTM except linter fails.

@jackzampolin
Copy link
Member Author

Turned off the linter on the affected file. This is ready to go and can be merged whenever.

Copy link
Contributor

@rigelrozanski rigelrozanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jackzampolin just for reference my comments where not fully addressed (I added leftover comments to another issue as well as made one commit) - Generally speaking, somebodies PR comments should only be considered "addressed" once all the the PR comments have been marked as resolved, which was not this case here (nbd obv. - just mentioning)

@rigelrozanski rigelrozanski merged commit b16af44 into develop Jan 9, 2019
@rigelrozanski rigelrozanski deleted the jack/rename-hooks branch January 9, 2019 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants