Skip to content

Commit

Permalink
feat: carry x/gov proposal execution error message (#15554)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksandr Bezobchuk <[email protected]>
  • Loading branch information
julienrbrt and alexanderbez authored Mar 27, 2023
1 parent 44b04da commit e783a41
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
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 proposal (%v) failed to execute; msgs: %s", proposal, err)

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

0 comments on commit e783a41

Please sign in to comment.