Skip to content

Commit 25e02c8

Browse files
committed
feat: Async ack support for IBCv2
1 parent 59da7ea commit 25e02c8

File tree

3 files changed

+55
-13
lines changed

3 files changed

+55
-13
lines changed

tests/e2e/ibc2_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,58 @@ func TestIBC2SendMsg(t *testing.T) {
105105
require.Equal(t, uint32(i), response.IBC2PacketReceiveCounter)
106106
}
107107
}
108+
109+
func TestIBC2RAsyncAckSending(t *testing.T) {
110+
coord := wasmibctesting.NewCoordinator(t, 2)
111+
chainA := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
112+
chainB := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(2)))
113+
114+
contractCodeA := chainA.StoreCodeFile("./testdata/ibc2.wasm").CodeID
115+
contractAddrA := chainA.InstantiateContract(contractCodeA, []byte(`{}`))
116+
contractPortA := wasmkeeper.PortIDForContractV2(contractAddrA)
117+
118+
contractCodeB := chainB.StoreCodeFile("./testdata/ibc2.wasm").CodeID
119+
contractAddrB := chainB.InstantiateContract(contractCodeB, []byte(`{}`))
120+
contractPortB := wasmkeeper.PortIDForContractV2(contractAddrB)
121+
require.NotEmpty(t, contractAddrA)
122+
123+
path := wasmibctesting.NewWasmPath(chainA, chainB)
124+
path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
125+
PortID: contractPortA,
126+
Version: ibctransfertypes.V1,
127+
Order: channeltypes.UNORDERED,
128+
}
129+
path.EndpointB.ChannelConfig = &ibctesting.ChannelConfig{
130+
PortID: contractPortB,
131+
Version: ibctransfertypes.V1,
132+
Order: channeltypes.UNORDERED,
133+
}
134+
135+
path.Path.SetupV2()
136+
137+
var err error
138+
timeoutTimestamp := chainA.GetTimeoutTimestampSecs()
139+
payload := mockv2.NewMockPayload(contractPortB, contractPortA)
140+
payload.Value, err = json.Marshal(IbcPayload{ResponseWithoutAck: true})
141+
require.NoError(t, err)
142+
packet, err := path.EndpointB.MsgSendPacket(timeoutTimestamp, payload)
143+
require.NoError(t, err)
144+
err = path.EndpointA.MsgRecvPacket(packet)
145+
require.NoError(t, err)
146+
147+
var response State
148+
err = chainA.SmartQuery(contractAddrA.String(), QueryMsg{QueryState: struct{}{}}, &response)
149+
require.NoError(t, err)
150+
require.Equal(t, uint32(1), response.IBC2PacketReceiveCounter)
151+
152+
timeoutTimestamp = chainA.GetTimeoutTimestampSecs()
153+
payload = mockv2.NewMockPayload(contractPortB, contractPortA)
154+
payload.Value, err = json.Marshal(IbcPayload{SendAsyncAckForPrevMsg: true})
155+
require.NoError(t, err)
156+
packet, err = path.EndpointB.MsgSendPacket(timeoutTimestamp, payload)
157+
require.NoError(t, err)
158+
err = wasmibctesting.RelayPendingPacketsV2(path)
159+
require.NoError(t, err)
160+
161+
// TODO tkulik: We need https://github.com/CosmWasm/wasmd/issues/2171 in order to properly test receiving async ACKs
162+
}

x/wasm/keeper/ibc2.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,6 @@ func (k Keeper) OnRecvIBC2Packet(
143143
}
144144

145145
if data == nil {
146-
// In case of lack of ack, we assume that the packet should
147-
// be handled asynchronously.
148-
// TODO: https://github.com/CosmWasm/wasmd/issues/2161
149-
// err = k.StoreAsyncAckPacket(ctx, convertPacket(msg.Payload))
150-
// if err != nil {
151-
// return channeltypesv2.RecvPacketResult{
152-
// Status: channeltypesv2.PacketStatus_Failure,
153-
// Acknowledgement: []byte(err.Error()),
154-
// }
155-
// }
156146
return channeltypesv2.RecvPacketResult{
157147
Status: channeltypesv2.PacketStatus_Async,
158148
}

x/wasm/types/expected_keepers.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ type ChannelKeeper interface {
8888
// The interface is implemented by the channel keeper on the lowest level in ibc-go. Middlewares or other abstractions
8989
// can add functionality on top of it. See ics4Wrapper in ibc-go.
9090
// It is important to choose the right implementation that is configured for any middleware used in the ibc-stack of wasm.
91-
//
92-
// For example, when ics-29 fee middleware is set up for the wasm ibc-stack, then the IBCFeeKeeper should be used, so
93-
// that they are in sync.
9491
type ICS4Wrapper interface {
9592
// SendPacket is called by a module in order to send an IBC packet on a channel.
9693
// The packet sequence generated for the packet to be sent is returned. An error

0 commit comments

Comments
 (0)