Skip to content

Commit

Permalink
Remove ChannelError::MissingProof and MissingProofHeight error variants
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchen1991 committed Sep 17, 2024
1 parent 9942007 commit d550bcd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
4 changes: 0 additions & 4 deletions ibc-core/ics04-channel/types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ pub enum ChannelError {
InvalidTimeoutTimestamp(TimestampError),
/// missing acknowledgment status
MissingAcknowledgmentStatus,
/// missing proof
MissingProof,
/// missing proof height
MissingProofHeight,
/// missing counterparty
MissingCounterparty,
/// missing timeout
Expand Down
14 changes: 6 additions & 8 deletions ibc-core/ics04-channel/types/src/msgs/chan_open_confirm.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use ibc_core_client_types::Height;
use ibc_core_commitment_types::commitment::CommitmentProofBytes;
use ibc_core_host_types::error::DecodingError;
use ibc_core_host_types::identifiers::{ChannelId, PortId};
use ibc_primitives::prelude::*;
use ibc_primitives::Signer;
use ibc_proto::ibc::core::channel::v1::MsgChannelOpenConfirm as RawMsgChannelOpenConfirm;
use ibc_proto::Protobuf;

use crate::error::ChannelError;

pub const CHAN_OPEN_CONFIRM_TYPE_URL: &str = "/ibc.core.channel.v1.MsgChannelOpenConfirm";

///
Expand All @@ -32,20 +31,19 @@ pub struct MsgChannelOpenConfirm {
impl Protobuf<RawMsgChannelOpenConfirm> for MsgChannelOpenConfirm {}

impl TryFrom<RawMsgChannelOpenConfirm> for MsgChannelOpenConfirm {
type Error = ChannelError;
type Error = DecodingError;

fn try_from(raw_msg: RawMsgChannelOpenConfirm) -> Result<Self, Self::Error> {
Ok(MsgChannelOpenConfirm {
port_id_on_b: raw_msg.port_id.parse()?,
chan_id_on_b: raw_msg.channel_id.parse()?,
proof_chan_end_on_a: raw_msg
.proof_ack
.try_into()
.map_err(|_| ChannelError::MissingProof)?,
proof_chan_end_on_a: raw_msg.proof_ack.try_into().map_err(|e| {
DecodingError::invalid_raw_data(format!("invalid commitment proof bytes: {e}"))
})?,
proof_height_on_a: raw_msg
.proof_height
.and_then(|raw_height| raw_height.try_into().ok())
.ok_or(ChannelError::MissingProofHeight)?,
.ok_or(DecodingError::invalid_raw_data("invalid proof height"))?,
signer: raw_msg.signer.into(),
})
}
Expand Down
28 changes: 13 additions & 15 deletions ibc-core/ics04-channel/types/src/msgs/chan_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ impl MsgChannelOpenTry {
impl Protobuf<RawMsgChannelOpenTry> for MsgChannelOpenTry {}

impl TryFrom<RawMsgChannelOpenTry> for MsgChannelOpenTry {
type Error = ChannelError;
type Error = DecodingError;

fn try_from(raw_msg: RawMsgChannelOpenTry) -> Result<Self, Self::Error> {
let chan_end_on_b: ChannelEnd = raw_msg
.channel
.ok_or(DecodingError::MissingRawData {
description: "channel end not set".to_string(),
})?
.ok_or(DecodingError::missing_raw_data("channel end not set"))?
.try_into()?;

chan_end_on_b.verify_state_matches(&State::TryOpen)?;
chan_end_on_b
.verify_state_matches(&State::TryOpen)
.map_err(|e| DecodingError::invalid_raw_data(format!("invalid channel state: {e}")))?;

#[allow(deprecated)]
if !raw_msg.previous_channel_id.is_empty() {
return Err(DecodingError::InvalidRawData { description: "previous channel id must be empty. It has been deprecated as crossing hellos are no longer supported".to_string() })?;
return Err(DecodingError::invalid_raw_data("previous channel id must be empty. It has been deprecated as crossing hellos are no longer supported"))?;

Check warning on line 68 in ibc-core/ics04-channel/types/src/msgs/chan_open_try.rs

View check run for this annotation

Codecov / codecov/patch

ibc-core/ics04-channel/types/src/msgs/chan_open_try.rs#L68

Added line #L68 was not covered by tests
}

#[allow(deprecated)]
Expand All @@ -74,19 +74,17 @@ impl TryFrom<RawMsgChannelOpenTry> for MsgChannelOpenTry {
ordering: chan_end_on_b.ordering,
connection_hops_on_b: chan_end_on_b.connection_hops,
port_id_on_a: chan_end_on_b.remote.port_id,
chan_id_on_a: chan_end_on_b
.remote
.channel_id
.ok_or(ChannelError::MissingCounterparty)?,
chan_id_on_a: chan_end_on_b.remote.channel_id.ok_or(
DecodingError::missing_raw_data("missing counterparty channel ID"),
)?,
version_supported_on_a: raw_msg.counterparty_version.into(),
proof_chan_end_on_a: raw_msg
.proof_init
.try_into()
.map_err(|_| ChannelError::MissingProof)?,
proof_chan_end_on_a: raw_msg.proof_init.try_into().map_err(|e| {
DecodingError::invalid_raw_data(format!("invalid commitment proof bytes: {e}"))
})?,
proof_height_on_a: raw_msg
.proof_height
.and_then(|raw_height| raw_height.try_into().ok())
.ok_or(ChannelError::MissingProofHeight)?,
.ok_or(DecodingError::invalid_raw_data("invalid proof height"))?,
signer: raw_msg.signer.into(),
version_proposal: chan_end_on_b.version,
};
Expand Down

0 comments on commit d550bcd

Please sign in to comment.