refactor(x/gov): set environment in context for legacy proposals (#20521)

This commit is contained in:
Julien Robert 2024-06-03 11:33:40 +02:00 committed by GitHub
parent 61da5d1c29
commit 7a87f2bb15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 2 deletions

View File

@ -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**`

View File

@ -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.

View File

@ -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"
@ -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)
}

View File

@ -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"
@ -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)
}