From 2a15457a99fe1d48eda67adce75d779f511d1f17 Mon Sep 17 00:00:00 2001 From: Vlad J Date: Mon, 1 Dec 2025 16:05:25 -0500 Subject: [PATCH] feat!(gov): add proposer address to hooks (#25617) Co-authored-by: Alex | Cosmos Labs --- CHANGELOG.md | 1 + UPGRADING.md | 20 +++++++++++++++++++- x/gov/keeper/hooks_test.go | 2 +- x/gov/keeper/proposal.go | 2 +- x/gov/types/expected_keepers.go | 10 +++++----- x/gov/types/hooks.go | 4 ++-- 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09ab1fe0a7..35ed1ab7f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/UPGRADING.md b/UPGRADING.md index a8e68eed50..ff7c053b15 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -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. \ No newline at end of file +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 +} +``` \ No newline at end of file diff --git a/x/gov/keeper/hooks_test.go b/x/gov/keeper/hooks_test.go index 4a746ad7c6..17ebf5e47c 100644 --- a/x/gov/keeper/hooks_test.go +++ b/x/gov/keeper/hooks_test.go @@ -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 } diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index bbedea6aca..f211e4d764 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -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 } diff --git a/x/gov/types/expected_keepers.go b/x/gov/types/expected_keepers.go index e2ee3a7748..5f6314d6d3 100644 --- a/x/gov/types/expected_keepers.go +++ b/x/gov/types/expected_keepers.go @@ -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 } diff --git a/x/gov/types/hooks.go b/x/gov/types/hooks.go index 886e42dfb7..05a276fc20 100644 --- a/x/gov/types/hooks.go +++ b/x/gov/types/hooks.go @@ -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