feat!(gov): add proposer address to hooks (#25617)

Co-authored-by: Alex | Cosmos Labs <alex@cosmoslabs.io>
This commit is contained in:
Vlad J 2025-12-01 16:05:25 -05:00 committed by GitHub
parent 8307749377
commit 2a15457a99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 29 additions and 10 deletions

View File

@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (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)).
* (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`.
`BondedTokens` has been renamed to `ValidatorPower` and `TotalBondedTokens` has been renamed to `TotalValidatorPower` to allow for multiple validator power representations.
* (x/gov) [#25617](https://github.com/cosmos/cosmos-sdk/pull/25617) `AfterProposalSubmission` hook now includes proposer address as a parameter.
* (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.
### Features

View File

@ -44,4 +44,22 @@ govKeeper := keeper.NewKeeper(
)
```
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.
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.
### GovHooks Interface
The `AfterProposalSubmission` hook now includes the proposer address as a parameter.
**Before:**
```go
func (h MyGovHooks) AfterProposalSubmission(ctx context.Context, proposalID uint64) error {
// implementation
}
```
**After:**
```go
func (h MyGovHooks) AfterProposalSubmission(ctx context.Context, proposalID uint64, proposerAddr sdk.AccAddress) error {
// implementation
}
```

View File

@ -27,7 +27,7 @@ type MockGovHooksReceiver struct {
AfterProposalVotingPeriodEndedValid bool
}
func (h *MockGovHooksReceiver) AfterProposalSubmission(ctx context.Context, proposalID uint64) error {
func (h *MockGovHooksReceiver) AfterProposalSubmission(ctx context.Context, proposalID uint64, proposerAddr sdk.AccAddress) error {
h.AfterProposalSubmissionValid = true
return nil
}

View File

@ -114,7 +114,7 @@ func (k Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata
}
// called right after a proposal is submitted
err = k.Hooks().AfterProposalSubmission(ctx, proposalID)
err = k.Hooks().AfterProposalSubmission(ctx, proposalID, proposer)
if err != nil {
return v1.Proposal{}, err
}

View File

@ -67,11 +67,11 @@ type BankKeeper interface {
// GovHooks event hooks for governance proposal object (noalias)
type GovHooks interface {
AfterProposalSubmission(ctx context.Context, proposalID uint64) error // Must be called after proposal is submitted
AfterProposalDeposit(ctx context.Context, proposalID uint64, depositorAddr sdk.AccAddress) error // Must be called after a deposit is made
AfterProposalVote(ctx context.Context, proposalID uint64, voterAddr sdk.AccAddress) error // Must be called after a vote on a proposal is cast
AfterProposalFailedMinDeposit(ctx context.Context, proposalID uint64) error // Must be called when proposal fails to reach min deposit
AfterProposalVotingPeriodEnded(ctx context.Context, proposalID uint64) error // Must be called when proposal's finishes it's voting period
AfterProposalSubmission(ctx context.Context, proposalID uint64, proposerAddr sdk.AccAddress) error // Must be called after proposal is submitted
AfterProposalDeposit(ctx context.Context, proposalID uint64, depositorAddr sdk.AccAddress) error // Must be called after a deposit is made
AfterProposalVote(ctx context.Context, proposalID uint64, voterAddr sdk.AccAddress) error // Must be called after a vote on a proposal is cast
AfterProposalFailedMinDeposit(ctx context.Context, proposalID uint64) error // Must be called when proposal fails to reach min deposit
AfterProposalVotingPeriodEnded(ctx context.Context, proposalID uint64) error // Must be called when proposal's finishes it's voting period
}
type GovHooksWrapper struct{ GovHooks }

View File

@ -16,10 +16,10 @@ func NewMultiGovHooks(hooks ...GovHooks) MultiGovHooks {
return hooks
}
func (h MultiGovHooks) AfterProposalSubmission(ctx context.Context, proposalID uint64) error {
func (h MultiGovHooks) AfterProposalSubmission(ctx context.Context, proposalID uint64, proposerAddr sdk.AccAddress) error {
var errs error
for i := range h {
errs = errors.Join(errs, h[i].AfterProposalSubmission(ctx, proposalID))
errs = errors.Join(errs, h[i].AfterProposalSubmission(ctx, proposalID, proposerAddr))
}
return errs