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
Merge branch 'master' into Cezara
  • Loading branch information
cezarad committed Jan 15, 2021
commit ea84402e10daf179099ab527030cd68fdcb9e52f
8 changes: 4 additions & 4 deletions modules/src/ics03_connection/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ impl Default for Version {
}
}

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

Expand Down
13 changes: 0 additions & 13 deletions modules/src/ics04_channel/channel.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
use crate::ics04_channel::error::{self, Error, Kind};

use crate::ics24_host::identifier::{ChannelId, ConnectionId, PortId};

use ibc_proto::ibc::core::channel::v1::Channel as RawChannel;
use ibc_proto::ibc::core::channel::v1::Counterparty as RawCounterparty;

use tendermint_proto::Protobuf;

use crate::events::IBCEventType;
use crate::ics02_client::height::Height;
use crate::ics04_channel::packet::Sequence;
use anomaly::fail;
use std::convert::{TryFrom, TryInto};
use std::str::FromStr;

Expand Down
5 changes: 2 additions & 3 deletions modules/src/ics04_channel/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ pub trait ChannelReader {
/// A context supplying all the necessary write-only dependencies (i.e., storage writing facility)
/// for processing any `ChannelMsg`.
pub trait ChannelKeeper {

fn next_channel_id(&mut self) -> ChannelId;

fn store_channel_result(&mut self, result: ChannelResult) -> Result<(), Error> {
match result.channel_end.state() {
State::Init => {
Expand Down Expand Up @@ -81,7 +80,7 @@ pub trait ChannelKeeper {
}
Ok(())
}

fn store_connection_channels(
&mut self,
conn_id: &ConnectionId,
Expand Down
2 changes: 1 addition & 1 deletion modules/src/ics04_channel/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub enum Kind {
#[error("single version must be negociated on connection before opening channel")]
InvalidVersionLengthConnection,
#[error("the channel ordering is not supported by connection ")]
ChannelFeatureNotSuportedByConnection
ChannelFeatureNotSuportedByConnection,
}

impl Kind {
Expand Down
48 changes: 24 additions & 24 deletions modules/src/ics04_channel/handler/chan_open_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

use crate::handler::{HandlerOutput, HandlerResult};
//use crate::ics03_connection::connection::C;
use crate::ics03_connection::version::verify_supported_feature;
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 All @@ -35,26 +35,26 @@ pub(crate) fn process(
}

// An IBC connection running on the local (host) chain should exist.

let connection_end = ctx
.connection_state(&msg.channel().connection_hops()[0]);

match connection_end{
None=> {
let connection_end = ctx.connection_state(&msg.channel().connection_hops()[0]);

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())
{
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 @@ -131,7 +131,6 @@ mod tests {
get_compatible_versions(),
msg_conn_init.delay_period,
);


let ccid = <ConnectionId as FromStr>::from_str("defaultConnection-0");
let cid = match ccid {
Expand All @@ -157,13 +156,14 @@ mod tests {
},
Test {
name: "Good parameters".to_string(),
ctx: context.with_connection(cid,
init_conn_end).with_port_capability(
MsgChannelOpenInit::try_from(get_dummy_raw_msg_chan_open_init())
.unwrap()
.port_id()
.clone(),
),
ctx: context
.with_connection(cid, init_conn_end)
.with_port_capability(
MsgChannelOpenInit::try_from(get_dummy_raw_msg_chan_open_init())
.unwrap()
.port_id()
.clone(),
),
msg: ChannelMsg::ChannelOpenInit(msg_chan_init),
want_pass: true,
},
Expand All @@ -188,7 +188,7 @@ mod tests {

// The object in the output is a ChannelEnd, should have init state.
let res: ChannelResult = proto_output.result;
assert_eq!(res.channel_end.state().clone(), State::Init);
assert_eq!(res.channel_end.state().clone(), State::Init);
let msg_init = test.msg.clone();

if let ChannelMsg::ChannelOpenInit(msg_init) = msg_init {
Expand Down
1 change: 0 additions & 1 deletion modules/src/ics04_channel/msgs/chan_open_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ pub mod test_util {
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 {
RawMsgChannelOpenInit {
Expand Down
1 change: 0 additions & 1 deletion modules/src/ics04_channel/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ 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
17 changes: 6 additions & 11 deletions modules/src/mock/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,7 @@ impl MockContext {
..self
}
}
pub fn with_port_capability(
self,
port_id: PortId,
) -> Self {
pub fn with_port_capability(self, port_id: PortId) -> Self {
let mut port_capabilities = self.port_capabilities.clone();
port_capabilities.insert(port_id, Capability::new());
Self {
Expand Down Expand Up @@ -378,13 +375,11 @@ impl ChannelReader for MockContext {

let conn = self.connection_state(&cid);
match conn {
Some(v) => {
ConnectionReader::client_consensus_state(
self,
&v.client_id().clone(),
height,
)
}
Some(v) => ConnectionReader::client_consensus_state(
self,
&v.client_id().clone(),
height,
),
None => panic!(),
}
}
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.