Skip to content

Commit 4230e18

Browse files
authored
Merge PR #228: ICS 4 refactors
1 parent 74e42f3 commit 4230e18

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

spec.pdf

0 Bytes
Binary file not shown.

spec/ics-004-channel-and-packet-semantics/README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,19 @@ function sendPacket(packet: Packet) {
466466
assert(packet.destPort === channel.counterpartyPortIdentifier)
467467
assert(packet.destChannel === channel.counterpartyChannelIdentifier)
468468
connection = provableStore.get(connectionPath(packet.connectionHops[0]))
469+
469470
// optimistic sends are permitted once the handshake has started
470471
assert(connection.state !== CLOSED)
471472
assert(packet.connectionHops === channel.connectionHops)
473+
472474
consensusState = provableStore.get(consensusStatePath(connection.clientIdentifier))
473475
assert(consensusState.getHeight() < packet.timeoutHeight)
476+
474477
nextSequenceSend = provableStore.get(nextSequenceSendPath(packet.sourcePort, packet.sourceChannel))
475478
assert(packet.sequence === nextSequenceSend)
479+
480+
// all assertions passed, we can alter state
481+
476482
nextSequenceSend = nextSequenceSend + 1
477483
provableStore.set(nextSequenceSendPath(packet.sourcePort, packet.sourceChannel), nextSequenceSend)
478484
provableStore.set(packetCommitmentPath(packet.sourcePort, packet.sourceChannel, sequence), commit(packet.data))
@@ -507,10 +513,13 @@ function recvPacket(
507513
assert(authenticate(provableStore.get(portPath(packet.destPort))))
508514
assert(packet.sourcePort === channel.counterpartyPortIdentifier)
509515
assert(packet.sourceChannel === channel.counterpartyChannelIdentifier)
516+
510517
connection = provableStore.get(connectionPath(channel.connectionHops[0]))
511518
assert(connection.state === OPEN)
512519
assert(packet.connectionHops === channel.connectionHops)
520+
513521
assert(proofHeight < packet.timeoutHeight)
522+
514523
client = queryClient(connection.clientIdentifier)
515524
assert(client.verifyMembership(
516525
proofHeight,
@@ -519,6 +528,8 @@ function recvPacket(
519528
commit(packet.data)
520529
))
521530

531+
// all assertions passed (except sequence check), we can alter state
532+
522533
if (acknowledgement.length > 0 || channel.order === UNORDERED)
523534
provableStore.set(
524535
packetAcknowledgementPath(packet.destPort, packet.destChannel, packet.sequence),
@@ -556,6 +567,7 @@ function acknowledgePacket(
556567
assert(channel.state === OPEN)
557568
assert(authenticate(provableStore.get(portPath(packet.sourcePort))))
558569
assert(packet.sourceChannel === channel.counterpartyChannelIdentifier)
570+
559571
connection = provableStore.get(connectionPath(channel.connectionHops[0]))
560572
assert(packet.sourcePort === channel.counterpartyPortIdentifier)
561573
assert(packet.connectionHops === channel.connectionHops)
@@ -574,6 +586,8 @@ function acknowledgePacket(
574586
commit(acknowledgement)
575587
))
576588

589+
// all assertions passed, we can alter state
590+
577591
// delete our commitment so we can't "acknowledge" again
578592
provableStore.delete(packetCommitmentPath(packet.sourcePort, packet.sourceChannel, packet.sequence))
579593

@@ -606,9 +620,11 @@ function timeoutPacketOrdered(
606620
proof: CommitmentProof,
607621
proofHeight: uint64,
608622
nextSequenceRecv: uint64): Packet {
623+
609624
channel = provableStore.get(channelPath(packet.sourcePort, packet.sourceChannel))
610625
assert(channel.state === OPEN)
611626
assert(channel.order === ORDERED)
627+
612628
assert(authenticate(provableStore.get(portPath(packet.sourcePort))))
613629
assert(packet.destChannel === channel.counterpartyChannelIdentifier)
614630

@@ -636,6 +652,8 @@ function timeoutPacketOrdered(
636652
nextSequenceRecv
637653
))
638654

655+
// all assertions passed, we can alter state
656+
639657
// delete our commitment
640658
provableStore.delete(packetCommitmentPath(packet.sourcePort, packet.sourceChannel, packet.sequence))
641659

@@ -685,6 +703,8 @@ function timeoutPacketUnordered(
685703
proof,
686704
packetAcknowledgementPath(packet.sourcePort, packet.sourceChannel, packet.sequence)
687705
))
706+
707+
// all assertions passed, we can alter state
688708

689709
// delete our commitment
690710
provableStore.delete(packetCommitmentPath(packet.sourcePort, packet.sourceChannel, packet.sequence))
@@ -732,6 +752,8 @@ function timeoutClose(
732752
commit(packet.data)
733753
))
734754

755+
// all assertions passed, we can alter state
756+
735757
channel.state = CLOSED
736758
provableStore.set(channelPath(packet.destPort, packet.destChannel), channel)
737759

@@ -784,6 +806,8 @@ function timeoutOnClose(
784806
packetAcknowledgementPath(packet.sourcePort, packet.sourceChannel, packet.sequence)
785807
))
786808

809+
// all assertions passed, we can alter state
810+
787811
// delete our commitment
788812
provableStore.delete(packetCommitmentPath(packet.sourcePort, packet.sourceChannel, packet.sequence))
789813

@@ -818,6 +842,10 @@ function cleanupPacketOrdered(
818842
// assert packet has been received on the other end
819843
assert(nextSequenceRecv > packet.sequence)
820844

845+
// verify we actually sent the packet, check the store
846+
assert(provableStore.get(packetCommitmentPath(packet.sourcePort, packet.sourceChannel, packet.sequence))
847+
=== commit(packet.data))
848+
821849
// check that the recv sequence is as claimed
822850
client = queryClient(connection.clientIdentifier)
823851
assert(client.verifyMembership(
@@ -827,9 +855,7 @@ function cleanupPacketOrdered(
827855
nextSequenceRecv
828856
))
829857

830-
// verify we actually sent the packet, check the store
831-
assert(provableStore.get(packetCommitmentPath(packet.sourcePort, packet.sourceChannel, packet.sequence))
832-
=== commit(packet.data))
858+
// all assertions passed, we can alter state
833859

834860
// clear the store
835861
provableStore.delete(packetCommitmentPath(packet.sourcePort, packet.sourceChannel, packet.sequence))
@@ -871,6 +897,8 @@ function cleanupPacketUnordered(
871897
assert(provableStore.get(packetCommitmentPath(packet.sourcePort, packet.sourceChannel, packet.sequence))
872898
=== commit(packet.data))
873899

900+
// all assertions passed, we can alter state
901+
874902
// clear the store
875903
provableStore.delete(packetCommitmentPath(packet.sourcePort, packet.sourceChannel, packet.sequence))
876904

0 commit comments

Comments
 (0)