Skip to content

Commit

Permalink
Return IBC packet sequence number (#1225)
Browse files Browse the repository at this point in the history
* Return IBC packet sequence number

* Fix review feedbacks

* Remove names to return values in DispatchMsg method

* Fix comments
  • Loading branch information
pinosu authored Mar 6, 2023
1 parent 32aebb8 commit 4f1c57f
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 27 deletions.
18 changes: 17 additions & 1 deletion docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- [cosmwasm/wasm/v1/ibc.proto](#cosmwasm/wasm/v1/ibc.proto)
- [MsgIBCCloseChannel](#cosmwasm.wasm.v1.MsgIBCCloseChannel)
- [MsgIBCSend](#cosmwasm.wasm.v1.MsgIBCSend)
- [MsgIBCSendResponse](#cosmwasm.wasm.v1.MsgIBCSendResponse)

- [cosmwasm/wasm/v1/proposal.proto](#cosmwasm/wasm/v1/proposal.proto)
- [AccessConfigUpdate](#cosmwasm.wasm.v1.AccessConfigUpdate)
Expand Down Expand Up @@ -573,6 +574,21 @@ MsgIBCSend




<a name="cosmwasm.wasm.v1.MsgIBCSendResponse"></a>

### MsgIBCSendResponse
MsgIBCSendResponse


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `sequence` | [uint64](#uint64) | | Sequence number of the IBC packet sent |





<!-- end messages -->

<!-- end enums -->
Expand Down Expand Up @@ -1457,7 +1473,7 @@ MsgStoreCode submit Wasm code to the system

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `sender` | [string](#string) | | Sender is the that actor that signed the messages |
| `sender` | [string](#string) | | Sender is the actor that signed the messages |
| `wasm_byte_code` | [bytes](#bytes) | | WASMByteCode can be raw or gzip compressed |
| `instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | InstantiatePermission access control to apply on contract creation, optional |

Expand Down
6 changes: 6 additions & 0 deletions proto/cosmwasm/wasm/v1/ibc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ message MsgIBCSend {
bytes data = 6;
}

// MsgIBCSendResponse
message MsgIBCSendResponse {
// Sequence number of the IBC packet sent
uint64 sequence = 1;
}

// MsgIBCCloseChannel port and channel need to be owned by the contract
message MsgIBCCloseChannel {
string channel = 2 [ (gogoproto.moretags) = "yaml:\"source_channel\"" ];
Expand Down
15 changes: 13 additions & 2 deletions x/wasm/keeper/handler_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func NewIBCRawPacketHandler(chk types.ChannelKeeper, cak types.CapabilityKeeper)
}

// DispatchMsg publishes a raw IBC packet onto the channel.
func (h IBCRawPacketHandler) DispatchMsg(ctx sdk.Context, _ sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) (events []sdk.Event, data [][]byte, err error) {
func (h IBCRawPacketHandler) DispatchMsg(ctx sdk.Context, _ sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) ([]sdk.Event, [][]byte, error) {
if msg.IBC == nil || msg.IBC.SendPacket == nil {
return nil, nil, types.ErrUnknownMsg
}
Expand Down Expand Up @@ -188,7 +188,18 @@ func (h IBCRawPacketHandler) DispatchMsg(ctx sdk.Context, _ sdk.AccAddress, cont
ConvertWasmIBCTimeoutHeightToCosmosHeight(msg.IBC.SendPacket.Timeout.Block),
msg.IBC.SendPacket.Timeout.Timestamp,
)
return nil, nil, h.channelKeeper.SendPacket(ctx, channelCap, packet)

if err := h.channelKeeper.SendPacket(ctx, channelCap, packet); err != nil {
return nil, nil, sdkerrors.Wrap(err, "failed to send packet")
}

resp := &types.MsgIBCSendResponse{Sequence: sequence}
val, err := resp.Marshal()
if err != nil {
return nil, nil, sdkerrors.Wrap(err, "failed to marshal IBC send response")
}

return nil, [][]byte{val}, nil
}

var _ Messenger = MessageHandlerFunc(nil)
Expand Down
13 changes: 11 additions & 2 deletions x/wasm/keeper/handler_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,23 @@ func TestIBCRawPacketHandler(t *testing.T) {
capturedPacket = nil
// when
h := NewIBCRawPacketHandler(spec.chanKeeper, spec.capKeeper)
data, evts, gotErr := h.DispatchMsg(ctx, RandomAccountAddress(t), ibcPort, wasmvmtypes.CosmosMsg{IBC: &wasmvmtypes.IBCMsg{SendPacket: &spec.srcMsg}})
evts, data, gotErr := h.DispatchMsg(ctx, RandomAccountAddress(t), ibcPort, wasmvmtypes.CosmosMsg{IBC: &wasmvmtypes.IBCMsg{SendPacket: &spec.srcMsg}})
// then
require.True(t, spec.expErr.Is(gotErr), "exp %v but got %#+v", spec.expErr, gotErr)
if spec.expErr != nil {
return
}
assert.Nil(t, data)

assert.Nil(t, evts)
require.NotNil(t, data)

expMsg := types.MsgIBCSendResponse{Sequence: 1}

actualMsg := types.MsgIBCSendResponse{}
err := actualMsg.Unmarshal(data[0])
require.NoError(t, err)

assert.Equal(t, expMsg, actualMsg)
assert.Equal(t, spec.expPacketSent, capturedPacket)
})
}
Expand Down
199 changes: 178 additions & 21 deletions x/wasm/types/ibc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/wasm/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4f1c57f

Please sign in to comment.