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

Refactor DeliverTx hook so that panics can be handled #543

Merged
merged 3 commits into from
Oct 17, 2024

Conversation

codchen
Copy link
Collaborator

@codchen codchen commented Oct 4, 2024

Describe your changes and provide context

Panics in tx handler is usually handled by a defer statement containing a recover() clause. Previously the call stack looks like:

func DeliverTx:
    func runTx:
        deferred recover
        (actual processing)
    DeliverTx hook

In the above structure, DeliverTx hooks are run on DeliverTx level, so they are outside the deferred recover clause which is within runTx level.

This PR changes it to be:

func DeliverTx:
    func runTx:
        deferred recover
        (actual processing)
        DeliverTx hook

so that the hook can be recovered as well

Testing performed to validate your change

unit test

@codchen codchen requested a review from udpatil October 4, 2024 07:51
Copy link

codecov bot commented Oct 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.90%. Comparing base (d73f5bc) to head (a143ae8).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #543      +/-   ##
==========================================
+ Coverage   54.88%   54.90%   +0.01%     
==========================================
  Files         631      631              
  Lines       54904    54920      +16     
==========================================
+ Hits        30135    30152      +17     
+ Misses      22615    22614       -1     
  Partials     2154     2154              
Flag Coverage Δ
?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
baseapp/abci.go 52.51% <ø> (+0.17%) ⬆️
baseapp/baseapp.go 66.34% <100.00%> (+1.18%) ⬆️
types/result.go 76.33% <ø> (ø)

... and 2 files with indirect coverage changes

resultStr := ""
res := app.getDeliverTxResponse(ctx, gInfo, result, &resultStr)
for _, hook := range app.deliverTxHooks {
hook(ctx, tx, checksum, res)
Copy link
Contributor

Choose a reason for hiding this comment

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

this will affect the actual gas Used for the tx execution, but will be using the res with a stale gas used from getDeliverTxResponse. is there a scenario where this difference between the deliverTx response used for hooks and deliver tx response returned via tendermint causes an issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hooks (as of right now) don't use gasUsed passed in. I changed the data structure to be one specific to delivertx hooks that exclude gasUsed to avoid future misuse.

}
}
var events []abci.Event = []abci.Event{}
if result != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

don't we also need to handle the case in which result.EvmError is non-nil? or do we want to index events for that case as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the existing behavior is to index events even if EvmError is non-nil https://github.com/sei-protocol/sei-cosmos/pull/543/files#diff-389d02f089ab55575400f5300d3c5cfe277fde5f04bd0fe6a85456a7252d1099R309-R330

not sure if we want to change that. I can see reasons both ways

@codchen codchen merged commit 4e7d467 into main Oct 17, 2024
15 checks passed
@codchen codchen deleted the deliver-hook-middleware branch October 17, 2024 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants