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

Add comments to handler for async handshake #1019

Merged
merged 6 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 3 additions & 7 deletions spec/core/ics-004-channel-and-packet-semantics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,7 @@ function chanOpenAck(
expected
))
}

channel.state = OPEN
channel.version = counterpartyVersion
channel.counterpartyChannelIdentifier = counterpartyChannelIdentifier
provableStore.set(channelPath(portIdentifier, channelIdentifier), channel)
// write will happen in the handler defined in the ICS26 spec
}
```

Expand Down Expand Up @@ -506,8 +502,7 @@ function chanOpenConfirm(
))
}

channel.state = OPEN
provableStore.set(channelPath(portIdentifier, channelIdentifier), channel)
// write will happen in the handler defined in the ICS26 spec
}
```

Expand Down Expand Up @@ -587,6 +582,7 @@ function chanCloseConfirm(
))
}

// write may happen asynchronously in the handler defined in the ICS26 spec
// if the channel is closing during an upgrade,
// then we can delete all auxiliary upgrade information
provableStore.delete(channelUpgradePath(portIdentifier, channelIdentifier))
Expand Down
59 changes: 55 additions & 4 deletions spec/core/ics-026-routing-module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,12 @@ function handleChanOpenInit(datagram: ChanOpenInit) {
datagram.portIdentifier,
datagram.counterpartyPortIdentifier
)
// SYNCHRONOUS: the following calls happen synchronously with the call above
// ASYNCHRONOUS: the module callback will be called at a time later than the channel handler
// in this case, the channel identifier will be stored with a sentinel value in the channel path so it is not taken
// by a new channel handshake and the capability is reserved for the application module.
// When the module eventually executes its callback it must call writeChannel so that the channel
// can be written into an INIT state with the right version and the handshake can proceed on the counterparty.
version, err = module.onChanOpenInit(
datagram.order,
datagram.connectionHops,
Expand Down Expand Up @@ -497,6 +503,12 @@ function handleChanOpenTry(datagram: ChanOpenTry) {
datagram.proofInit,
datagram.proofHeight
)
// SYNCHRONOUS: the following calls happen syncrhonously with the call above
// ASYNCHRONOUS: the module callback will be called at a time later than the channel handler
// in this case, the channel identifier will be stored with a sentinel value in the channel path so it is not taken
// by a new channel handshake and the capability is reserved for the application module.
// When the module eventually executes its callback it must call writeChannel so that the channel
// can be written into a TRY state with the right version and the handshake can proceed on the counterparty.
version, err = module.onChanOpenTry(
datagram.order,
datagram.connectionHops,
Expand Down Expand Up @@ -542,13 +554,28 @@ function handleChanOpenAck(datagram: ChanOpenAck) {
datagram.proofTry,
datagram.proofHeight
)
// SYNCHRONOUS: the following calls happen syncrhonously with the call above
// ASYNCHRONOUS: the module callback will be called at a time later than the channel handler
// When the module eventually executes its callback it must call writeChannel so that the channel
// can be written into an OPEN state and the handshake can proceed on the counterparty.
err = module.onChanOpenAck(
datagram.portIdentifier,
datagram.channelIdentifier,
datagram.counterpartyChannelIdentifier,
datagram.counterpartyVersion
)
abortTransactionUnless(err === nil)
channel = provableStore.get(channelPath(datagram.portIdentifier, datagram.channelIdentifier))
writeChannel(
datagram.portIdentifier,
datagram.channelIdentifier,
OPEN,
channel.order,
channel.counterparty.portIdentifier,
datagram.counterpartyChannelIdentifier,
channel.connectionHops,
datagram.counterpartyVersion
)
}
```

Expand All @@ -570,11 +597,26 @@ function handleChanOpenConfirm(datagram: ChanOpenConfirm) {
datagram.proofAck,
datagram.proofHeight
)
// SYNCHRONOUS: the following calls happen syncrhonously with the call above
// ASYNCHRONOUS: the module callback will be called at a time later than the channel handler
// When the module eventually executes its callback it must call writeChannel so that the channel
// can be written into an OPEN state and the handshake can proceed on the counterparty.
err = module.onChanOpenConfirm(
datagram.portIdentifier,
datagram.channelIdentifier
)
abortTransactionUnless(err === nil)
channel = provableStore.get(channelPath(datagram.portIdentifier, datagram.channelIdentifier))
writeChannel(
datagram.portIdentifier,
datagram.channelIdentifier,
OPEN,
channel.order,
channel.counterparty.portIdentifier,
channel.counterparty.channelIdentifier,
channel.connectionHops,
channel.version
)
}
```

Expand Down Expand Up @@ -610,18 +652,27 @@ interface ChanCloseConfirm {
```

```typescript
function handleChanCloseConfirm(datagram: ChanCloseConfirm) {
function handleChanCloseConfirm(datagram: ChanCloseConfirm) {
handler.chanCloseConfirm(
datagram.portIdentifier,
datagram.channelIdentifier,
datagram.proofInit,
datagram.proofHeight
)
// SYNCHRONOUS: the following calls happen syncrhonously with the call above
// ASYNCHRONOUS: the module callback will be called at a time later than the channel handler
// When the module eventually executes its callback it must call writeChannel so that the channel
// can be written into a CLOSED state and the handshake can proceed on the counterparty.
module = lookupModule(datagram.portIdentifier)
err = module.onChanCloseConfirm(
datagram.portIdentifier,
datagram.channelIdentifier
)
abortTransactionUnless(err === nil)
handler.chanCloseConfirm(
writeChannel(
datagram.portIdentifier,
datagram.channelIdentifier,
datagram.proofInit,
datagram.proofHeight
CLOSED,
)
}
```
Expand Down
Loading