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

Handler for channel open init #452

Merged
merged 35 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
79caad1
handler for channel open init
cezarad Dec 17, 2020
b177fe5
formated
cezarad Dec 17, 2020
3cd7b8f
Update modules/src/ics04_channel/handler/chan_open_init.rs
cezarad Dec 21, 2020
d2e1dff
Update modules/src/ics04_channel/handler/chan_open_init.rs
cezarad Dec 21, 2020
4beb025
Update modules/src/ics04_channel/context.rs
cezarad Dec 21, 2020
0a7aa38
chan open init Romains comments
cezarad Dec 21, 2020
af514ec
added port verification
cezarad Jan 7, 2021
5a62fd5
Merge branch 'master' into Cezara
cezarad Jan 7, 2021
1054aee
chan open init
cezarad Jan 7, 2021
d899101
chan open init
cezarad Jan 7, 2021
08b54fb
minor fmt
cezarad Jan 8, 2021
0f5f16d
chan open init
cezarad Jan 8, 2021
17fe71f
Update modules/src/ics04_channel/channel.rs
cezarad Jan 12, 2021
791f5a1
Update modules/src/ics04_channel/channel.rs
cezarad Jan 12, 2021
bffcb1a
Update modules/src/ics04_channel/context.rs
cezarad Jan 12, 2021
8580c2c
Update modules/src/ics04_channel/context.rs
cezarad Jan 12, 2021
b2f8105
Update error.rs
cezarad Jan 12, 2021
f57b658
Update modules/src/ics04_channel/error.rs
cezarad Jan 12, 2021
e0afeb1
Update modules/src/ics04_channel/channel.rs
cezarad Jan 14, 2021
823eb49
Update modules/src/ics04_channel/context.rs
cezarad Jan 14, 2021
0f37d37
Update context.rs
cezarad Jan 14, 2021
3e40a36
minor
cezarad Jan 14, 2021
cbcaa41
minor
cezarad Jan 14, 2021
e4876e1
test for port
cezarad Jan 14, 2021
2448106
connetion features
cezarad Jan 15, 2021
24a3ae8
connetion features
cezarad Jan 15, 2021
839f675
connetion features
cezarad Jan 15, 2021
a9611fa
review comments
cezarad Jan 15, 2021
ea84402
Merge branch 'master' into Cezara
cezarad Jan 15, 2021
053f0e0
Small refactor to improve readability
romac Jan 15, 2021
1426985
Cleanup ics05_port::capabilities
romac Jan 15, 2021
2d7bc35
Replace panic! with unwrap and avoid some clones in mock context
romac Jan 15, 2021
107236e
Avoid clones in MockContext::add_port
romac Jan 15, 2021
768dfd6
Only clone the channel id
romac Jan 15, 2021
05017f5
Fix a couple comments
romac Jan 15, 2021
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
Prev Previous commit
Next Next commit
connetion features
  • Loading branch information
cezarad committed Jan 15, 2021
commit 2448106dbe79fc765252f0d1b51cb3874a99f7e7
16 changes: 0 additions & 16 deletions .vscode/launch.json

This file was deleted.

26 changes: 0 additions & 26 deletions .vscode/tasks.json

This file was deleted.

9 changes: 9 additions & 0 deletions modules/src/ics03_connection/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ impl Default for Version {
}
}

pub fn verify_supported_feature(version: Version, feature: String) -> bool{
for f in version.features.iter() {
if f.eq(&feature) {
return true;
}
}
false
}

/// Returns the lists of supported versions
pub fn get_compatible_versions() -> Vec<Version> {
vec![Version::default()]
Expand Down
10 changes: 5 additions & 5 deletions modules/src/ics04_channel/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl TryFrom<RawChannel> for ChannelEnd {

fn try_from(value: RawChannel) -> Result<Self, Self::Error> {
// Parse the ordering type. Propagate the error, if any, to our caller.
let chan_state = State::from_i32(value.state)?;
let chan_state: State = State::from_i32(value.state)?;

if chan_state == State::Uninitialized {
return Ok(ChannelEnd::default());
Expand Down Expand Up @@ -237,8 +237,8 @@ impl Order {
pub fn as_string(&self) -> &'static str {
match self {
Self::None => "UNINITIALIZED",
Self::Unordered => "UNORDERED",
Self::Ordered => "ORDERED",
Self::Unordered => "ORDER_UNORDERED",
Self::Ordered => "ORDER_ORDERED",
}
}

Expand Down Expand Up @@ -335,7 +335,7 @@ pub mod test_util {
pub fn get_dummy_raw_channel_end() -> RawChannel {
RawChannel {
state: 1,
ordering: 0,
ordering: 1,
counterparty: Some(get_dummy_raw_counterparty()),
connection_hops: vec!["defaultConnection-0".to_string()],
version: "ics20".to_string(), // The version is not validated.
Expand All @@ -345,7 +345,7 @@ pub mod test_util {
pub fn get_dummy_raw_channel_end_with_missing_connection() -> RawChannel {
RawChannel {
state: 1,
ordering: 0,
ordering: 1,
counterparty: Some(get_dummy_raw_counterparty()),
connection_hops: vec!["noconnection".to_string()],
version: "ics20".to_string(), // The version is not validated.
Expand Down
5 changes: 5 additions & 0 deletions modules/src/ics04_channel/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ pub enum Kind {

#[error("the module associated with the port does not have the capability it needs")]
InvalidPortCapability,

#[error("single version must be negociated on connection before opening channel")]
InvalidVersionLengthConnection,
#[error("the channel ordering is not supported by connection ")]
ChannelFeatureNotSuportedByConnection
}

impl Kind {
Expand Down
24 changes: 18 additions & 6 deletions modules/src/ics04_channel/handler/chan_open_init.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//! Protocol logic specific to ICS4 messages of type `MsgChannelOpenInit`.

use crate::handler::{HandlerOutput, HandlerResult};
//use crate::ics03_connection::connection::C;
use crate::ics04_channel::channel::{ChannelEnd, State};
use crate::ics04_channel::context::ChannelReader;
use crate::ics04_channel::error::{Error, Kind};
use crate::ics04_channel::handler::ChannelEvent::ChanOpenInit;
use crate::ics04_channel::handler::ChannelResult;
use crate::ics04_channel::msgs::chan_open_init::MsgChannelOpenInit;
use crate::ics03_connection::version::verify_supported_feature;

pub(crate) fn process(
ctx: &dyn ChannelReader,
Expand Down Expand Up @@ -37,13 +39,22 @@ pub(crate) fn process(
let connection_end = ctx
.connection_state(&msg.channel().connection_hops()[0]);

if connection_end.is_none()
{
return Err(Kind::MissingConnection(msg.channel().connection_hops()[0].clone()).into());
}
else{
//TODO: Understand conenction version.
match connection_end{
None=> {
return Err(Kind::MissingConnection(msg.channel().connection_hops()[0].clone()).into());
}
Some(conn) =>
{
let get_versions = conn.versions();
if get_versions.len() != 1 {
return Err(Kind::InvalidVersionLengthConnection.into());
}
if !verify_supported_feature(get_versions[0].clone(),msg.channel().ordering().as_string().to_string())
{
return Err(Kind::ChannelFeatureNotSuportedByConnection.into());
}
}
}

// TODO: Check that `version` is non empty but not necessary coherent
if msg.channel().version().is_empty() {
Expand Down Expand Up @@ -120,6 +131,7 @@ mod tests {
get_compatible_versions(),
msg_conn_init.delay_period,
);


let ccid = <ConnectionId as FromStr>::from_str("defaultConnection-0");
let cid = match ccid {
Expand Down
3 changes: 3 additions & 0 deletions modules/src/ics04_channel/msgs/chan_open_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ pub mod test_util {
use crate::ics04_channel::channel::test_util::get_dummy_raw_channel_end;
use crate::ics04_channel::channel::test_util::get_dummy_raw_channel_end_with_missing_connection;
use crate::test_utils::get_dummy_bech32_account;
//use crate::ics04_channel::channel::State;


/// Returns a dummy `RawMsgChannelOpenInit`, for testing only!
pub fn get_dummy_raw_msg_chan_open_init() -> RawMsgChannelOpenInit {
Expand Down Expand Up @@ -176,6 +178,7 @@ mod tests {
fn to_and_from() {
let raw = get_dummy_raw_msg_chan_open_init();
let msg = MsgChannelOpenInit::try_from(raw.clone()).unwrap();
assert!(msg.channel().state_matches(&crate::ics04_channel::channel::State::Init));
let raw_back = RawMsgChannelOpenInit::from(msg.clone());
let msg_back = MsgChannelOpenInit::try_from(raw_back.clone()).unwrap();
assert_eq!(raw, raw_back);
Expand Down
1 change: 1 addition & 0 deletions modules/src/ics04_channel/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub fn pick_version(
Ok(intersection[0].to_string())
}


pub fn validate_versions(versions: Vec<String>) -> Result<Vec<String>, Error> {
if versions.is_empty() {
return Err(Kind::InvalidVersion
Expand Down