-
Notifications
You must be signed in to change notification settings - Fork 418
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
Spike error ack #1299
Spike error ack #1299
Changes from all commits
03c264c
610c677
fcd0040
a59ccb8
2df007f
dbc3483
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ package keeper | |
import ( | ||
"time" | ||
|
||
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" | ||
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
wasmvmtypes "github.com/CosmWasm/wasmvm/types" | ||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
|
@@ -116,7 +119,7 @@ func (k Keeper) OnRecvPacket( | |
ctx sdk.Context, | ||
contractAddr sdk.AccAddress, | ||
msg wasmvmtypes.IBCPacketReceiveMsg, | ||
) ([]byte, error) { | ||
) (ibcexported.Acknowledgement, error) { | ||
defer telemetry.MeasureSince(time.Now(), "wasm", "contract", "ibc-recv-packet") | ||
contractInfo, codeInfo, prefixStore, err := k.contractInstance(ctx, contractAddr) | ||
if err != nil { | ||
|
@@ -130,13 +133,34 @@ func (k Keeper) OnRecvPacket( | |
res, gasUsed, execErr := k.wasmVM.IBCPacketReceive(codeInfo.CodeHash, env, msg, prefixStore, cosmwasmAPI, querier, ctx.GasMeter(), gas, costJSONDeserialization) | ||
k.consumeRuntimeGas(ctx, gasUsed) | ||
if execErr != nil { | ||
panic(execErr) | ||
panic(execErr) // let contract fully abort IBC receive in certain case | ||
} | ||
if res.Err != "" { // handle error case as before https://github.com/CosmWasm/wasmvm/commit/c300106fe5c9426a495f8e10821e00a9330c56c6 | ||
return nil, errorsmod.Wrap(types.ErrExecuteFailed, res.Err) | ||
if res.Err != "" { | ||
// return error ACK with non-redacted contract message | ||
return channeltypes.Acknowledgement{ | ||
Response: &channeltypes.Acknowledgement_Error{Error: res.Err}, | ||
}, nil | ||
} | ||
// note submessage reply results can overwrite the `Acknowledgement` data | ||
return k.handleContractResponse(ctx, contractAddr, contractInfo.IBCPortID, res.Ok.Messages, res.Ok.Attributes, res.Ok.Acknowledgement, res.Ok.Events) | ||
data, err := k.handleContractResponse(ctx, contractAddr, contractInfo.IBCPortID, res.Ok.Messages, res.Ok.Attributes, res.Ok.Acknowledgement, res.Ok.Events) | ||
if err != nil { | ||
// submessage errors result in error ACK | ||
return nil, err | ||
} | ||
// success ACK | ||
return ContractConfirmStateAck(data), nil | ||
} | ||
|
||
var _ ibcexported.Acknowledgement = ContractConfirmStateAck{} | ||
|
||
type ContractConfirmStateAck []byte | ||
|
||
func (w ContractConfirmStateAck) Success() bool { | ||
return true // always commit state | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any documentation what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The best source for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I raised the issue here: cosmos/ibc-go#3434 |
||
|
||
func (w ContractConfirmStateAck) Acknowledgement() []byte { | ||
return w | ||
} | ||
|
||
// OnAckPacket calls the contract to handle the "acknowledgement" data which can contain success or failure of a packet | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code or comment is misleading because it can be either a success or and error or a non-binary acknowledgement type. We should not try to give it any meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On packet receive, success can be defined as case 1 + 2 of #697 (comment) . The contract was able to fully handle the packet. State will be committed.