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 2 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
12 changes: 3 additions & 9 deletions spec/core/ics-004-channel-and-packet-semantics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,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 @@ -507,8 +503,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 @@ -588,8 +583,7 @@ function chanCloseConfirm(
))
}

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

Expand Down
67 changes: 60 additions & 7 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 syncrhonously with the call above
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
// 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 so it is not taken
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this you mean that a sentinel value is stored in the path channelEnds/ports/{datagram.portIdentifier}/channels/{channelIdentifier}, right? Maybe it's more explicit to mention it like this?

// 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 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,19 +652,30 @@ interface ChanCloseConfirm {
```

```typescript
function handleChanCloseConfirm(datagram: ChanCloseConfirm) {
module = lookupModule(datagram.portIdentifier)
err = module.onChanCloseConfirm(
datagram.portIdentifier,
datagram.channelIdentifier
)
abortTransactionUnless(err === nil)
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
// in this case, the channel identifier will be stored with a sentinel value so it is not taken
// by a new channel handshake and the capability is reserved for the application module.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually needed?

// 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.
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
module = lookupModule(datagram.portIdentifier)
err = module.onChanCloseConfirm(
datagram.portIdentifier,
datagram.channelIdentifier
)
abortTransactionUnless(err === nil)
writeChannel(
datagram.portIdentifier,
datagram.channelIdentifier,
CLOSED,
)
}
```

Expand Down
Loading