Skip to content

Commit 7a87f2b

Browse files
authored
refactor(x/gov): set environment in context for legacy proposals (#20521)
1 parent 61da5d1 commit 7a87f2b

4 files changed

Lines changed: 11 additions & 2 deletions

File tree

UPGRADING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ To learn more see the [docs](https://docs.cosmos.network/main/learn/advanced/tra
688688
* mention changes with sdk context removal
689689
* mention changes with environment
690690
* mention changes with environment in context in interfaces
691+
* mention legacy proposal in gov when using server/v2 if using sdk context must be rewritten
691692
-->
692693

693694
#### `**all**`

x/gov/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
3838

3939
### Improvements
4040

41+
* [#20521](https://github.com/cosmos/cosmos-sdk/pull/20521) Legacy proposals can now access the `appmodule.Environment` present in the `context.Context` of the handler. This is useful when migrating to server/v2 and removing the sdk context dependency.
4142
* [#19741](https://github.com/cosmos/cosmos-sdk/pull/19741) Add `ExpeditedQuorum` parameter specifying a minimum quorum for expedited proposals, that can differ from the regular quorum.
4243
* [#19352](https://github.com/cosmos/cosmos-sdk/pull/19352) `TallyResult` include vote options counts. Those counts replicates the now deprecated (but not removed) yes, no, abstain and veto count fields.
4344
* [#18976](https://github.com/cosmos/cosmos-sdk/pull/18976) Log and send an event when a proposal deposit refund or burn has failed.

x/gov/keeper/msg_server.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"google.golang.org/protobuf/runtime/protoiface"
99

10+
corecontext "cosmossdk.io/core/context"
1011
"cosmossdk.io/core/event"
1112
"cosmossdk.io/errors"
1213
"cosmossdk.io/math"
@@ -209,7 +210,10 @@ func (k msgServer) ExecLegacyContent(ctx context.Context, msg *v1.MsgExecLegacyC
209210
}
210211

211212
handler := k.Keeper.legacyRouter.GetRoute(content.ProposalRoute())
212-
if err := handler(ctx, content); err != nil {
213+
214+
// NOTE: the support of legacy gov proposal in server/v2 is different than for baseapp.
215+
// Legacy proposal in server/v2 can only access services provided by the gov module environment.
216+
if err := handler(context.WithValue(ctx, corecontext.EnvironmentContextKey, k.Environment), content); err != nil {
213217
return nil, errors.Wrapf(govtypes.ErrInvalidProposalContent, "failed to run legacy handler %s, %+v", content.ProposalRoute(), err)
214218
}
215219

x/gov/keeper/proposal.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"cosmossdk.io/collections"
13+
corecontext "cosmossdk.io/core/context"
1314
"cosmossdk.io/core/event"
1415
errorsmod "cosmossdk.io/errors"
1516
sdkmath "cosmossdk.io/math"
@@ -113,7 +114,9 @@ func (k Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata
113114

114115
if err = k.BranchService.Execute(ctx, func(ctx context.Context) error {
115116
handler := k.legacyRouter.GetRoute(content.ProposalRoute())
116-
if err := handler(ctx, content); err != nil {
117+
// NOTE: the support of legacy gov proposal in server/v2 is different than for baseapp.
118+
// Legacy proposal in server/v2 can only access services provided by the gov module environment.
119+
if err := handler(context.WithValue(ctx, corecontext.EnvironmentContextKey, k.Environment), content); err != nil {
117120
return types.ErrInvalidProposalContent.Wrapf("failed to run legacy handler %s, %+v", content.ProposalRoute(), err)
118121
}
119122

0 commit comments

Comments
 (0)