Skip to content

Commit 775b784

Browse files
authored
fix: Update xcall connection spec to match implementation (#672)
1 parent 3044520 commit 775b784

File tree

1 file changed

+15
-28
lines changed

1 file changed

+15
-28
lines changed

docs/adr/XCall_IBC_Connection.md

+15-28
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,25 @@ The sendMessage function is responsible for sending a message to a specified tar
1313

1414
The behavior of sendMessage depends on the value of sn (sequence number). If sn is greater than 0, it indicates a new message that requires a response. In this case, both the sending fee and the response fee should be included. If sn is 0, it signifies a one-way message where no response is expected. If sn is less than 0, it implies that the message is a response to a previously received message. In this scenario, no fee is included in the sending message since it should have already been paid when the positive sn was sent.
1515

16-
After handling the sn value, the sendMessage function triggers the handleMessage function on the targetNetwork. It passes targetNetwork, sn, and msg as arguments to handleMessage. The purpose of this function is to handle the incoming message on the specified targetNetwork's xCall contract.
16+
After handling the sn value, the sendMessage function triggers the handleMessage function on the targetNetwork. It passes targetNetwork and msg as arguments to handleMessage on xCall.
1717

18-
In case the message fails to be delivered for any reason, the code triggers the handleError function. It passes sn, errorCode, and errorMessage to the function. The responsibility of this function is to handle errors that occur during the message delivery process.
18+
In case the message fails to be delivered for any reason, the connection triggers the handleError function. It passes the failed sn to the function. The responsibility of this function is to handle errors that occur during the message delivery process.
1919

2020
The second external function, getFee(network, response), calculates and returns the fee required to send a message to the specified network and back. It takes into account the optional response parameter when determining the fee.
2121

2222
In summary, this code snippet illustrates a specific behavior expected from a connection regarding message sending and error handling.
23-
``` javascript
23+
```javascript
2424
external function sendMessage(targetNetwork, svc, sn, msg)
25-
if sn < 0:
26-
sn = sn.negate()
27-
On targetNetwork, trigger handleMessage(targetNetwork, sn, msg)
25+
On targetNetwork, trigger handleMessage(targetNetwork, msg)
2826
if message fails to deliver:
29-
trigger handleBTPError(sn, errorCode, errorMessage)
27+
trigger handleError(sn)
3028
```
31-
3229
``` javascript
3330
external function getFee(network, response)
3431
Returns the fee required to send a message to "network" and back, considering the optional response parameter.
35-
...
3632
```
3733

34+
3835
## General IBC Connection Design Overview
3936
The IBC (Inter-Blockchain Communication) connection facilitates communication between different chains using IBC channels and ports. This connection relies on the administrator to associate network IDs with specific connections/ports. Once established, these properties become immutable and cannot be changed. Consequently, users can depend on the stability and reliability of a configured connection to another chain.
4037

@@ -62,7 +59,6 @@ destinationChannel: channelId -> counterPartyChannelId
6259
destinationPort: channelId -> counterPartyPortId
6360

6461
incomingPackets: channel -> sn -> packet
65-
outgoingPackets: channel -> paketSequence -> sn
6662

6763
sendPacketFee: NetworkId -> int
6864
ackFee: NetworkId -> int
@@ -134,9 +130,6 @@ void sendMessage(String _to, String _svc, BigInteger _sn, byte[] _msg) {
134130
}
135131

136132
assert Context.value() == packetfee + _ackFee
137-
if (!_sn.equals(BigInteger.ZERO)) {
138-
outgoingPackets[channel][seqNum] = _sn;
139-
}
140133

141134
Message msg = new Message(_sn, packetfee, _msg);
142135
Packet packet = Packet(
@@ -176,7 +169,7 @@ public byte[] onRecvPacket(byte[] calldata, Address relayer) {
176169

177170
if (msg.getSn() == null) {
178171
Context.transfer(msg.getFee(), Address.fromBytes(msg.getData()))
179-
return new byte[0]
172+
return new byte[0]
180173
}
181174

182175
if (msg.getSn() > 0) {
@@ -193,17 +186,14 @@ public byte[] onRecvPacket(byte[] calldata, Address relayer) {
193186
public void onAcknowledgementPacket(byte[] calldata, byte[] acknowledgement, Address relayer) {
194187
onlyIBCHandler();
195188
Packet packet = Packet.decode(calldata);
196-
BigInteger sn = outgoingPackets[packet.getSourceChannel()][packet.getSequence()];
197-
outgoingPackets[packet.getSourceChannel()][packet.getSequence()] = null;
198189
String nid = networkIds[packet.getSourceChannel()];
199190

200191
assert nid != null;
201-
assert sn != null;
202192

203193
Context.transfer(unclaimedAckFees[_to][packet.sequence], relayer)
204194
unclaimedAckFees[nid][packet.sequence] = null
205195

206-
xCall.handleMessage(nid, sn, acknowledgement);
196+
xCall.handleMessage(nid, acknowledgement);
207197
}
208198
```
209199

@@ -212,19 +202,16 @@ public void onTimeoutPacket(byte[] calldata, Address relayer) {
212202
onlyIBCHandler();
213203
Packet packet = Packet.decode(calldata);
214204
Message msg = Message.fromBytes(packet.getData());
215-
BigInteger sn = outgoingPackets.at(packet.getSourceChannel()).get(packet.getSequence());
216-
outgoingPackets.at(packet.getSourceChannel()).set(packet.getSequence(), null);
205+
BigInteger sn = msg.sn
217206
String nid = networkIds[packet.getSourceChannel()];
218207

219-
assert sn != null;
220-
221-
fee = msg.getFee();
222-
if (sn != null) {
223-
fee += unclaimedAckFees[nid][packet.sequence];
224-
unclaimedAckFees[nid][packet.sequence] = null
225-
xCall.handleError(sn, -1, "Timeout");
226-
}
208+
if (sn == null)
209+
return
227210

211+
fee = msg.fee
212+
fee += unclaimedAckFees[nid][packet.sequence];
213+
unclaimedAckFees[nid][packet.sequence] = null
214+
xCall.handleError(sn, -1, "Timeout");
228215
Context.transfer(fee, relayer)
229216
}
230217
```

0 commit comments

Comments
 (0)