feat!: add error handling to staking hooks (#9571)
<!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description - Adds error handling for staking hooks <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
+29
-17
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing/types"
|
||||
)
|
||||
|
||||
func (k Keeper) AfterValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, _ sdk.ValAddress) {
|
||||
func (k Keeper) AfterValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, _ sdk.ValAddress) error {
|
||||
// Update the signing info start height or create a new signing info
|
||||
_, found := k.GetValidatorSigningInfo(ctx, address)
|
||||
if !found {
|
||||
@@ -23,6 +23,8 @@ func (k Keeper) AfterValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, _
|
||||
)
|
||||
k.SetValidatorSigningInfo(ctx, address, signingInfo)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterValidatorCreated adds the address-pubkey relation when a validator is created.
|
||||
@@ -32,14 +34,14 @@ func (k Keeper) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) e
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
k.AddPubkey(ctx, consPk)
|
||||
|
||||
return nil
|
||||
return k.AddPubkey(ctx, consPk)
|
||||
}
|
||||
|
||||
// AfterValidatorRemoved deletes the address-pubkey relation when a validator is removed,
|
||||
func (k Keeper) AfterValidatorRemoved(ctx sdk.Context, address sdk.ConsAddress) {
|
||||
func (k Keeper) AfterValidatorRemoved(ctx sdk.Context, address sdk.ConsAddress) error {
|
||||
k.deleteAddrPubkeyRelation(ctx, crypto.Address(address))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Hooks wrapper struct for slashing keeper
|
||||
@@ -55,24 +57,34 @@ func (k Keeper) Hooks() Hooks {
|
||||
}
|
||||
|
||||
// Implements sdk.ValidatorHooks
|
||||
func (h Hooks) AfterValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) {
|
||||
h.k.AfterValidatorBonded(ctx, consAddr, valAddr)
|
||||
func (h Hooks) AfterValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
|
||||
return h.k.AfterValidatorBonded(ctx, consAddr, valAddr)
|
||||
}
|
||||
|
||||
// Implements sdk.ValidatorHooks
|
||||
func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, _ sdk.ValAddress) {
|
||||
h.k.AfterValidatorRemoved(ctx, consAddr)
|
||||
func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, _ sdk.ValAddress) error {
|
||||
return h.k.AfterValidatorRemoved(ctx, consAddr)
|
||||
}
|
||||
|
||||
// Implements sdk.ValidatorHooks
|
||||
func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) {
|
||||
h.k.AfterValidatorCreated(ctx, valAddr)
|
||||
func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) error {
|
||||
return h.k.AfterValidatorCreated(ctx, valAddr)
|
||||
}
|
||||
|
||||
func (h Hooks) AfterValidatorBeginUnbonding(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) {}
|
||||
func (h Hooks) BeforeValidatorModified(_ sdk.Context, _ sdk.ValAddress) {}
|
||||
func (h Hooks) BeforeDelegationCreated(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {}
|
||||
func (h Hooks) BeforeDelegationSharesModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {}
|
||||
func (h Hooks) BeforeDelegationRemoved(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {}
|
||||
func (h Hooks) AfterDelegationModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {}
|
||||
func (h Hooks) BeforeValidatorSlashed(_ sdk.Context, _ sdk.ValAddress, _ sdk.Dec) {}
|
||||
func (h Hooks) AfterValidatorBeginUnbonding(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error {
|
||||
return nil
|
||||
}
|
||||
func (h Hooks) BeforeValidatorModified(_ sdk.Context, _ sdk.ValAddress) error { return nil }
|
||||
func (h Hooks) BeforeDelegationCreated(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) error {
|
||||
return nil
|
||||
}
|
||||
func (h Hooks) BeforeDelegationSharesModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) error {
|
||||
return nil
|
||||
}
|
||||
func (h Hooks) BeforeDelegationRemoved(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) error {
|
||||
return nil
|
||||
}
|
||||
func (h Hooks) AfterDelegationModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) error {
|
||||
return nil
|
||||
}
|
||||
func (h Hooks) BeforeValidatorSlashed(_ sdk.Context, _ sdk.ValAddress, _ sdk.Dec) error { return nil }
|
||||
|
||||
Reference in New Issue
Block a user