Skip to content

Commit

Permalink
refactor(x/gov): set environment in context for legacy proposals (#20521
Browse files Browse the repository at this point in the history
)
  • Loading branch information
julienrbrt authored Jun 3, 2024
1 parent 61da5d1 commit 7a87f2b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ To learn more see the [docs](https://docs.cosmos.network/main/learn/advanced/tra
* mention changes with sdk context removal
* mention changes with environment
* mention changes with environment in context in interfaces
* mention legacy proposal in gov when using server/v2 if using sdk context must be rewritten
-->

#### `**all**`
Expand Down
1 change: 1 addition & 0 deletions x/gov/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* [#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.
* [#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.
* [#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.
* [#18976](https://github.com/cosmos/cosmos-sdk/pull/18976) Log and send an event when a proposal deposit refund or burn has failed.
Expand Down
6 changes: 5 additions & 1 deletion x/gov/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

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

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

handler := k.Keeper.legacyRouter.GetRoute(content.ProposalRoute())
if err := handler(ctx, content); err != nil {

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

Expand Down
5 changes: 4 additions & 1 deletion x/gov/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

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

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

Expand Down

0 comments on commit 7a87f2b

Please sign in to comment.