-
Notifications
You must be signed in to change notification settings - Fork 382
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
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ce5e098
add comments to handler interface describing how to make handshakes a…
AdityaSripal 59cd70c
remove writes from ICS4 to allow for async handshake
AdityaSripal 7d4ec92
Apply suggestions from code review
crodriguezvega 9326341
indentation
crodriguezvega 9f7fe51
Update README.md
AdityaSripal 56462ab
Merge branch 'main' into aditya/async-handshake
AdityaSripal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 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, | ||
|
@@ -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, | ||
|
@@ -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 | ||
) | ||
} | ||
``` | ||
|
||
|
@@ -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 | ||
) | ||
} | ||
``` | ||
|
||
|
@@ -610,18 +652,29 @@ 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 | ||
// 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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, | ||
) | ||
} | ||
``` | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?