-
Notifications
You must be signed in to change notification settings - Fork 751
Callbacks Eureka #7934
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
Merged
Merged
Callbacks Eureka #7934
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
be8cdee
callbacks middleware compatible for eureka
AdityaSripal a9c28f5
convert v2 packets to v1 to preserve contractKeeper interface
AdityaSripal bcc4b36
remove ContractKeeperV2 interface
AdityaSripal afa88ab
pass in channeltypesv2.Acknowledgement
AdityaSripal e3eab32
testing progress
AdityaSripal 7d6f7dd
start sendpacket test pass
AdityaSripal bb73c5f
test events
AdityaSripal bfea28d
acknowledgement tests
AdityaSripal bc83db1
fix timeout tests
AdityaSripal ec65620
fix recvPacket test
AdityaSripal 0dcc001
fix writeack tests
AdityaSripal 9403192
fix writeack fail testcase
AdityaSripal 1d22ea9
lint
AdityaSripal 0c27be8
lint moar
AdityaSripal c067db3
lint with tool finally
AdityaSripal 684fe73
Merge branch 'main' of github.com:cosmos/ibc-go into aditya/cherrypic…
AdityaSripal b0e0aaf
update and lint
AdityaSripal e93d5e1
address serdar review
AdityaSripal 348fe72
Update modules/core/api/module.go
AdityaSripal 170ccfe
Merge branch 'main' into aditya/cherrypick-callbacks-eureka
AdityaSripal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| errorsmod "cosmossdk.io/errors" | ||
| storetypes "cosmossdk.io/store/types" | ||
|
|
||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
|
||
| "github.com/cosmos/ibc-go/modules/apps/callbacks/types" | ||
| ) | ||
|
|
||
| // ProcessCallback executes the callbackExecutor and reverts contract changes if the callbackExecutor fails. | ||
| // | ||
| // Error Precedence and Returns: | ||
| // - oogErr: Takes the highest precedence. If the callback runs out of gas, an error wrapped with types.ErrCallbackOutOfGas is returned. | ||
| // - panicErr: Takes the second-highest precedence. If a panic occurs and it is not propagated, an error wrapped with types.ErrCallbackPanic is returned. | ||
| // - callbackErr: If the callbackExecutor returns an error, it is returned as-is. | ||
| // | ||
| // panics if | ||
| // - the contractExecutor panics for any reason, and the callbackType is SendPacket, or | ||
| // - the contractExecutor runs out of gas and the relayer has not reserved gas grater than or equal to | ||
| // CommitGasLimit. | ||
| func ProcessCallback( | ||
| ctx sdk.Context, callbackType types.CallbackType, | ||
| callbackData types.CallbackData, callbackExecutor func(sdk.Context) error, | ||
| ) (err error) { | ||
| cachedCtx, writeFn := ctx.CacheContext() | ||
| cachedCtx = cachedCtx.WithGasMeter(storetypes.NewGasMeter(callbackData.ExecutionGasLimit)) | ||
|
|
||
| defer func() { | ||
| // consume the minimum of g.consumed and g.limit | ||
| ctx.GasMeter().ConsumeGas(cachedCtx.GasMeter().GasConsumedToLimit(), fmt.Sprintf("ibc %s callback", callbackType)) | ||
|
|
||
| // recover from all panics except during SendPacket callbacks | ||
| if r := recover(); r != nil { | ||
| if callbackType == types.CallbackTypeSendPacket { | ||
| panic(r) | ||
| } | ||
| err = errorsmod.Wrapf(types.ErrCallbackPanic, "ibc %s callback panicked with: %v", callbackType, r) | ||
| } | ||
|
|
||
| // if the callback ran out of gas and the relayer has not reserved enough gas, then revert the state | ||
| if cachedCtx.GasMeter().IsPastLimit() { | ||
| if callbackData.AllowRetry() { | ||
| panic(storetypes.ErrorOutOfGas{Descriptor: fmt.Sprintf("ibc %s callback out of gas; commitGasLimit: %d", callbackType, callbackData.CommitGasLimit)}) | ||
| } | ||
| err = errorsmod.Wrapf(types.ErrCallbackOutOfGas, "ibc %s callback out of gas", callbackType) | ||
| } | ||
|
|
||
| // allow the transaction to be committed, continuing the packet lifecycle | ||
| }() | ||
|
|
||
| err = callbackExecutor(cachedCtx) | ||
| if err == nil { | ||
| writeFn() | ||
| } | ||
|
|
||
| return err | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.