Skip to content
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

ICS004: Remove last packet sent #1026

Merged
merged 3 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/core/ics-004-channel-and-packet-semantics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ function recvPacket(
channel = provableStore.get(channelPath(packet.destPort, packet.destChannel))
abortTransactionUnless(channel !== null)
counterpartyLastPacketSent = privateStore.get(channelCounterpartyLastPacketSequencePath(packet.destPort, packet.destChannel)
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
abortTransactionUnless(channel.state === OPEN || (channel.state === FLUSHING && packet.sequence <= counterpartyLastPacketSent))
abortTransactionUnless(channel.state === OPEN || (channel.state === FLUSHING))
abortTransactionUnless(authenticateCapability(channelCapabilityPath(packet.destPort, packet.destChannel), capability))
abortTransactionUnless(packet.sourcePort === channel.counterpartyPortIdentifier)
abortTransactionUnless(packet.sourceChannel === channel.counterpartyChannelIdentifier)
Expand Down
22 changes: 3 additions & 19 deletions spec/core/ics-004-channel-and-packet-semantics/UPGRADES.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,10 @@ The upgrade type will represent a particular upgrade attempt on a channel end.
interface Upgrade {
fields: UpgradeFields
timeout: UpgradeTimeout
lastPacketSent: uint64
}
```

The upgrade contains the proposed upgrade for the channel end on the executing chain, the timeout for the upgrade attempt, and the last packet send sequence for the channel. The `lastPacketSent` allows the counterparty to know which packets need to be flushed before the channel can reopen with the newly negotiated parameters. Any packet sent to the channel end with a packet sequence above the `lastPacketSent` will be rejected until the upgrade is complete.
The upgrade contains the proposed upgrade for the channel end on the executing chain and the timeout for the upgrade attempt.

#### `ErrorReceipt`

Expand Down Expand Up @@ -156,16 +155,6 @@ function verifyChannelUpgrade(
}
```

#### CounterpartyLastPacketSequence Path

The chain must store the counterparty's last packet sequence on `startFlushUpgradeHandshake`. This will be stored in the `counterpartyLastPacketSequence` path on the private store.

```typescript
function counterpartyLastPacketSequencePath(portIdentifier: Identifier, channelIdentifier: Identifier): Path {
return "channelUpgrades/counterpartyLastPacketSequence/ports/{portIdentifier}/channels/{channelIdentifier}"
}
```

#### CounterpartyUpgradeTimeout Path

The chain must store the counterparty's upgradeTimeout. This will be stored in the `counterpartyUpgradeTimeout` path on the private store
Expand Down Expand Up @@ -244,7 +233,7 @@ function initUpgradeHandshake(
// new order must be supported by the new connection
abortTransactionUnless(isSupported(proposedConnection, proposedUpgradeFields.ordering))

// lastPacketSent and timeout will be filled when we move to FLUSHING
// timeout will be filled when we move to FLUSHING
upgrade = Upgrade{
fields: proposedUpgradeFields,
}
Expand Down Expand Up @@ -289,7 +278,7 @@ function isCompatibleUpgradeFields(
}
```

`startFlushUpgradeHandshake` will set the counterparty last packet send and continue blocking the upgrade from continuing until all in-flight packets have been flushed. When the channel is in blocked mode, any packet receive above the counterparty last packet send will be rejected. It will set the channel state to `FLUSHING` and block `sendPacket`. During this time; `receivePacket`, `acknowledgePacket` and `timeoutPacket` will still be allowed and processed according to the original channel parameters. The state machine will set a timer for how long the other side can take before it completes flushing and moves to `FLUSHCOMPLETE`. The new proposed upgrade will be stored in the public store for counterparty verification.
`startFlushUpgradeHandshake` will block the upgrade from continuing until all in-flight packets have been flushed. It will set the channel state to `FLUSHING` and block `sendPacket`. During this time; `receivePacket`, `acknowledgePacket` and `timeoutPacket` will still be allowed and processed according to the original channel parameters. The state machine will set a timer for how long the other side can take before it completes flushing and moves to `FLUSHCOMPLETE`. The new proposed upgrade will be stored in the public store for counterparty verification.

```typescript
// startFlushUpgradeHandshake will verify that the channel
Expand All @@ -312,10 +301,7 @@ function startFlushUpgradeHandshake(
// either timeout height or timestamp must be non-zero
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
abortTransactionUnless(upgradeTimeout.timeoutHeight != 0 || upgradeTimeout.timeoutTimestamp != 0)

lastPacketSendSequence = provableStore.get(nextSequenceSendPath(portIdentifier, channelIdentifier)) - 1

upgrade.timeout = upgradeTimeout
upgrade.lastPacketSendSequence = lastPacketSendSequence

// store upgrade in public store for counterparty proof verification
provableStore.set(channelPath(portIdentifier, channelIdentifier), channel)
Expand Down Expand Up @@ -348,7 +334,6 @@ function openUpgradeHandshake(

crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
// delete auxiliary state
provableStore.delete(channelUpgradePath(portIdentifier, channelIdentifier))
privateStore.delete(channelCounterpartyLastPacketSequencePath(portIdentifier, channelIdentifier))
privateStore.delete(channelCounterpartyUpgradeTimeout(portIdentifier, channelIdentifier))
}
```
Expand All @@ -375,7 +360,6 @@ function restoreChannel(

// delete auxiliary state
provableStore.delete(channelUpgradePath(portIdentifier, channelIdentifier))
privateStore.delete(channelCounterpartyLastPacketSequencePath(portIdentifier, channelIdentifier))
privateStore.delete(channelCounterpartyUpgradeTimeout(portIdentifier, channelIdentifier))

// call modules onChanUpgradeRestore callback
Expand Down
Loading