Skip to content

Commit 690ba1d

Browse files
feat!(gov): add proposer address to hooks (cosmos#25617)
2 parents 835b185 + 2a15457 commit 690ba1d

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4848
* (crypto) [#24414](https://github.com/cosmos/cosmos-sdk/pull/24414) Remove sr25519 support, since it was removed in CometBFT v1.x (see: CometBFT [#3646](https://github.com/cometbft/cometbft/pull/3646)).
4949
* (x/gov) [#25615](https://github.com/cosmos/cosmos-sdk/pull/25615) Decouple `x/gov` from `x/staking` by making `CalculateVoteResultsAndVotingPowerFn` a required parameter to `keeper.NewKeeper` instead of `StakingKeeper`.
5050
`BondedTokens` has been renamed to `ValidatorPower` and `TotalBondedTokens` has been renamed to `TotalValidatorPower` to allow for multiple validator power representations.
51+
* (x/gov) [#25617](https://github.com/cosmos/cosmos-sdk/pull/25617) `AfterProposalSubmission` hook now includes proposer address as a parameter.
5152
* (x/gov) [#25616](https://github.com/cosmos/cosmos-sdk/pull/25616) `DistrKeeper` `x/distribution` is now optional. Genesis validation ensures `distrKeeper` is set if distribution module is used as proposal cancel destination.
5253

5354
### Features

UPGRADING.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,22 @@ govKeeper := keeper.NewKeeper(
4444
)
4545
```
4646

47-
For applications using depinject, the governance module now accepts an optional `CalculateVoteResultsAndVotingPowerFn`. If not provided, it will use the `StakingKeeper` (also optional) to create the default function.
47+
For applications using depinject, the governance module now accepts an optional `CalculateVoteResultsAndVotingPowerFn`. If not provided, it will use the `StakingKeeper` (also optional) to create the default function.
48+
49+
### GovHooks Interface
50+
51+
The `AfterProposalSubmission` hook now includes the proposer address as a parameter.
52+
53+
**Before:**
54+
```go
55+
func (h MyGovHooks) AfterProposalSubmission(ctx context.Context, proposalID uint64) error {
56+
// implementation
57+
}
58+
```
59+
60+
**After:**
61+
```go
62+
func (h MyGovHooks) AfterProposalSubmission(ctx context.Context, proposalID uint64, proposerAddr sdk.AccAddress) error {
63+
// implementation
64+
}
65+
```

x/gov/keeper/hooks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type MockGovHooksReceiver struct {
2727
AfterProposalVotingPeriodEndedValid bool
2828
}
2929

30-
func (h *MockGovHooksReceiver) AfterProposalSubmission(ctx context.Context, proposalID uint64) error {
30+
func (h *MockGovHooksReceiver) AfterProposalSubmission(ctx context.Context, proposalID uint64, proposerAddr sdk.AccAddress) error {
3131
h.AfterProposalSubmissionValid = true
3232
return nil
3333
}

x/gov/keeper/proposal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (k Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata
114114
}
115115

116116
// called right after a proposal is submitted
117-
err = k.Hooks().AfterProposalSubmission(ctx, proposalID)
117+
err = k.Hooks().AfterProposalSubmission(ctx, proposalID, proposer)
118118
if err != nil {
119119
return v1.Proposal{}, err
120120
}

x/gov/types/expected_keepers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ type BankKeeper interface {
6767

6868
// GovHooks event hooks for governance proposal object (noalias)
6969
type GovHooks interface {
70-
AfterProposalSubmission(ctx context.Context, proposalID uint64) error // Must be called after proposal is submitted
71-
AfterProposalDeposit(ctx context.Context, proposalID uint64, depositorAddr sdk.AccAddress) error // Must be called after a deposit is made
72-
AfterProposalVote(ctx context.Context, proposalID uint64, voterAddr sdk.AccAddress) error // Must be called after a vote on a proposal is cast
73-
AfterProposalFailedMinDeposit(ctx context.Context, proposalID uint64) error // Must be called when proposal fails to reach min deposit
74-
AfterProposalVotingPeriodEnded(ctx context.Context, proposalID uint64) error // Must be called when proposal's finishes it's voting period
70+
AfterProposalSubmission(ctx context.Context, proposalID uint64, proposerAddr sdk.AccAddress) error // Must be called after proposal is submitted
71+
AfterProposalDeposit(ctx context.Context, proposalID uint64, depositorAddr sdk.AccAddress) error // Must be called after a deposit is made
72+
AfterProposalVote(ctx context.Context, proposalID uint64, voterAddr sdk.AccAddress) error // Must be called after a vote on a proposal is cast
73+
AfterProposalFailedMinDeposit(ctx context.Context, proposalID uint64) error // Must be called when proposal fails to reach min deposit
74+
AfterProposalVotingPeriodEnded(ctx context.Context, proposalID uint64) error // Must be called when proposal's finishes it's voting period
7575
}
7676

7777
type GovHooksWrapper struct{ GovHooks }

x/gov/types/hooks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ func NewMultiGovHooks(hooks ...GovHooks) MultiGovHooks {
1616
return hooks
1717
}
1818

19-
func (h MultiGovHooks) AfterProposalSubmission(ctx context.Context, proposalID uint64) error {
19+
func (h MultiGovHooks) AfterProposalSubmission(ctx context.Context, proposalID uint64, proposerAddr sdk.AccAddress) error {
2020
var errs error
2121
for i := range h {
22-
errs = errors.Join(errs, h[i].AfterProposalSubmission(ctx, proposalID))
22+
errs = errors.Join(errs, h[i].AfterProposalSubmission(ctx, proposalID, proposerAddr))
2323
}
2424

2525
return errs

0 commit comments

Comments
 (0)