Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: carry x/gov proposal execution error message #15554

Merged
merged 4 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (x/gov) [#15554](https://github.com/cosmos/cosmos-sdk/pull/15554) Add proposal result log in `active_proposal` event. When a proposal passes but fails to execute, the proposal result is logged in the `active_proposal` event.
* (mempool) [#15328](https://github.com/cosmos/cosmos-sdk/pull/15328) Improve the `PriorityNonceMempool`
* Support generic transaction prioritization, instead of `ctx.Priority()`
* Improve construction through the use of a single `PriorityNonceMempoolConfig` instead of option functions
Expand Down
28 changes: 19 additions & 9 deletions x/gov/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,25 @@ func EndBlocker(ctx sdk.Context, keeper *keeper.Keeper) {
// message is logged.
cacheCtx, writeCache := ctx.CacheContext()
messages, err := proposal.GetMsgs()
if err == nil {
for idx, msg = range messages {
handler := keeper.Router().Handler(msg)
if err != nil {
proposal.Status = v1.StatusFailed
tagValue = types.AttributeValueProposalFailed
logMsg = fmt.Sprintf("passed, but failed to get proposal (%v) msgs: %s", proposal, err)
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved

var res *sdk.Result
res, err = handler(cacheCtx, msg)
if err != nil {
break
}
break
}

events = append(events, res.GetEvents()...)
// execute all messages
for idx, msg = range messages {
handler := keeper.Router().Handler(msg)

var res *sdk.Result
res, err = handler(cacheCtx, msg)
if err != nil {
break
}

events = append(events, res.GetEvents()...)
}

// `err == nil` when all handlers passed.
Expand Down Expand Up @@ -146,6 +153,7 @@ func EndBlocker(ctx sdk.Context, keeper *keeper.Keeper) {
logger.Info(
"proposal tallied",
"proposal", proposal.Id,
"status", proposal.Status.String(),
"expedited", proposal.Expedited,
"title", proposal.Title,
"results", logMsg,
Expand All @@ -156,8 +164,10 @@ func EndBlocker(ctx sdk.Context, keeper *keeper.Keeper) {
types.EventTypeActiveProposal,
sdk.NewAttribute(types.AttributeKeyProposalID, fmt.Sprintf("%d", proposal.Id)),
sdk.NewAttribute(types.AttributeKeyProposalResult, tagValue),
sdk.NewAttribute(types.AttributeKeyProposalLog, logMsg),
),
)

return false
})
}
6 changes: 6 additions & 0 deletions x/gov/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ func TestEndBlockerProposalHandlerFailed(t *testing.T) {
// validate that the proposal fails/has been rejected
gov.EndBlocker(ctx, suite.GovKeeper)

// check proposal events
events := ctx.EventManager().Events()
attr, eventOk := events.GetAttributes(types.AttributeKeyProposalLog)
require.True(t, eventOk)
require.Contains(t, attr[0].Value, "failed on execution")

proposal, ok := suite.GovKeeper.GetProposal(ctx, proposal.Id)
require.True(t, ok)
require.Equal(t, v1.StatusFailed, proposal.Status)
Expand Down
2 changes: 1 addition & 1 deletion x/gov/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const (
EventTypeProposalVote = "proposal_vote"
EventTypeInactiveProposal = "inactive_proposal"
EventTypeActiveProposal = "active_proposal"
EventTypeSignalProposal = "signal_proposal"
EventTypeCancelProposal = "cancel_proposal"

AttributeKeyProposalResult = "proposal_result"
AttributeKeyOption = "option"
AttributeKeyProposalID = "proposal_id"
AttributeKeyProposalMessages = "proposal_messages" // Msg type_urls in the proposal
AttributeKeyVotingPeriodStart = "voting_period_start"
AttributeKeyProposalLog = "proposal_log" // log of proposal execution
AttributeValueProposalDropped = "proposal_dropped" // didn't meet min deposit
AttributeValueProposalPassed = "proposal_passed" // met vote quorum
AttributeValueProposalRejected = "proposal_rejected" // didn't meet vote quorum
Expand Down