-
Notifications
You must be signed in to change notification settings - Fork 440
Flexible identifier selection #482
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
Changes from all commits
9ef11e5
2e0c350
262a7de
5d845a0
67d9088
b805be3
4630d60
ff93ac3
3354f39
dad036a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,6 +281,13 @@ At the end of an opening handshake between two chains implementing the sub-proto | |
|
||
This sub-protocol need not be permissioned, modulo anti-spam measures. | ||
|
||
In `connOpenInit`, a sentinel empty-string identifier can be used to allow the recipient chain to choose its own connection identifier. Chains may implement a function `desiredIdentifier` which chooses an identifier, e.g. by incrementing a counter: | ||
|
||
```typescript | ||
type desiredIdentifier = (provedIdentifier: Identifier) -> Identifier | ||
``` | ||
|
||
A specific version can optionally be passed as `version` to ensure that the handshake will either complete with that version or fail. | ||
|
||
*ConnOpenInit* initialises a connection attempt on chain A. | ||
|
||
|
@@ -290,12 +297,20 @@ function connOpenInit( | |
desiredCounterpartyConnectionIdentifier: Identifier, | ||
counterpartyPrefix: CommitmentPrefix, | ||
clientIdentifier: Identifier, | ||
counterpartyClientIdentifier: Identifier) { | ||
counterpartyClientIdentifier: Identifier, | ||
version: string) { | ||
abortTransactionUnless(validateConnectionIdentifier(identifier)) | ||
abortTransactionUnless(provableStore.get(connectionPath(identifier)) == null) | ||
state = INIT | ||
if version != "" { | ||
// manually selected version must be one we can support | ||
abortTransactionUnless(getCompatibleVersions().indexOf(version) > -1) | ||
versions = [version] | ||
} else { | ||
versions = getCompatibleVersions() | ||
} | ||
connection = ConnectionEnd{state, desiredCounterpartyConnectionIdentifier, counterpartyPrefix, | ||
clientIdentifier, counterpartyClientIdentifier, getCompatibleVersions()} | ||
clientIdentifier, counterpartyClientIdentifier, versions} | ||
provableStore.set(connectionPath(identifier), connection) | ||
addConnectionToClient(clientIdentifier, identifier) | ||
} | ||
|
@@ -306,6 +321,7 @@ function connOpenInit( | |
```typescript | ||
function connOpenTry( | ||
desiredIdentifier: Identifier, | ||
provedIdentifier: Identifier, | ||
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. couldn't this just be a boolean indicating if the sending chain decided to choose the identifier or not? 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. sure, though we'll still construct a "provedIdentifier" since we need to check it |
||
counterpartyConnectionIdentifier: Identifier, | ||
counterpartyPrefix: CommitmentPrefix, | ||
counterpartyClientIdentifier: Identifier, | ||
|
@@ -318,24 +334,27 @@ function connOpenTry( | |
abortTransactionUnless(validateConnectionIdentifier(desiredIdentifier)) | ||
abortTransactionUnless(consensusHeight < getCurrentHeight()) | ||
expectedConsensusState = getConsensusState(consensusHeight) | ||
expected = ConnectionEnd{INIT, desiredIdentifier, getCommitmentPrefix(), counterpartyClientIdentifier, | ||
abortTransationUnless( | ||
provedIdentifier === desiredIdentifier || | ||
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. This is a bit confusing to me. proved identifier is empty or comes from the init chain. Desired Identifier comes from the receiving chain. But where? There doesn't seem to be a way to say "use whatever name they suggest", or "use whatever name they suggest if it starts with 'foo'" for example. Rather than comparing here, it would make more sense to have
So the receiving module can make this decision and about if desired 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. Right, that's the intended usage, it just doesn't need to happen "within" the IBC module, per se. I can add a note about it. 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. Added a comment with your example.
cwgoes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
provedIdentifier === "" | ||
) | ||
expected = ConnectionEnd{INIT, provedIdentifier, getCommitmentPrefix(), counterpartyClientIdentifier, | ||
clientIdentifier, counterpartyVersions} | ||
versionsIntersection = intersection(counterpartyVersions, getCompatibleVersions()) | ||
version = pickVersion(versionsIntersection) | ||
connection = ConnectionEnd{TRYOPEN, counterpartyConnectionIdentifier, counterpartyPrefix, | ||
clientIdentifier, counterpartyClientIdentifier, version} | ||
abortTransactionUnless(connection.verifyConnectionState(proofHeight, proofInit, counterpartyConnectionIdentifier, expected)) | ||
abortTransactionUnless(connection.verifyClientConsensusState( | ||
proofHeight, proofConsensus, counterpartyClientIdentifier, consensusHeight, expectedConsensusState)) | ||
previous = provableStore.get(connectionPath(desiredIdentifier)) | ||
abortTransactionUnless( | ||
(previous === null) || | ||
(previous.state === INIT && | ||
previous.counterpartyConnectionIdentifier === counterpartyConnectionIdentifier && | ||
previous.counterpartyPrefix === counterpartyPrefix && | ||
previous.clientIdentifier === clientIdentifier && | ||
previous.counterpartyClientIdentifier === counterpartyClientIdentifier && | ||
previous.version === getCompatibleVersions())) | ||
cwgoes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
previous.counterpartyClientIdentifier === counterpartyClientIdentifier)) | ||
versionsIntersection = intersection(counterpartyVersions, previous !== null ? previous.version : getCompatibleVersions()) | ||
version = pickVersion(versionsIntersection) // throws if there is no intersection | ||
connection = ConnectionEnd{TRYOPEN, counterpartyConnectionIdentifier, counterpartyPrefix, | ||
clientIdentifier, counterpartyClientIdentifier, version} | ||
abortTransactionUnless(connection.verifyConnectionState(proofHeight, proofInit, counterpartyConnectionIdentifier, expected)) | ||
abortTransactionUnless(connection.verifyClientConsensusState( | ||
proofHeight, proofConsensus, counterpartyClientIdentifier, consensusHeight, expectedConsensusState)) | ||
identifier = desiredIdentifier | ||
provableStore.set(connectionPath(identifier), connection) | ||
addConnectionToClient(clientIdentifier, identifier) | ||
|
@@ -348,24 +367,30 @@ function connOpenTry( | |
function connOpenAck( | ||
identifier: Identifier, | ||
version: string, | ||
counterpartyIdentifier: Identifier, | ||
proofTry: CommitmentProof, | ||
proofConsensus: CommitmentProof, | ||
proofHeight: Height, | ||
consensusHeight: Height) { | ||
abortTransactionUnless(consensusHeight < getCurrentHeight()) | ||
connection = provableStore.get(connectionPath(identifier)) | ||
abortTransactionUnless( | ||
counterpartyIdentifier === connection.counterpartyConnectionIdentifier || | ||
connection.counterpartyConnectionIdentifier === "" | ||
) | ||
abortTransactionUnless( | ||
(connection.state === INIT && connection.version.indexOf(version) !== -1) | ||
|| (connection.state === TRYOPEN && connection.version === version)) | ||
expectedConsensusState = getConsensusState(consensusHeight) | ||
expected = ConnectionEnd{TRYOPEN, identifier, getCommitmentPrefix(), | ||
connection.counterpartyClientIdentifier, connection.clientIdentifier, | ||
version} | ||
abortTransactionUnless(connection.verifyConnectionState(proofHeight, proofTry, connection.counterpartyConnectionIdentifier, expected)) | ||
abortTransactionUnless(connection.verifyConnectionState(proofHeight, proofTry, counterpartyIdentifier, expected)) | ||
abortTransactionUnless(connection.verifyClientConsensusState( | ||
proofHeight, proofConsensus, connection.counterpartyClientIdentifier, consensusHeight, expectedConsensusState)) | ||
connection.state = OPEN | ||
connection.version = version | ||
connection.counterpartyConnectionIdentifier = counterpartyIdentifier | ||
provableStore.set(connectionPath(identifier), connection) | ||
} | ||
``` | ||
|
Uh oh!
There was an error while loading. Please reload this page.