Skip to content

Commit

Permalink
ics 04(upgrades): set counterparty last packet sent
Browse files Browse the repository at this point in the history
  • Loading branch information
crodriguezvega committed Oct 11, 2023
1 parent 69ee911 commit 62bd33d
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions spec/core/ics-004-channel-and-packet-semantics/UPGRADES.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,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 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 provable store for counterparty verification.
```typescript
// startFlushUpgradeHandshake will verify that the channel
Expand All @@ -315,9 +315,9 @@ function startFlushUpgradeHandshake(
lastPacketSendSequence = provableStore.get(nextSequenceSendPath(portIdentifier, channelIdentifier)) - 1

upgrade.timeout = upgradeTimeout
upgrade.lastPacketSendSequence = lastPacketSendSequence
upgrade.lastPacketSent = lastPacketSendSequence

// store upgrade in public store for counterparty proof verification
// store upgrade in provable store for counterparty proof verification
provableStore.set(channelPath(portIdentifier, channelIdentifier), channel)
provableStore.set(channelUpgradePath(portIdentifier, channelIdentifier), upgrade)
}
Expand Down Expand Up @@ -692,6 +692,12 @@ function chanUpgradeAck(
return
}

// store counterparty's sequence number of last packet sent
privateStore.set(
channelCounterpartyLastPacketSequencePath(portIdentifier, channelIdentifier),
counterpartyUpgrade.lastPacketSent
)

// if there are no in-flight packets on our end, we can automatically go to FLUSHCOMPLETE
// otherwise store counterparty timeout so packet handlers can check before going to FLUSHCOMPLETE
if pendingInflightPackets(portIdentifier, channelIdentifier) == nil {
Expand Down Expand Up @@ -787,6 +793,12 @@ function chanUpgradeConfirm(
return
}

// store counterparty's sequence number of last packet sent
privateStore.set(
channelCounterpartyLastPacketSequencePath(portIdentifier, channelIdentifier),
counterpartyUpgrade.lastPacketSent
)

// if there are no in-flight packets on our end, we can automatically go to FLUSHCOMPLETE
if pendingInflightPackets(portIdentifier, channelIdentifier) == nil {
channel.state = FLUSHCOMPLETE
Expand All @@ -797,7 +809,8 @@ function chanUpgradeConfirm(

// if both chains are already in flushcomplete we can move to OPEN
if channel.state == FLUSHCOMPLETE && counterpartyChannelState == FLUSHCOMPLETE {
openUpgradelHandshake(portIdentifier, channelIdentifier)
openUpgradeHandshake(portIdentifier, channelIdentifier)
module = lookupModule(portIdentifier)
module.onChanUpgradeOpen(portIdentifier, channelIdentifier)
}
}
Expand Down

0 comments on commit 62bd33d

Please sign in to comment.