Skip to content

Commit

Permalink
Use empty version for ChanOpenInit and source channel version for `…
Browse files Browse the repository at this point in the history
…ChanOpenTry` steps
  • Loading branch information
romac committed Feb 3, 2022
1 parent c26cdf5 commit 690c16b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
6 changes: 4 additions & 2 deletions relayer/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,8 @@ impl<ChainA: ChainHandle, ChainB: ChainHandle> Channel<ChainA, ChainB> {

let counterparty = Counterparty::new(self.src_port_id().clone(), None);

let version = version::default_by_port(self.dst_port_id())?;
// If the port is not know, use the default (empty) version
let version = version::default_by_port(self.dst_port_id()).unwrap_or_default();

let channel = ChannelEnd::new(
State::Init,
Expand Down Expand Up @@ -866,7 +867,8 @@ impl<ChainA: ChainHandle, ChainB: ChainHandle> Channel<ChainA, ChainB> {
let counterparty =
Counterparty::new(self.src_port_id().clone(), self.src_channel_id().cloned());

let version = version::default_by_port(self.dst_port_id())?;
// Re-use the version that was either set on ChanOpenInit or overwritten by the application.
let version = src_channel.version().clone();

let channel = ChannelEnd::new(
State::TryOpen,
Expand Down
4 changes: 2 additions & 2 deletions relayer/src/channel/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ define_error! {
e.event)
},

InvalidPortId
UnknownPortId
{ port_id: PortId }
| e | {
format_args!("could not resolve channel version because the port is invalid: {0}",
format_args!("could not resolve channel version because the port is not known: {0}",
e.port_id)
},

Expand Down
36 changes: 14 additions & 22 deletions relayer/src/channel/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,24 @@
//! channel version to be used in a channel open
//! handshake.

use tracing::warn;

use ibc::{
applications::{ics20_fungible_token_transfer, ics27_interchain_accounts},
core::{ics04_channel::Version, ics24_host::identifier::PortId},
};

use crate::channel::ChannelError;

/// Returns the default channel version, depending on the the given [`PortId`].
pub fn default_by_port(port_id: &PortId) -> Result<Version, ChannelError> {
if port_id.as_str() == ics20_fungible_token_transfer::PORT_ID {
// https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#forwards-compatibility
Ok(Version::ics20())
} else if port_id
.as_str()
.starts_with(ics27_interchain_accounts::PORT_ID_PREFIX)
{
// https://github.com/cosmos/ibc/tree/master/spec/app/ics-027-interchain-accounts#channel-lifecycle-management
Ok(Version::ics27())
} else {
warn!(
port = %port_id,
"cannot resolve channel version for unknown port",
);

Err(ChannelError::invalid_port_id(port_id.clone()))
/// Returns the default channel version, for the given [`PortId`].
///
/// Currently only ICS20 and ICS27 ports are recognized.
pub fn default_by_port(port_id: &PortId) -> Option<Version> {
match port_id.as_str() {
ics20_fungible_token_transfer::PORT_ID => {
// https://github.com/cosmos/ibc/tree/master/spec/app/ics-020-fungible-token-transfer#forwards-compatibility
Some(Version::ics20())
}
port_id if port_id.starts_with(ics27_interchain_accounts::PORT_ID_PREFIX) => {
// https://github.com/cosmos/ibc/tree/master/spec/app/ics-027-interchain-accounts#channel-lifecycle-management
Some(Version::ics27())
}
_ => None,
}
}

0 comments on commit 690c16b

Please sign in to comment.