From 89e85f2da0392af155d8428364dc214ab25ed4a0 Mon Sep 17 00:00:00 2001 From: yihuang Date: Mon, 3 Apr 2023 16:42:36 +0800 Subject: [PATCH] fix(x/gov): Return ErrInvalidProposalContent in SubmitProposal when legacy handler returns an error. (backport #13051) (#15667) Co-authored-by: Daniel Wedul Co-authored-by: Aleksandr Bezobchuk --- CHANGELOG.md | 1 + x/gov/keeper/proposal.go | 23 ++++++++--------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e12d3c3233b..3bb3582b4e42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes * (x/auth/vesting) [#15383](https://github.com/cosmos/cosmos-sdk/pull/15383) Add extra checks when creating a periodic vesting account. +* (x/gov) [#13051](https://github.com/cosmos/cosmos-sdk/pull/13051) In SubmitPropsal, when a legacy msg fails it's handler call, wrap the error as ErrInvalidProposalContent (instead of ErrNoProposalHandlerExists). ## [v0.46.11](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.11) - 2022-03-03 diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index c68ef10c165f..f44d3aa25ab7 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -1,8 +1,6 @@ package keeper import ( - "bytes" - "context" "errors" "fmt" "slices" @@ -116,19 +114,14 @@ func (k Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata // For other Msgs, we do not verify the proposal messages any further. // They may fail upon execution. // ref: https://github.com/cosmos/cosmos-sdk/pull/10868#discussion_r784872842 - msg, ok := msg.(*v1.MsgExecLegacyContent) - if !ok { - continue - } - - content, err := v1.LegacyContentFromMessage(msg) - if err != nil { - return v1.Proposal{}, errorsmod.Wrapf(types.ErrInvalidProposalContent, "%+v", err) - } - - // Ensure that the content has a respective handler - if !k.legacyRouter.HasRoute(content.ProposalRoute()) { - return v1.Proposal{}, errorsmod.Wrap(types.ErrNoProposalHandlerExists, content.ProposalRoute()) + if msg, ok := msg.(*v1.MsgExecLegacyContent); ok { + cacheCtx, _ := ctx.CacheContext() + if _, err := handler(cacheCtx, msg); err != nil { + if errors.Is(types.ErrNoProposalHandlerExists, err) { + return v1.Proposal{}, err + } + return v1.Proposal{}, sdkerrors.Wrap(types.ErrInvalidProposalContent, err.Error()) + } } if err = k.BranchService.Execute(ctx, func(ctx context.Context) error {