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(gov): handle panics when executing x/gov proposals #17780

Merged
merged 10 commits into from
Sep 18, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/bank) [#17569](https://github.com/cosmos/cosmos-sdk/pull/17569) Introduce a new message type, `MsgBurn `, to burn coins.
* (genutil) [#17571](https://github.com/cosmos/cosmos-sdk/pull/17571) Allow creation of `AppGenesis` without a file lookup.
* (server) [#17094](https://github.com/cosmos/cosmos-sdk/pull/17094) Add duration `shutdown-grace` for resource clean up (closing database handles) before exit.
* (x/gov) [#17780](https://github.com/cosmos/cosmos-sdk/pull/17780) Handle panics when executing x/gov proposals.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recover panics and turn them into errors when executing x/gov proposals

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@odeke-em thanks for suggestion. I will update the changelog. However I don't think this kind of comment should be blocking, because now we need to wait for you to unblock.


### Improvements

Expand Down
18 changes: 16 additions & 2 deletions x/gov/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"time"

"cosmossdk.io/collections"
"google.golang.org/protobuf/proto"

Check failure on line 8 in x/gov/abci.go

View workflow job for this annotation

GitHub Actions / dependency-review

"google.golang.org/protobuf/proto" imported and not used

Check failure on line 8 in x/gov/abci.go

View workflow job for this annotation

GitHub Actions / tests (01)

"google.golang.org/protobuf/proto" imported and not used

Check failure on line 8 in x/gov/abci.go

View workflow job for this annotation

GitHub Actions / tests (01)

"google.golang.org/protobuf/proto" imported and not used

Check failure on line 8 in x/gov/abci.go

View workflow job for this annotation

GitHub Actions / tests (02)

"google.golang.org/protobuf/proto" imported and not used

Check failure on line 8 in x/gov/abci.go

View workflow job for this annotation

GitHub Actions / tests (02)

"google.golang.org/protobuf/proto" imported and not used

Check failure on line 8 in x/gov/abci.go

View workflow job for this annotation

GitHub Actions / tests (02)

"google.golang.org/protobuf/proto" imported and not used

Check failure on line 8 in x/gov/abci.go

View workflow job for this annotation

GitHub Actions / tests (02)

"google.golang.org/protobuf/proto" imported and not used

Check failure on line 8 in x/gov/abci.go

View workflow job for this annotation

GitHub Actions / tests (02)

"google.golang.org/protobuf/proto" imported and not used

Check failure on line 8 in x/gov/abci.go

View workflow job for this annotation

GitHub Actions / tests (02)

"google.golang.org/protobuf/proto" imported and not used

Check failure on line 8 in x/gov/abci.go

View workflow job for this annotation

GitHub Actions / tests (02)

"google.golang.org/protobuf/proto" imported and not used

Check failure on line 8 in x/gov/abci.go

View workflow job for this annotation

GitHub Actions / tests (03)

"google.golang.org/protobuf/proto" imported and not used
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
Expand Down Expand Up @@ -133,9 +135,8 @@
// execute all messages
for idx, msg = range messages {
handler := keeper.Router().Handler(msg)

var res *sdk.Result
res, err = handler(cacheCtx, msg)
res, err = safeExecuteHandler(cacheCtx, msg, handler)
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
break
}
Expand Down Expand Up @@ -223,3 +224,16 @@
}
return nil
}

// executes handle(msg) and recovers from panic.
func safeExecuteHandler(ctx sdk.Context, msg sdk.Msg, handler baseapp.MsgServiceHandler,
) (res *sdk.Result, err error) {

defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("handling x/gov poposal msg [%s] PANICED: %v", msg, r)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another typo I think PANICED -> PANICKED

}
}()
res, err = handler(ctx, msg)
return
}
Loading