-
Notifications
You must be signed in to change notification settings - Fork 12
Build a channel #247
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
Build a channel #247
Changes from all commits
01965c5
5aa3577
46e2c8c
2dc4fe4
c3a9661
ef95b1a
2dcd316
5e7d8ed
7434879
56eb390
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 |
|---|---|---|
|
|
@@ -54,12 +54,17 @@ impl<'a> Manager<'a> { | |
| } | ||
|
|
||
| // Utility functions | ||
| fn check_connection_opened(&self, id: IdentifierSlice) -> Result<Identifier, String> { | ||
| fn query_connection(&self, connection_id: IdentifierSlice) -> Result<ConnectionEnd, String> { | ||
| let kv_store = self.ctx.get_kv_store(); | ||
| let connection_end: ConnectionEnd = | ||
| rlp::decode(&kv_store.get(&connection_path(&id)).ok_or_else(|| "Connection doesn't exist".to_owned())?) | ||
| .expect("Illformed ConnectionEnd stored in the DB"); | ||
| let connection_end: ConnectionEnd = rlp::decode( | ||
| &kv_store.get(&connection_path(&connection_id)).ok_or_else(|| "Connection doesn't exist".to_owned())?, | ||
| ) | ||
| .expect("Illformed ConnectionEnd stored in the DB"); | ||
| Ok(connection_end) | ||
| } | ||
|
|
||
| fn check_connection_opened(&self, id: IdentifierSlice) -> Result<Identifier, String> { | ||
| let connection_end = self.query_connection(id)?; | ||
| if connection_end.state != ConnectionState::OPEN { | ||
| return Err("Connection not opened".to_owned()) | ||
| } | ||
|
|
@@ -203,14 +208,15 @@ impl<'a> Manager<'a> { | |
| } | ||
|
|
||
| let client_identifier = self.check_connection_opened(&connection)?; | ||
| let connection_end = self.query_connection(&connection)?; | ||
|
|
||
| let expected = ChannelEnd { | ||
| state: ChannelState::INIT, | ||
| ordering: order, | ||
| counterparty_port_identifier: DEFAULT_PORT.to_string(), | ||
| counterparty_channel_identifier: channel_identifier.clone(), | ||
| // Note: the array should be reversed in the future where `connection` becomes an array. | ||
| connection_hops: vec![connection.clone()], | ||
| connection_hops: vec![connection_end.counterparty_connection_identifier], | ||
|
Contributor
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. Note that ICS javascript example uses just
Contributor
Author
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. Since the word "connection" was used in the channel/manager.rs code for the connection identifier, I used the term "connection_end". We need a consistent naming rule. What do you prefer? Shall we use
Contributor
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. Ah, I was misunderstanding something. The name |
||
| version: counterparty_version, | ||
| }; | ||
|
|
||
|
|
@@ -284,9 +290,8 @@ impl<'a> Manager<'a> { | |
| counterparty_port_identifier: DEFAULT_PORT.to_string(), | ||
| counterparty_channel_identifier: channel_identifier.clone(), | ||
| connection_hops: { | ||
| let mut x = previous.connection_hops.clone(); | ||
| x.reverse(); | ||
| x | ||
| let connection_end = self.query_connection(&previous.connection_hops[0])?; | ||
| vec![connection_end.counterparty_connection_identifier] | ||
| }, | ||
| version: counterparty_version.clone(), | ||
| }; | ||
|
|
@@ -330,9 +335,8 @@ impl<'a> Manager<'a> { | |
| counterparty_port_identifier: DEFAULT_PORT.to_string(), | ||
| counterparty_channel_identifier: channel_identifier.clone(), | ||
| connection_hops: { | ||
| let mut x = previous.connection_hops.clone(); | ||
| x.reverse(); | ||
| x | ||
| let connection_end = self.query_connection(&previous.connection_hops[0])?; | ||
| vec![connection_end.counterparty_connection_identifier] | ||
| }, | ||
| version: previous.version.clone(), | ||
| }; | ||
|
|
@@ -392,9 +396,8 @@ impl<'a> Manager<'a> { | |
| counterparty_port_identifier: DEFAULT_PORT.to_string(), | ||
| counterparty_channel_identifier: channel_identifier.clone(), | ||
| connection_hops: { | ||
| let mut x = previous.connection_hops.clone(); | ||
| x.reverse(); | ||
| x | ||
| let connection_end = self.query_connection(&previous.connection_hops[0])?; | ||
| vec![connection_end.counterparty_connection_identifier] | ||
| }, | ||
| version: previous.version.clone(), | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| const RLP = require("rlp"); | ||
|
|
||
| export class ChanOpenAckDatagram { | ||
| private channelIdentifier: string; | ||
| private counterpartyVersion: string; | ||
| private proofTry: Buffer; | ||
| private proofHeight: number; | ||
|
|
||
| public constructor({ | ||
| channelIdentifier, | ||
| counterpartyVersion, | ||
| proofTry, | ||
| proofHeight | ||
| }: { | ||
| channelIdentifier: string; | ||
| counterpartyVersion: string; | ||
| proofTry: Buffer; | ||
| proofHeight: number; | ||
| }) { | ||
| this.channelIdentifier = channelIdentifier; | ||
| this.counterpartyVersion = counterpartyVersion; | ||
| this.proofTry = proofTry; | ||
| this.proofHeight = proofHeight; | ||
| } | ||
|
|
||
| public rlpBytes(): Buffer { | ||
| return RLP.encode(this.toEncodeObject()); | ||
| } | ||
|
|
||
| public toEncodeObject(): any[] { | ||
| return [ | ||
| 9, | ||
| this.channelIdentifier, | ||
| this.counterpartyVersion, | ||
| this.proofTry, | ||
| this.proofHeight | ||
| ]; | ||
| } | ||
| } |
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.
What is "Acked-by: Park Juhyung [email protected]" in your commit message? ('Fix connection hop to use the same chain's identifier')
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.
I added it by mistake. I'll remove it.