From aa97ced3f936dd0cb4bf586d340f36af4e5c986a Mon Sep 17 00:00:00 2001 From: Davirain Date: Tue, 10 Jan 2023 02:36:04 +0800 Subject: [PATCH] Make `process()` functions `pub(crate)` (#328) * Make Msg* structs pub(crate) * Create 324-make-msg-structs-pub-crate.md * fix clippy * Remove Unused new function * fix merge error * Revert pub(crate) because pub trait ValidationContext * fix test --- .../324-make-msg-structs-pub-crate.md | 2 + crates/ibc/src/core/context.rs | 44 ++++------ crates/ibc/src/core/ics02_client/handler.rs | 5 +- .../ics02_client/handler/create_client.rs | 2 +- .../core/ics02_client/handler/misbehaviour.rs | 2 +- .../ics02_client/handler/update_client.rs | 2 +- .../ics02_client/handler/upgrade_client.rs | 2 +- crates/ibc/src/core/ics02_client/msgs.rs | 1 + .../core/ics02_client/msgs/update_client.rs | 22 ++--- .../core/ics02_client/msgs/upgrade_client.rs | 47 ++++++----- .../ibc/src/core/ics03_connection/handler.rs | 10 +-- .../ics03_connection/handler/conn_open_ack.rs | 8 +- .../handler/conn_open_confirm.rs | 8 +- .../handler/conn_open_init.rs | 10 +-- .../ics03_connection/handler/conn_open_try.rs | 14 ++-- crates/ibc/src/core/ics03_connection/msgs.rs | 8 +- crates/ibc/src/core/ics04_channel/handler.rs | 73 ++++++++-------- .../ics04_channel/handler/acknowledgement.rs | 3 +- .../handler/chan_close_confirm.rs | 6 +- .../ics04_channel/handler/chan_close_init.rs | 2 +- .../ics04_channel/handler/chan_open_ack.rs | 10 +-- .../handler/chan_open_confirm.rs | 2 +- .../ics04_channel/handler/chan_open_init.rs | 6 +- .../ics04_channel/handler/chan_open_try.rs | 10 +-- .../core/ics04_channel/handler/recv_packet.rs | 2 +- .../src/core/ics04_channel/handler/timeout.rs | 2 +- .../ics04_channel/handler/timeout_on_close.rs | 2 +- crates/ibc/src/core/ics04_channel/msgs.rs | 40 ++++----- .../ics04_channel/msgs/acknowledgement.rs | 22 ----- .../ics04_channel/msgs/chan_close_confirm.rs | 18 ---- .../ics04_channel/msgs/chan_close_init.rs | 10 --- .../core/ics04_channel/msgs/chan_open_ack.rs | 22 ----- .../ics04_channel/msgs/chan_open_confirm.rs | 18 ---- .../core/ics04_channel/msgs/chan_open_init.rs | 10 --- .../core/ics04_channel/msgs/chan_open_try.rs | 22 ----- .../core/ics04_channel/msgs/recv_packet.rs | 36 ++++---- .../src/core/ics04_channel/msgs/timeout.rs | 18 ---- .../ics04_channel/msgs/timeout_on_close.rs | 20 ----- crates/ibc/src/core/ics26_routing/handler.rs | 83 +++++++++---------- crates/ibc/src/core/ics26_routing/msgs.rs | 66 +++++---------- crates/ibc/src/mock/ics18_relayer/context.rs | 6 +- 41 files changed, 251 insertions(+), 445 deletions(-) create mode 100644 .changelog/unreleased/improvements/324-make-msg-structs-pub-crate.md diff --git a/.changelog/unreleased/improvements/324-make-msg-structs-pub-crate.md b/.changelog/unreleased/improvements/324-make-msg-structs-pub-crate.md new file mode 100644 index 000000000..ff276ed61 --- /dev/null +++ b/.changelog/unreleased/improvements/324-make-msg-structs-pub-crate.md @@ -0,0 +1,2 @@ +- Make Msg* structs pub(crate) ([#324](https://github.com/cosmos/ibc- + rs/issues/324)) \ No newline at end of file diff --git a/crates/ibc/src/core/context.rs b/crates/ibc/src/core/context.rs index 8ba9d2a97..2383d7c5a 100644 --- a/crates/ibc/src/core/context.rs +++ b/crates/ibc/src/core/context.rs @@ -110,30 +110,24 @@ mod val_exec_ctx { Self: Sized, { match message { - MsgEnvelope::ClientMsg(message) => match message { + MsgEnvelope::Client(message) => match message { ClientMsg::CreateClient(message) => create_client::validate(self, message), ClientMsg::UpdateClient(message) => update_client::validate(self, message), ClientMsg::Misbehaviour(message) => misbehaviour::validate(self, message), ClientMsg::UpgradeClient(message) => upgrade_client::validate(self, message), } .map_err(RouterError::ContextError), - MsgEnvelope::ConnectionMsg(message) => match message { - ConnectionMsg::ConnectionOpenInit(message) => { - conn_open_init::validate(self, message) - } - ConnectionMsg::ConnectionOpenTry(message) => { - conn_open_try::validate(self, message) - } - ConnectionMsg::ConnectionOpenAck(message) => { - conn_open_ack::validate(self, message) - } - ConnectionMsg::ConnectionOpenConfirm(ref message) => { + MsgEnvelope::Connection(message) => match message { + ConnectionMsg::OpenInit(message) => conn_open_init::validate(self, message), + ConnectionMsg::OpenTry(message) => conn_open_try::validate(self, message), + ConnectionMsg::OpenAck(message) => conn_open_ack::validate(self, message), + ConnectionMsg::OpenConfirm(ref message) => { conn_open_confirm::validate(self, message) } } .map_err(RouterError::ContextError), - MsgEnvelope::ChannelMsg(_message) => todo!(), - MsgEnvelope::PacketMsg(_message) => todo!(), + MsgEnvelope::Channel(_message) => todo!(), + MsgEnvelope::Packet(_message) => todo!(), } } @@ -335,30 +329,24 @@ mod val_exec_ctx { Self: Sized, { match message { - MsgEnvelope::ClientMsg(message) => match message { + MsgEnvelope::Client(message) => match message { ClientMsg::CreateClient(message) => create_client::execute(self, message), ClientMsg::UpdateClient(message) => update_client::execute(self, message), ClientMsg::Misbehaviour(message) => misbehaviour::execute(self, message), ClientMsg::UpgradeClient(message) => upgrade_client::execute(self, message), } .map_err(RouterError::ContextError), - MsgEnvelope::ConnectionMsg(message) => match message { - ConnectionMsg::ConnectionOpenInit(message) => { - conn_open_init::execute(self, message) - } - ConnectionMsg::ConnectionOpenTry(message) => { - conn_open_try::execute(self, message) - } - ConnectionMsg::ConnectionOpenAck(message) => { - conn_open_ack::execute(self, message) - } - ConnectionMsg::ConnectionOpenConfirm(ref message) => { + MsgEnvelope::Connection(message) => match message { + ConnectionMsg::OpenInit(message) => conn_open_init::execute(self, message), + ConnectionMsg::OpenTry(message) => conn_open_try::execute(self, message), + ConnectionMsg::OpenAck(message) => conn_open_ack::execute(self, message), + ConnectionMsg::OpenConfirm(ref message) => { conn_open_confirm::execute(self, message) } } .map_err(RouterError::ContextError), - MsgEnvelope::ChannelMsg(_message) => todo!(), - MsgEnvelope::PacketMsg(_message) => todo!(), + MsgEnvelope::Channel(_message) => todo!(), + MsgEnvelope::Packet(_message) => todo!(), } } diff --git a/crates/ibc/src/core/ics02_client/handler.rs b/crates/ibc/src/core/ics02_client/handler.rs index 4190c3a07..2bb86f7b7 100644 --- a/crates/ibc/src/core/ics02_client/handler.rs +++ b/crates/ibc/src/core/ics02_client/handler.rs @@ -19,7 +19,10 @@ pub enum ClientResult { } /// General entry point for processing any message related to ICS2 (client functions) protocols. -pub fn dispatch(ctx: &Ctx, msg: ClientMsg) -> Result, ClientError> +pub(crate) fn dispatch( + ctx: &Ctx, + msg: ClientMsg, +) -> Result, ClientError> where Ctx: ClientReader, { diff --git a/crates/ibc/src/core/ics02_client/handler/create_client.rs b/crates/ibc/src/core/ics02_client/handler/create_client.rs index 5d6ddb1bb..c0044096b 100644 --- a/crates/ibc/src/core/ics02_client/handler/create_client.rs +++ b/crates/ibc/src/core/ics02_client/handler/create_client.rs @@ -129,7 +129,7 @@ where Ok(()) } -pub fn process( +pub(crate) fn process( ctx: &dyn ClientReader, msg: MsgCreateClient, ) -> HandlerResult { diff --git a/crates/ibc/src/core/ics02_client/handler/misbehaviour.rs b/crates/ibc/src/core/ics02_client/handler/misbehaviour.rs index 37907791b..e42e9417d 100644 --- a/crates/ibc/src/core/ics02_client/handler/misbehaviour.rs +++ b/crates/ibc/src/core/ics02_client/handler/misbehaviour.rs @@ -83,7 +83,7 @@ where ctx.store_client_state(ClientStatePath(client_id), client_state) } -pub fn process( +pub(crate) fn process( ctx: &dyn ClientReader, msg: MsgSubmitMisbehaviour, ) -> HandlerResult { diff --git a/crates/ibc/src/core/ics02_client/handler/update_client.rs b/crates/ibc/src/core/ics02_client/handler/update_client.rs index dcfd8c1f0..986ec108f 100644 --- a/crates/ibc/src/core/ics02_client/handler/update_client.rs +++ b/crates/ibc/src/core/ics02_client/handler/update_client.rs @@ -143,7 +143,7 @@ where Ok(()) } -pub fn process( +pub(crate) fn process( ctx: &Ctx, msg: MsgUpdateClient, ) -> HandlerResult { diff --git a/crates/ibc/src/core/ics02_client/handler/upgrade_client.rs b/crates/ibc/src/core/ics02_client/handler/upgrade_client.rs index 7c2019a23..1fc36065b 100644 --- a/crates/ibc/src/core/ics02_client/handler/upgrade_client.rs +++ b/crates/ibc/src/core/ics02_client/handler/upgrade_client.rs @@ -91,7 +91,7 @@ where Ok(()) } -pub fn process( +pub(crate) fn process( ctx: &dyn ClientReader, msg: MsgUpgradeClient, ) -> HandlerResult { diff --git a/crates/ibc/src/core/ics02_client/msgs.rs b/crates/ibc/src/core/ics02_client/msgs.rs index de807cfbb..476f34cb6 100644 --- a/crates/ibc/src/core/ics02_client/msgs.rs +++ b/crates/ibc/src/core/ics02_client/msgs.rs @@ -14,6 +14,7 @@ pub mod misbehaviour; pub mod update_client; pub mod upgrade_client; +#[allow(dead_code)] #[derive(Clone, Debug)] pub enum ClientMsg { CreateClient(MsgCreateClient), diff --git a/crates/ibc/src/core/ics02_client/msgs/update_client.rs b/crates/ibc/src/core/ics02_client/msgs/update_client.rs index 50644c4dd..57d470273 100644 --- a/crates/ibc/src/core/ics02_client/msgs/update_client.rs +++ b/crates/ibc/src/core/ics02_client/msgs/update_client.rs @@ -21,16 +21,6 @@ pub struct MsgUpdateClient { pub signer: Signer, } -impl MsgUpdateClient { - pub fn new(client_id: ClientId, header: Any, signer: Signer) -> Self { - MsgUpdateClient { - client_id, - header, - signer, - } - } -} - impl Msg for MsgUpdateClient { type Raw = RawMsgUpdateClient; @@ -71,13 +61,25 @@ mod tests { use test_log::test; + use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::core::client::v1::MsgUpdateClient as RawMsgUpdateClient; use crate::clients::ics07_tendermint::header::test_util::get_dummy_ics07_header; use crate::core::ics02_client::msgs::MsgUpdateClient; use crate::core::ics24_host::identifier::ClientId; + use crate::signer::Signer; use crate::test_utils::get_dummy_account_id; + impl MsgUpdateClient { + pub fn new(client_id: ClientId, header: Any, signer: Signer) -> Self { + MsgUpdateClient { + client_id, + header, + signer, + } + } + } + #[test] fn msg_update_client_serialization() { let client_id: ClientId = "tendermint".parse().unwrap(); diff --git a/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs b/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs index a0bba4003..754d220ae 100644 --- a/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs +++ b/crates/ibc/src/core/ics02_client/msgs/upgrade_client.rs @@ -29,26 +29,6 @@ pub struct MsgUpgradeClient { pub signer: Signer, } -impl MsgUpgradeClient { - pub fn new( - client_id: ClientId, - client_state: Any, - consensus_state: Any, - proof_upgrade_client: RawMerkleProof, - proof_upgrade_consensus_state: RawMerkleProof, - signer: Signer, - ) -> Self { - MsgUpgradeClient { - client_id, - client_state, - consensus_state, - proof_upgrade_client, - proof_upgrade_consensus_state, - signer, - } - } -} - impl Msg for MsgUpgradeClient { type Raw = RawMsgUpgradeClient; @@ -114,7 +94,9 @@ impl TryFrom for MsgUpgradeClient { #[cfg(test)] pub mod test_util { + use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::core::client::v1::MsgUpgradeClient as RawMsgUpgradeClient; + use ibc_proto::ibc::core::commitment::v1::MerkleProof as RawMerkleProof; use crate::{ core::{ics02_client::height::Height, ics24_host::identifier::ClientId}, @@ -125,13 +107,32 @@ pub mod test_util { }; use super::MsgUpgradeClient; + use crate::signer::Signer; /// Extends the implementation with additional helper methods. impl MsgUpgradeClient { - /// Setter for `client_id`. Amenable to chaining, since it consumes the input message. - pub fn with_client_id(self, client_id: ClientId) -> Self { - MsgUpgradeClient { client_id, ..self } + pub fn new( + client_id: ClientId, + client_state: Any, + consensus_state: Any, + proof_upgrade_client: RawMerkleProof, + proof_upgrade_consensus_state: RawMerkleProof, + signer: Signer, + ) -> Self { + MsgUpgradeClient { + client_id, + client_state, + consensus_state, + proof_upgrade_client, + proof_upgrade_consensus_state, + signer, + } } + + // /// Setter for `client_id`. Amenable to chaining, since it consumes the input message. + // pub fn with_client_id(self, client_id: ClientId) -> Self { + // MsgUpgradeClient { client_id, ..self } + // } } /// Returns a dummy `RawMsgUpgradeClient`, for testing only! diff --git a/crates/ibc/src/core/ics03_connection/handler.rs b/crates/ibc/src/core/ics03_connection/handler.rs index 75afe20fd..30d233a07 100644 --- a/crates/ibc/src/core/ics03_connection/handler.rs +++ b/crates/ibc/src/core/ics03_connection/handler.rs @@ -40,7 +40,7 @@ pub struct ConnectionResult { /// General entry point for processing any type of message related to the ICS3 connection open /// handshake protocol. -pub fn dispatch( +pub(crate) fn dispatch( ctx: &Ctx, msg: ConnectionMsg, ) -> Result, ConnectionError> @@ -48,9 +48,9 @@ where Ctx: ConnectionReader, { match msg { - ConnectionMsg::ConnectionOpenInit(msg) => conn_open_init::process(ctx, msg), - ConnectionMsg::ConnectionOpenTry(msg) => conn_open_try::process(ctx, msg), - ConnectionMsg::ConnectionOpenAck(msg) => conn_open_ack::process(ctx, msg), - ConnectionMsg::ConnectionOpenConfirm(msg) => conn_open_confirm::process(ctx, msg), + ConnectionMsg::OpenInit(msg) => conn_open_init::process(ctx, msg), + ConnectionMsg::OpenTry(msg) => conn_open_try::process(ctx, msg), + ConnectionMsg::OpenAck(msg) => conn_open_ack::process(ctx, msg), + ConnectionMsg::OpenConfirm(msg) => conn_open_confirm::process(ctx, msg), } } diff --git a/crates/ibc/src/core/ics03_connection/handler/conn_open_ack.rs b/crates/ibc/src/core/ics03_connection/handler/conn_open_ack.rs index 58f623639..edb307d44 100644 --- a/crates/ibc/src/core/ics03_connection/handler/conn_open_ack.rs +++ b/crates/ibc/src/core/ics03_connection/handler/conn_open_ack.rs @@ -416,7 +416,7 @@ mod tests { .clone() .with_client(&client_id, proof_height) .with_connection(conn_id.clone(), default_conn_end), - msg: ConnectionMsg::ConnectionOpenAck(msg_ack.clone()), + msg: ConnectionMsg::OpenAck(msg_ack.clone()), want_pass: true, match_error: Box::new(|_| panic!("should not have error")), }, @@ -424,7 +424,7 @@ mod tests { name: "Processing fails because the connection does not exist in the context" .to_string(), ctx: default_context.clone(), - msg: ConnectionMsg::ConnectionOpenAck(msg_ack.clone()), + msg: ConnectionMsg::OpenAck(msg_ack.clone()), want_pass: false, match_error: { let right_connection_id = conn_id.clone(); @@ -444,7 +444,7 @@ mod tests { ctx: default_context .with_client(&client_id, proof_height) .with_connection(conn_id.clone(), conn_end_open), - msg: ConnectionMsg::ConnectionOpenAck(msg_ack), + msg: ConnectionMsg::OpenAck(msg_ack), want_pass: false, match_error: { let right_connection_id = conn_id; @@ -476,7 +476,7 @@ mod tests { { let res = ValidationContext::validate( &test.ctx, - MsgEnvelope::ConnectionMsg(test.msg.clone()), + MsgEnvelope::Connection(test.msg.clone()), ); match res { diff --git a/crates/ibc/src/core/ics03_connection/handler/conn_open_confirm.rs b/crates/ibc/src/core/ics03_connection/handler/conn_open_confirm.rs index 2c53817b1..f0e03e5be 100644 --- a/crates/ibc/src/core/ics03_connection/handler/conn_open_confirm.rs +++ b/crates/ibc/src/core/ics03_connection/handler/conn_open_confirm.rs @@ -316,7 +316,7 @@ mod tests { Test { name: "Processing fails due to missing connection in context".to_string(), ctx: context.clone(), - msg: ConnectionMsg::ConnectionOpenConfirm(msg_confirm.clone()), + msg: ConnectionMsg::OpenConfirm(msg_confirm.clone()), want_pass: false, }, Test { @@ -325,7 +325,7 @@ mod tests { .clone() .with_client(&client_id, Height::new(0, 10).unwrap()) .with_connection(msg_confirm.conn_id_on_b.clone(), incorrect_conn_end_state), - msg: ConnectionMsg::ConnectionOpenConfirm(msg_confirm.clone()), + msg: ConnectionMsg::OpenConfirm(msg_confirm.clone()), want_pass: false, }, Test { @@ -333,7 +333,7 @@ mod tests { ctx: context .with_client(&client_id, Height::new(0, 10).unwrap()) .with_connection(msg_confirm.conn_id_on_b.clone(), correct_conn_end), - msg: ConnectionMsg::ConnectionOpenConfirm(msg_confirm), + msg: ConnectionMsg::OpenConfirm(msg_confirm), want_pass: true, }, ] @@ -345,7 +345,7 @@ mod tests { { let res = ValidationContext::validate( &test.ctx, - MsgEnvelope::ConnectionMsg(test.msg.clone()), + MsgEnvelope::Connection(test.msg.clone()), ); match res { diff --git a/crates/ibc/src/core/ics03_connection/handler/conn_open_init.rs b/crates/ibc/src/core/ics03_connection/handler/conn_open_init.rs index 49aae7a12..136d74664 100644 --- a/crates/ibc/src/core/ics03_connection/handler/conn_open_init.rs +++ b/crates/ibc/src/core/ics03_connection/handler/conn_open_init.rs @@ -211,28 +211,28 @@ mod tests { Test { name: "Processing fails because no client exists in the context".to_string(), ctx: default_context, - msg: ConnectionMsg::ConnectionOpenInit(msg_conn_init_default.clone()), + msg: ConnectionMsg::OpenInit(msg_conn_init_default.clone()), expected_versions: vec![msg_conn_init_default.version.clone().unwrap()], want_pass: false, }, Test { name: "Incompatible version in MsgConnectionOpenInit msg".to_string(), ctx: good_context.clone(), - msg: ConnectionMsg::ConnectionOpenInit(msg_conn_init_bad_version), + msg: ConnectionMsg::OpenInit(msg_conn_init_bad_version), expected_versions: vec![], want_pass: false, }, Test { name: "No version in MsgConnectionOpenInit msg".to_string(), ctx: good_context.clone(), - msg: ConnectionMsg::ConnectionOpenInit(msg_conn_init_no_version), + msg: ConnectionMsg::OpenInit(msg_conn_init_no_version), expected_versions: ConnectionReader::get_compatible_versions(&good_context), want_pass: true, }, Test { name: "Good parameters".to_string(), ctx: good_context, - msg: ConnectionMsg::ConnectionOpenInit(msg_conn_init_default.clone()), + msg: ConnectionMsg::OpenInit(msg_conn_init_default.clone()), expected_versions: vec![msg_conn_init_default.version.unwrap()], want_pass: true, }, @@ -245,7 +245,7 @@ mod tests { { let res = ValidationContext::validate( &test.ctx, - MsgEnvelope::ConnectionMsg(test.msg.clone()), + MsgEnvelope::Connection(test.msg.clone()), ); match res { diff --git a/crates/ibc/src/core/ics03_connection/handler/conn_open_try.rs b/crates/ibc/src/core/ics03_connection/handler/conn_open_try.rs index 0c27486d1..7c9cec03e 100644 --- a/crates/ibc/src/core/ics03_connection/handler/conn_open_try.rs +++ b/crates/ibc/src/core/ics03_connection/handler/conn_open_try.rs @@ -401,37 +401,37 @@ mod tests { Test { name: "Processing fails because the height is too advanced".to_string(), ctx: context.clone(), - msg: ConnectionMsg::ConnectionOpenTry(msg_height_advanced), + msg: ConnectionMsg::OpenTry(msg_height_advanced), want_pass: false, }, Test { name: "Processing fails because the height is too old".to_string(), ctx: context.clone(), - msg: ConnectionMsg::ConnectionOpenTry(msg_height_old), + msg: ConnectionMsg::OpenTry(msg_height_old), want_pass: false, }, Test { name: "Processing fails because no client exists".to_string(), ctx: context.clone(), - msg: ConnectionMsg::ConnectionOpenTry(msg_conn_try.clone()), + msg: ConnectionMsg::OpenTry(msg_conn_try.clone()), want_pass: false, }, Test { name: "Processing fails because the client misses the consensus state targeted by the proof".to_string(), ctx: context.clone().with_client(&msg_proof_height_missing.client_id_on_b, Height::new(0, client_consensus_state_height).unwrap()), - msg: ConnectionMsg::ConnectionOpenTry(msg_proof_height_missing), + msg: ConnectionMsg::OpenTry(msg_proof_height_missing), want_pass: false, }, Test { name: "Good parameters (no previous_connection_id)".to_string(), ctx: context.clone().with_client(&msg_conn_try.client_id_on_b, Height::new(0, client_consensus_state_height).unwrap()), - msg: ConnectionMsg::ConnectionOpenTry(msg_conn_try.clone()), + msg: ConnectionMsg::OpenTry(msg_conn_try.clone()), want_pass: true, }, Test { name: "Good parameters".to_string(), ctx: context.with_client(&msg_conn_try.client_id_on_b, Height::new(0, client_consensus_state_height).unwrap()), - msg: ConnectionMsg::ConnectionOpenTry(msg_conn_try), + msg: ConnectionMsg::OpenTry(msg_conn_try), want_pass: true, }, ] @@ -443,7 +443,7 @@ mod tests { { let res = ValidationContext::validate( &test.ctx, - MsgEnvelope::ConnectionMsg(test.msg.clone()), + MsgEnvelope::Connection(test.msg.clone()), ); match res { diff --git a/crates/ibc/src/core/ics03_connection/msgs.rs b/crates/ibc/src/core/ics03_connection/msgs.rs index 6f1b00162..97dcba6e4 100644 --- a/crates/ibc/src/core/ics03_connection/msgs.rs +++ b/crates/ibc/src/core/ics03_connection/msgs.rs @@ -25,10 +25,10 @@ pub mod conn_open_try; /// Enumeration of all possible messages that the ICS3 protocol processes. #[derive(Clone, Debug, PartialEq, Eq)] pub enum ConnectionMsg { - ConnectionOpenInit(MsgConnectionOpenInit), - ConnectionOpenTry(MsgConnectionOpenTry), - ConnectionOpenAck(MsgConnectionOpenAck), - ConnectionOpenConfirm(MsgConnectionOpenConfirm), + OpenInit(MsgConnectionOpenInit), + OpenTry(MsgConnectionOpenTry), + OpenAck(MsgConnectionOpenAck), + OpenConfirm(MsgConnectionOpenConfirm), } #[cfg(test)] diff --git a/crates/ibc/src/core/ics04_channel/handler.rs b/crates/ibc/src/core/ics04_channel/handler.rs index dd269c162..a9dd71cd3 100644 --- a/crates/ibc/src/core/ics04_channel/handler.rs +++ b/crates/ibc/src/core/ics04_channel/handler.rs @@ -64,7 +64,7 @@ impl ModuleExtras { } } -pub fn channel_validate(ctx: &Ctx, msg: &ChannelMsg) -> Result +pub(crate) fn channel_validate(ctx: &Ctx, msg: &ChannelMsg) -> Result where Ctx: RouterContext, { @@ -78,7 +78,7 @@ where /// General entry point for processing any type of message related to the ICS4 channel open and /// channel close handshake protocols. -pub fn channel_dispatch( +pub(crate) fn channel_dispatch( ctx: &Ctx, msg: &ChannelMsg, ) -> Result<(Vec, ChannelResult), ChannelError> @@ -86,19 +86,19 @@ where Ctx: ChannelReader, { let output = match msg { - ChannelMsg::ChannelOpenInit(msg) => chan_open_init::process(ctx, msg), - ChannelMsg::ChannelOpenTry(msg) => chan_open_try::process(ctx, msg), - ChannelMsg::ChannelOpenAck(msg) => chan_open_ack::process(ctx, msg), - ChannelMsg::ChannelOpenConfirm(msg) => chan_open_confirm::process(ctx, msg), - ChannelMsg::ChannelCloseInit(msg) => chan_close_init::process(ctx, msg), - ChannelMsg::ChannelCloseConfirm(msg) => chan_close_confirm::process(ctx, msg), + ChannelMsg::OpenInit(msg) => chan_open_init::process(ctx, msg), + ChannelMsg::OpenTry(msg) => chan_open_try::process(ctx, msg), + ChannelMsg::OpenAck(msg) => chan_open_ack::process(ctx, msg), + ChannelMsg::OpenConfirm(msg) => chan_open_confirm::process(ctx, msg), + ChannelMsg::CloseInit(msg) => chan_close_init::process(ctx, msg), + ChannelMsg::CloseConfirm(msg) => chan_close_confirm::process(ctx, msg), }?; let HandlerOutput { result, log, .. } = output; Ok((log, result)) } -pub fn channel_callback( +pub(crate) fn channel_callback( ctx: &mut Ctx, module_id: &ModuleId, msg: &ChannelMsg, @@ -113,7 +113,7 @@ where .ok_or(ChannelError::RouteNotFound)?; match msg { - ChannelMsg::ChannelOpenInit(msg) => { + ChannelMsg::OpenInit(msg) => { let (extras, version) = cb.on_chan_open_init( msg.chan_end_on_a.ordering, &msg.chan_end_on_a.connection_hops, @@ -126,7 +126,7 @@ where Ok(extras) } - ChannelMsg::ChannelOpenTry(msg) => { + ChannelMsg::OpenTry(msg) => { let (extras, version) = cb.on_chan_open_try( msg.chan_end_on_b.ordering, &msg.chan_end_on_b.connection_hops, @@ -139,23 +139,21 @@ where Ok(extras) } - ChannelMsg::ChannelOpenAck(msg) => { + ChannelMsg::OpenAck(msg) => { cb.on_chan_open_ack(&msg.port_id_on_a, &result.channel_id, &msg.version_on_b) } - ChannelMsg::ChannelOpenConfirm(msg) => { + ChannelMsg::OpenConfirm(msg) => { cb.on_chan_open_confirm(&msg.port_id_on_b, &result.channel_id) } - ChannelMsg::ChannelCloseInit(msg) => { - cb.on_chan_close_init(&msg.port_id_on_a, &result.channel_id) - } - ChannelMsg::ChannelCloseConfirm(msg) => { + ChannelMsg::CloseInit(msg) => cb.on_chan_close_init(&msg.port_id_on_a, &result.channel_id), + ChannelMsg::CloseConfirm(msg) => { cb.on_chan_close_confirm(&msg.port_id_on_b, &result.channel_id) } } } /// Constructs the proper channel event -pub fn channel_events( +pub(crate) fn channel_events( msg: &ChannelMsg, channel_id: ChannelId, counterparty: Counterparty, @@ -163,14 +161,14 @@ pub fn channel_events( version: &Version, ) -> Vec { let event = match msg { - ChannelMsg::ChannelOpenInit(msg) => IbcEvent::OpenInitChannel(OpenInit::new( + ChannelMsg::OpenInit(msg) => IbcEvent::OpenInitChannel(OpenInit::new( msg.port_id_on_a.clone(), channel_id, counterparty.port_id, connection_id, version.clone(), )), - ChannelMsg::ChannelOpenTry(msg) => IbcEvent::OpenTryChannel(OpenTry::new( + ChannelMsg::OpenTry(msg) => IbcEvent::OpenTryChannel(OpenTry::new( msg.port_id_on_b.clone(), channel_id, counterparty.port_id, @@ -180,7 +178,7 @@ pub fn channel_events( connection_id, version.clone(), )), - ChannelMsg::ChannelOpenAck(msg) => IbcEvent::OpenAckChannel(OpenAck::new( + ChannelMsg::OpenAck(msg) => IbcEvent::OpenAckChannel(OpenAck::new( msg.port_id_on_a.clone(), channel_id, counterparty.port_id, @@ -189,7 +187,7 @@ pub fn channel_events( .expect("counterparty channel id must exist after channel open ack"), connection_id, )), - ChannelMsg::ChannelOpenConfirm(msg) => IbcEvent::OpenConfirmChannel(OpenConfirm::new( + ChannelMsg::OpenConfirm(msg) => IbcEvent::OpenConfirmChannel(OpenConfirm::new( msg.port_id_on_b.clone(), channel_id, counterparty.port_id, @@ -198,7 +196,7 @@ pub fn channel_events( .expect("counterparty channel id must exist after channel open confirm"), connection_id, )), - ChannelMsg::ChannelCloseInit(msg) => IbcEvent::CloseInitChannel(CloseInit::new( + ChannelMsg::CloseInit(msg) => IbcEvent::CloseInitChannel(CloseInit::new( msg.port_id_on_a.clone(), channel_id, counterparty.port_id, @@ -207,7 +205,7 @@ pub fn channel_events( .expect("counterparty channel id must exist after channel open ack"), connection_id, )), - ChannelMsg::ChannelCloseConfirm(msg) => IbcEvent::CloseConfirmChannel(CloseConfirm::new( + ChannelMsg::CloseConfirm(msg) => IbcEvent::CloseConfirmChannel(CloseConfirm::new( msg.port_id_on_b.clone(), channel_id, counterparty.port_id, @@ -221,7 +219,10 @@ pub fn channel_events( vec![event] } -pub fn get_module_for_packet_msg(ctx: &Ctx, msg: &PacketMsg) -> Result +pub(crate) fn get_module_for_packet_msg( + ctx: &Ctx, + msg: &PacketMsg, +) -> Result where Ctx: RouterContext, { @@ -234,7 +235,7 @@ where } /// Dispatcher for processing any type of message related to the ICS4 packet protocols. -pub fn packet_dispatch( +pub(crate) fn packet_dispatch( ctx: &Ctx, msg: &PacketMsg, ) -> Result<(HandlerOutputBuilder<()>, PacketResult), PacketError> @@ -242,10 +243,10 @@ where Ctx: ChannelReader, { let output = match msg { - PacketMsg::RecvPacket(msg) => recv_packet::process(ctx, msg), - PacketMsg::AckPacket(msg) => acknowledgement::process(ctx, msg), - PacketMsg::TimeoutPacket(msg) => timeout::process(ctx, msg), - PacketMsg::TimeoutOnClosePacket(msg) => timeout_on_close::process(ctx, msg), + PacketMsg::Recv(msg) => recv_packet::process(ctx, msg), + PacketMsg::Ack(msg) => acknowledgement::process(ctx, msg), + PacketMsg::Timeout(msg) => timeout::process(ctx, msg), + PacketMsg::TimeoutOnClose(msg) => timeout_on_close::process(ctx, msg), }?; let HandlerOutput { result, @@ -256,7 +257,7 @@ where Ok((builder, result)) } -pub fn packet_callback( +pub(crate) fn packet_callback( ctx: &mut Ctx, module_id: &ModuleId, msg: &PacketMsg, @@ -288,7 +289,7 @@ fn do_packet_callback( .ok_or(PacketError::RouteNotFound)?; match msg { - PacketMsg::RecvPacket(msg) => { + PacketMsg::Recv(msg) => { let result = cb.on_recv_packet(module_output, &msg.packet, &msg.signer); match result { OnRecvPacketAck::Nil(write_fn) => { @@ -305,16 +306,14 @@ fn do_packet_callback( } } } - PacketMsg::AckPacket(msg) => cb.on_acknowledgement_packet( + PacketMsg::Ack(msg) => cb.on_acknowledgement_packet( module_output, &msg.packet, &msg.acknowledgement, &msg.signer, ), - PacketMsg::TimeoutPacket(msg) => { - cb.on_timeout_packet(module_output, &msg.packet, &msg.signer) - } - PacketMsg::TimeoutOnClosePacket(msg) => { + PacketMsg::Timeout(msg) => cb.on_timeout_packet(module_output, &msg.packet, &msg.signer), + PacketMsg::TimeoutOnClose(msg) => { cb.on_timeout_packet(module_output, &msg.packet, &msg.signer) } } diff --git a/crates/ibc/src/core/ics04_channel/handler/acknowledgement.rs b/crates/ibc/src/core/ics04_channel/handler/acknowledgement.rs index d7b34d822..87ea08b2d 100644 --- a/crates/ibc/src/core/ics04_channel/handler/acknowledgement.rs +++ b/crates/ibc/src/core/ics04_channel/handler/acknowledgement.rs @@ -19,8 +19,7 @@ pub struct AckPacketResult { pub seq_number: Option, } -/// Per our convention, this message is processed on chain A. -pub fn process( +pub(crate) fn process( ctx_a: &Ctx, msg: &MsgAcknowledgement, ) -> HandlerResult { diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_close_confirm.rs b/crates/ibc/src/core/ics04_channel/handler/chan_close_confirm.rs index da1c75529..74d29d5bd 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_close_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_close_confirm.rs @@ -171,10 +171,6 @@ mod tests { chan_end, ); - channel_dispatch( - &context, - &ChannelMsg::ChannelCloseConfirm(msg_chan_close_confirm), - ) - .unwrap(); + channel_dispatch(&context, &ChannelMsg::CloseConfirm(msg_chan_close_confirm)).unwrap(); } } diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_close_init.rs b/crates/ibc/src/core/ics04_channel/handler/chan_close_init.rs index 745a5b261..4db9e1b06 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_close_init.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_close_init.rs @@ -123,6 +123,6 @@ mod tests { ) }; - channel_dispatch(&context, &ChannelMsg::ChannelCloseInit(msg_chan_close_init)).unwrap(); + channel_dispatch(&context, &ChannelMsg::CloseInit(msg_chan_close_init)).unwrap(); } } diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_open_ack.rs b/crates/ibc/src/core/ics04_channel/handler/chan_open_ack.rs index 63783ca80..788448fd2 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_open_ack.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_open_ack.rs @@ -222,7 +222,7 @@ mod tests { Test { name: "Processing fails because no channel exists in the context".to_string(), ctx: context.clone(), - msg: ChannelMsg::ChannelOpenAck(msg_chan_ack.clone()), + msg: ChannelMsg::OpenAck(msg_chan_ack.clone()), want_pass: false, }, Test { @@ -238,7 +238,7 @@ mod tests { msg_chan_ack.chan_id_on_a.clone(), failed_chan_end, ), - msg: ChannelMsg::ChannelOpenAck(msg_chan_ack.clone()), + msg: ChannelMsg::OpenAck(msg_chan_ack.clone()), want_pass: false, }, Test { @@ -254,7 +254,7 @@ mod tests { msg_chan_ack.chan_id_on_a.clone(), chan_end.clone(), ), - msg: ChannelMsg::ChannelOpenAck(msg_chan_ack.clone()), + msg: ChannelMsg::OpenAck(msg_chan_ack.clone()), want_pass: false, }, Test { @@ -267,7 +267,7 @@ mod tests { msg_chan_ack.chan_id_on_a.clone(), chan_end.clone(), ), - msg: ChannelMsg::ChannelOpenAck(msg_chan_ack.clone()), + msg: ChannelMsg::OpenAck(msg_chan_ack.clone()), want_pass: false, }, Test { @@ -283,7 +283,7 @@ mod tests { msg_chan_ack.chan_id_on_a.clone(), chan_end, ), - msg: ChannelMsg::ChannelOpenAck(msg_chan_ack), + msg: ChannelMsg::OpenAck(msg_chan_ack), want_pass: true, }, ] diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs b/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs index 7c6f2237c..4eef3fe54 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_open_confirm.rs @@ -182,7 +182,7 @@ mod tests { msg_chan_confirm.chan_id_on_b.clone(), chan_end, ), - msg: ChannelMsg::ChannelOpenConfirm(msg_chan_confirm), + msg: ChannelMsg::OpenConfirm(msg_chan_confirm), want_pass: true, }] .into_iter() diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_open_init.rs b/crates/ibc/src/core/ics04_channel/handler/chan_open_init.rs index b4a929d00..09e59a68d 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_open_init.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_open_init.rs @@ -110,13 +110,13 @@ mod tests { Test { name: "Processing fails because no connection exists in the context".to_string(), ctx: context.clone(), - msg: ChannelMsg::ChannelOpenInit(msg_chan_init.clone()), + msg: ChannelMsg::OpenInit(msg_chan_init.clone()), want_pass: false, }, Test { name: "Good parameters".to_string(), ctx: context.with_connection(cid, init_conn_end), - msg: ChannelMsg::ChannelOpenInit(msg_chan_init), + msg: ChannelMsg::OpenInit(msg_chan_init), want_pass: true, }, ] @@ -140,7 +140,7 @@ mod tests { assert_eq!(res.channel_end.state().clone(), State::Init); let msg_init = test.msg; - if let ChannelMsg::ChannelOpenInit(msg_init) = msg_init { + if let ChannelMsg::OpenInit(msg_init) = msg_init { assert_eq!(res.port_id.clone(), msg_init.port_id_on_a.clone()); } } diff --git a/crates/ibc/src/core/ics04_channel/handler/chan_open_try.rs b/crates/ibc/src/core/ics04_channel/handler/chan_open_try.rs index ef40c1a23..f0f2e88b6 100644 --- a/crates/ibc/src/core/ics04_channel/handler/chan_open_try.rs +++ b/crates/ibc/src/core/ics04_channel/handler/chan_open_try.rs @@ -192,7 +192,7 @@ mod tests { Test { name: "Processing fails because no connection exists in the context".to_string(), ctx: context.clone(), - msg: ChannelMsg::ChannelOpenTry(msg.clone()), + msg: ChannelMsg::OpenTry(msg.clone()), want_pass: false, match_error: { let connection_id = msg.chan_end_on_b.connection_hops()[0].clone(); @@ -220,7 +220,7 @@ mod tests { chan_id.clone(), correct_chan_end.clone(), ), - msg: ChannelMsg::ChannelOpenTry(msg.clone()), + msg: ChannelMsg::OpenTry(msg.clone()), want_pass: false, match_error: Box::new(|e| match e { error::ChannelError::Connection(e) => { @@ -246,7 +246,7 @@ mod tests { .with_client(&client_id, Height::new(0, proof_height).unwrap()) .with_connection(conn_id.clone(), conn_end.clone()) .with_channel(msg.port_id_on_b.clone(), chan_id, correct_chan_end), - msg: ChannelMsg::ChannelOpenTry(msg.clone()), + msg: ChannelMsg::OpenTry(msg.clone()), want_pass: true, match_error: Box::new(|_| {}), }, @@ -256,7 +256,7 @@ mod tests { ctx: context .with_client(&client_id, Height::new(0, proof_height).unwrap()) .with_connection(conn_id, conn_end), - msg: ChannelMsg::ChannelOpenTry(msg), + msg: ChannelMsg::OpenTry(msg), want_pass: true, match_error: Box::new(|_| {}), }, @@ -265,7 +265,7 @@ mod tests { .collect(); for test in tests { - let test_msg = downcast!(test.msg => ChannelMsg::ChannelOpenTry).unwrap(); + let test_msg = downcast!(test.msg => ChannelMsg::OpenTry).unwrap(); let res = chan_open_try::process(&test.ctx, &test_msg); // Additionally check the events and the output objects in the result. match res { diff --git a/crates/ibc/src/core/ics04_channel/handler/recv_packet.rs b/crates/ibc/src/core/ics04_channel/handler/recv_packet.rs index ebe3b3d98..916465bc3 100644 --- a/crates/ibc/src/core/ics04_channel/handler/recv_packet.rs +++ b/crates/ibc/src/core/ics04_channel/handler/recv_packet.rs @@ -29,7 +29,7 @@ pub enum RecvPacketResult { } /// Per our convention, this message is processed on chain B. -pub fn process( +pub(crate) fn process( ctx_b: &Ctx, msg: &MsgRecvPacket, ) -> HandlerResult { diff --git a/crates/ibc/src/core/ics04_channel/handler/timeout.rs b/crates/ibc/src/core/ics04_channel/handler/timeout.rs index ae150de21..e5e55aec0 100644 --- a/crates/ibc/src/core/ics04_channel/handler/timeout.rs +++ b/crates/ibc/src/core/ics04_channel/handler/timeout.rs @@ -25,7 +25,7 @@ pub struct TimeoutPacketResult { /// packet can no longer be executed and to allow the calling module to safely /// perform appropriate state transitions. /// Per our convention, this message is processed on chain A. -pub fn process( +pub(crate) fn process( ctx_a: &Ctx, msg: &MsgTimeout, ) -> HandlerResult { diff --git a/crates/ibc/src/core/ics04_channel/handler/timeout_on_close.rs b/crates/ibc/src/core/ics04_channel/handler/timeout_on_close.rs index 2cf805c84..f721d8573 100644 --- a/crates/ibc/src/core/ics04_channel/handler/timeout_on_close.rs +++ b/crates/ibc/src/core/ics04_channel/handler/timeout_on_close.rs @@ -12,7 +12,7 @@ use crate::handler::{HandlerOutput, HandlerResult}; use crate::prelude::*; /// Per our convention, this message is processed on chain A. -pub fn process( +pub(crate) fn process( ctx_a: &Ctx, msg: &MsgTimeoutOnClose, ) -> HandlerResult { diff --git a/crates/ibc/src/core/ics04_channel/msgs.rs b/crates/ibc/src/core/ics04_channel/msgs.rs index 098e25add..5c34cee2c 100644 --- a/crates/ibc/src/core/ics04_channel/msgs.rs +++ b/crates/ibc/src/core/ics04_channel/msgs.rs @@ -33,23 +33,23 @@ pub mod timeout_on_close; /// Enumeration of all possible messages that the ICS4 protocol processes. #[derive(Clone, Debug, PartialEq, Eq)] pub enum ChannelMsg { - ChannelOpenInit(MsgChannelOpenInit), - ChannelOpenTry(MsgChannelOpenTry), - ChannelOpenAck(MsgChannelOpenAck), - ChannelOpenConfirm(MsgChannelOpenConfirm), - ChannelCloseInit(MsgChannelCloseInit), - ChannelCloseConfirm(MsgChannelCloseConfirm), + OpenInit(MsgChannelOpenInit), + OpenTry(MsgChannelOpenTry), + OpenAck(MsgChannelOpenAck), + OpenConfirm(MsgChannelOpenConfirm), + CloseInit(MsgChannelCloseInit), + CloseConfirm(MsgChannelCloseConfirm), } impl ChannelMsg { pub(super) fn lookup_module(&self, ctx: &impl RouterContext) -> Result { let port_id = match self { - ChannelMsg::ChannelOpenInit(msg) => &msg.port_id_on_a, - ChannelMsg::ChannelOpenTry(msg) => &msg.port_id_on_b, - ChannelMsg::ChannelOpenAck(msg) => &msg.port_id_on_a, - ChannelMsg::ChannelOpenConfirm(msg) => &msg.port_id_on_b, - ChannelMsg::ChannelCloseInit(msg) => &msg.port_id_on_a, - ChannelMsg::ChannelCloseConfirm(msg) => &msg.port_id_on_b, + ChannelMsg::OpenInit(msg) => &msg.port_id_on_a, + ChannelMsg::OpenTry(msg) => &msg.port_id_on_b, + ChannelMsg::OpenAck(msg) => &msg.port_id_on_a, + ChannelMsg::OpenConfirm(msg) => &msg.port_id_on_b, + ChannelMsg::CloseInit(msg) => &msg.port_id_on_a, + ChannelMsg::CloseConfirm(msg) => &msg.port_id_on_b, }; let module_id = ctx .lookup_module_by_port(port_id) @@ -60,19 +60,19 @@ impl ChannelMsg { #[derive(Clone, Debug, PartialEq, Eq)] pub enum PacketMsg { - RecvPacket(MsgRecvPacket), - AckPacket(MsgAcknowledgement), - TimeoutPacket(MsgTimeout), - TimeoutOnClosePacket(MsgTimeoutOnClose), + Recv(MsgRecvPacket), + Ack(MsgAcknowledgement), + Timeout(MsgTimeout), + TimeoutOnClose(MsgTimeoutOnClose), } impl PacketMsg { pub(super) fn lookup_module(&self, ctx: &impl RouterContext) -> Result { let port_id = match self { - PacketMsg::RecvPacket(msg) => &msg.packet.port_on_b, - PacketMsg::AckPacket(msg) => &msg.packet.port_on_a, - PacketMsg::TimeoutPacket(msg) => &msg.packet.port_on_a, - PacketMsg::TimeoutOnClosePacket(msg) => &msg.packet.port_on_a, + PacketMsg::Recv(msg) => &msg.packet.port_on_b, + PacketMsg::Ack(msg) => &msg.packet.port_on_a, + PacketMsg::Timeout(msg) => &msg.packet.port_on_a, + PacketMsg::TimeoutOnClose(msg) => &msg.packet.port_on_a, }; let module_id = ctx .lookup_module_by_port(port_id) diff --git a/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs b/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs index d59ff8e56..2aad08e7e 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/acknowledgement.rs @@ -60,28 +60,6 @@ pub struct MsgAcknowledgement { pub signer: Signer, } -impl MsgAcknowledgement { - pub fn new( - packet: Packet, - acknowledgement: Acknowledgement, - proof_acked_on_b: CommitmentProofBytes, - proof_height_on_b: Height, - signer: Signer, - ) -> MsgAcknowledgement { - Self { - packet, - acknowledgement, - proof_acked_on_b, - proof_height_on_b, - signer, - } - } - - pub fn acknowledgement(&self) -> &Acknowledgement { - &self.acknowledgement - } -} - impl Msg for MsgAcknowledgement { type Raw = RawMsgAcknowledgement; diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs index 5158e1ef6..3ac3a36b8 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_close_confirm.rs @@ -26,24 +26,6 @@ pub struct MsgChannelCloseConfirm { pub signer: Signer, } -impl MsgChannelCloseConfirm { - pub fn new( - port_id_on_b: PortId, - chan_id_on_b: ChannelId, - proof_chan_end_on_a: CommitmentProofBytes, - proof_height_on_a: Height, - signer: Signer, - ) -> Self { - Self { - port_id_on_b, - chan_id_on_b, - proof_chan_end_on_a, - proof_height_on_a, - signer, - } - } -} - impl Msg for MsgChannelCloseConfirm { type Raw = RawMsgChannelCloseConfirm; diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs index 5ef0cce5d..34e575710 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_close_init.rs @@ -22,16 +22,6 @@ pub struct MsgChannelCloseInit { pub signer: Signer, } -impl MsgChannelCloseInit { - pub fn new(port_id_on_a: PortId, chan_id_on_a: ChannelId, signer: Signer) -> Self { - Self { - port_id_on_a, - chan_id_on_a, - signer, - } - } -} - impl Msg for MsgChannelCloseInit { type Raw = RawMsgChannelCloseInit; diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs index d7a1ac353..97dc89bb2 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_ack.rs @@ -26,28 +26,6 @@ pub struct MsgChannelOpenAck { pub signer: Signer, } -impl MsgChannelOpenAck { - pub fn new( - port_id_on_a: PortId, - chan_id_on_a: ChannelId, - chan_id_on_b: ChannelId, - version_on_b: Version, - proof_chan_end_on_b: CommitmentProofBytes, - proof_height_on_b: Height, - signer: Signer, - ) -> Self { - Self { - port_id_on_a, - chan_id_on_a, - chan_id_on_b, - version_on_b, - proof_chan_end_on_b, - proof_height_on_b, - signer, - } - } -} - impl Msg for MsgChannelOpenAck { type Raw = RawMsgChannelOpenAck; diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs index 167c24ab8..b74309912 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_confirm.rs @@ -24,24 +24,6 @@ pub struct MsgChannelOpenConfirm { pub signer: Signer, } -impl MsgChannelOpenConfirm { - pub fn new( - port_id: PortId, - channel_id: ChannelId, - proof_chan_end_on_a: CommitmentProofBytes, - proof_height_on_a: Height, - signer: Signer, - ) -> Self { - Self { - port_id_on_b: port_id, - chan_id_on_b: channel_id, - proof_chan_end_on_a, - proof_height_on_a, - signer, - } - } -} - impl Msg for MsgChannelOpenConfirm { type Raw = RawMsgChannelOpenConfirm; diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs index 570bbda0e..eddfcf41f 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_init.rs @@ -21,16 +21,6 @@ pub struct MsgChannelOpenInit { pub signer: Signer, } -impl MsgChannelOpenInit { - pub fn new(port_id_on_a: PortId, chan_end_on_a: ChannelEnd, signer: Signer) -> Self { - Self { - port_id_on_a, - chan_end_on_a, - signer, - } - } -} - impl Msg for MsgChannelOpenInit { type Raw = RawMsgChannelOpenInit; diff --git a/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs b/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs index 9ee98da2a..78932f934 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/chan_open_try.rs @@ -31,28 +31,6 @@ pub struct MsgChannelOpenTry { pub previous_channel_id: String, } -impl MsgChannelOpenTry { - pub fn new( - port_id_on_b: PortId, - chan_end_on_b: ChannelEnd, - version_on_a: Version, - proof_chan_end_on_a: CommitmentProofBytes, - proof_height_on_a: Height, - signer: Signer, - ) -> Self { - #[allow(deprecated)] - Self { - port_id_on_b, - chan_end_on_b, - version_on_a, - proof_chan_end_on_a, - proof_height_on_a, - signer, - previous_channel_id: "".to_string(), - } - } -} - impl Msg for MsgChannelOpenTry { type Raw = RawMsgChannelOpenTry; diff --git a/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs b/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs index 950e34618..a0dc4c524 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/recv_packet.rs @@ -28,22 +28,6 @@ pub struct MsgRecvPacket { pub signer: Signer, } -impl MsgRecvPacket { - pub fn new( - packet: Packet, - proof_commitment_on_a: CommitmentProofBytes, - proof_height_on_a: Height, - signer: Signer, - ) -> MsgRecvPacket { - Self { - packet, - proof_commitment_on_a, - proof_height_on_a, - signer, - } - } -} - impl Msg for MsgRecvPacket { type Raw = RawMsgRecvPacket; @@ -92,12 +76,32 @@ pub mod test_util { use ibc_proto::ibc::core::channel::v1::MsgRecvPacket as RawMsgRecvPacket; use ibc_proto::ibc::core::client::v1::Height as RawHeight; + use super::MsgRecvPacket; use crate::core::ics04_channel::packet::test_utils::get_dummy_raw_packet; + use crate::core::ics04_channel::packet::Packet; + use crate::core::ics23_commitment::commitment::CommitmentProofBytes; + use crate::signer::Signer; use crate::test_utils::{get_dummy_bech32_account, get_dummy_proof}; use crate::timestamp::Timestamp; use core::ops::Add; use core::time::Duration; + impl MsgRecvPacket { + pub fn new( + packet: Packet, + proof_commitment_on_a: CommitmentProofBytes, + proof_height_on_a: crate::Height, + signer: Signer, + ) -> MsgRecvPacket { + Self { + packet, + proof_commitment_on_a, + proof_height_on_a, + signer, + } + } + } + /// Returns a dummy `RawMsgRecvPacket`, for testing only! The `height` parametrizes both the /// proof height as well as the timeout height. pub fn get_dummy_raw_msg_recv_packet(height: u64) -> RawMsgRecvPacket { diff --git a/crates/ibc/src/core/ics04_channel/msgs/timeout.rs b/crates/ibc/src/core/ics04_channel/msgs/timeout.rs index bc91f19c7..368832ab9 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/timeout.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/timeout.rs @@ -26,24 +26,6 @@ pub struct MsgTimeout { pub signer: Signer, } -impl MsgTimeout { - pub fn new( - packet: Packet, - next_seq_recv_on_b: Sequence, - proof_unreceived_on_b: CommitmentProofBytes, - proof_height_on_b: Height, - signer: Signer, - ) -> MsgTimeout { - Self { - packet, - next_seq_recv_on_b, - proof_unreceived_on_b, - proof_height_on_b, - signer, - } - } -} - impl Msg for MsgTimeout { type Raw = RawMsgTimeout; diff --git a/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs b/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs index 700548327..8158ed397 100644 --- a/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs +++ b/crates/ibc/src/core/ics04_channel/msgs/timeout_on_close.rs @@ -25,26 +25,6 @@ pub struct MsgTimeoutOnClose { pub signer: Signer, } -impl MsgTimeoutOnClose { - pub fn new( - packet: Packet, - next_seq_recv_on_b: Sequence, - proof_unreceived_on_b: CommitmentProofBytes, - proof_close_on_b: CommitmentProofBytes, - proof_height_on_b: Height, - signer: Signer, - ) -> MsgTimeoutOnClose { - Self { - packet, - next_seq_recv_on_b, - proof_unreceived_on_b, - proof_close_on_b, - proof_height_on_b, - signer, - } - } -} - impl Msg for MsgTimeoutOnClose { type Raw = RawMsgTimeoutOnClose; diff --git a/crates/ibc/src/core/ics26_routing/handler.rs b/crates/ibc/src/core/ics26_routing/handler.rs index dbb8fb397..a0b9a93cd 100644 --- a/crates/ibc/src/core/ics26_routing/handler.rs +++ b/crates/ibc/src/core/ics26_routing/handler.rs @@ -15,9 +15,7 @@ use crate::core::ics04_channel::handler::{ use crate::core::ics04_channel::packet::PacketResult; use crate::core::ics26_routing::context::RouterContext; use crate::core::ics26_routing::error::RouterError; -use crate::core::ics26_routing::msgs::MsgEnvelope::{ - self, ChannelMsg, ClientMsg, ConnectionMsg, PacketMsg, -}; +use crate::core::ics26_routing::msgs::MsgEnvelope::{self, Channel, Client, Connection, Packet}; use crate::{events::IbcEvent, handler::HandlerOutput}; /// Result of message execution - comprises of events emitted and logs entries created during the @@ -44,7 +42,7 @@ where } /// Attempts to convert a message into a [MsgEnvelope] message -pub fn decode(message: Any) -> Result { +pub(crate) fn decode(message: Any) -> Result { message.try_into() } @@ -53,12 +51,15 @@ pub fn decode(message: Any) -> Result { /// and events produced after processing the input `msg`. /// If this method returns an error, the runtime is expected to rollback all state modifications to /// the `Ctx` caused by all messages from the transaction that this `msg` is a part of. -pub fn dispatch(ctx: &mut Ctx, msg: MsgEnvelope) -> Result, RouterError> +pub(crate) fn dispatch( + ctx: &mut Ctx, + msg: MsgEnvelope, +) -> Result, RouterError> where Ctx: RouterContext, { let output = match msg { - ClientMsg(msg) => { + Client(msg) => { let handler_output = ics2_msg_dispatcher(ctx, msg).map_err(|e| RouterError::ContextError(e.into()))?; @@ -72,7 +73,7 @@ where .with_result(()) } - ConnectionMsg(msg) => { + Connection(msg) => { let handler_output = ics3_msg_dispatcher(ctx, msg).map_err(|e| RouterError::ContextError(e.into()))?; @@ -86,7 +87,7 @@ where .with_result(()) } - ChannelMsg(msg) => { + Channel(msg) => { let module_id = channel_validate(ctx, &msg).map_err(|e| RouterError::ContextError(e.into()))?; let dispatch_output = HandlerOutputBuilder::<()>::new(); @@ -130,7 +131,7 @@ where .with_result(()) } - PacketMsg(msg) => { + Packet(msg) => { let module_id = get_module_for_packet_msg(ctx, &msg) .map_err(|e| RouterError::ContextError(e.into()))?; let (mut handler_builder, packet_result) = ics4_packet_msg_dispatcher(ctx, &msg) @@ -370,7 +371,7 @@ mod tests { // First, create a client.. let res = dispatch( &mut ctx, - MsgEnvelope::ClientMsg(ClientMsg::CreateClient(create_client_msg.clone())), + MsgEnvelope::Client(ClientMsg::CreateClient(create_client_msg.clone())), ); assert!( @@ -399,7 +400,7 @@ mod tests { // Test some ICS2 client functionality. Test { name: "Client update successful".to_string(), - msg: MsgEnvelope::ClientMsg(ClientMsg::UpdateClient(MsgUpdateClient { + msg: MsgEnvelope::Client(ClientMsg::UpdateClient(MsgUpdateClient { client_id: client_id.clone(), header: MockHeader::new(update_client_height) .with_timestamp(Timestamp::now()) @@ -412,7 +413,7 @@ mod tests { }, Test { name: "Client update fails due to stale header".to_string(), - msg: MsgEnvelope::ClientMsg(ClientMsg::UpdateClient(MsgUpdateClient { + msg: MsgEnvelope::Client(ClientMsg::UpdateClient(MsgUpdateClient { client_id: client_id.clone(), header: MockHeader::new(update_client_height).into(), signer: default_signer.clone(), @@ -423,7 +424,7 @@ mod tests { }, Test { name: "Connection open init succeeds".to_string(), - msg: MsgEnvelope::ConnectionMsg(ConnectionMsg::ConnectionOpenInit( + msg: MsgEnvelope::Connection(ConnectionMsg::OpenInit( msg_conn_init.with_client_id(client_id.clone()), )) .into(), @@ -433,16 +434,13 @@ mod tests { Test { name: "Connection open try fails due to InvalidConsensusHeight (too high)" .to_string(), - msg: MsgEnvelope::ConnectionMsg(ConnectionMsg::ConnectionOpenTry( - incorrect_msg_conn_try, - )) - .into(), + msg: MsgEnvelope::Connection(ConnectionMsg::OpenTry(incorrect_msg_conn_try)).into(), want_pass: false, state_check: None, }, Test { name: "Connection open try succeeds".to_string(), - msg: MsgEnvelope::ConnectionMsg(ConnectionMsg::ConnectionOpenTry( + msg: MsgEnvelope::Connection(ConnectionMsg::OpenTry( correct_msg_conn_try.with_client_id(client_id.clone()), )) .into(), @@ -451,34 +449,32 @@ mod tests { }, Test { name: "Connection open ack succeeds".to_string(), - msg: MsgEnvelope::ConnectionMsg(ConnectionMsg::ConnectionOpenAck(msg_conn_ack)) - .into(), + msg: MsgEnvelope::Connection(ConnectionMsg::OpenAck(msg_conn_ack)).into(), want_pass: true, state_check: None, }, // ICS04 Test { name: "Channel open init succeeds".to_string(), - msg: MsgEnvelope::ChannelMsg(ChannelMsg::ChannelOpenInit(msg_chan_init)).into(), + msg: MsgEnvelope::Channel(ChannelMsg::OpenInit(msg_chan_init)).into(), want_pass: true, state_check: None, }, Test { name: "Channel open init fail due to missing connection".to_string(), - msg: MsgEnvelope::ChannelMsg(ChannelMsg::ChannelOpenInit(incorrect_msg_chan_init)) - .into(), + msg: MsgEnvelope::Channel(ChannelMsg::OpenInit(incorrect_msg_chan_init)).into(), want_pass: false, state_check: None, }, Test { name: "Channel open try succeeds".to_string(), - msg: MsgEnvelope::ChannelMsg(ChannelMsg::ChannelOpenTry(msg_chan_try)).into(), + msg: MsgEnvelope::Channel(ChannelMsg::OpenTry(msg_chan_try)).into(), want_pass: true, state_check: None, }, Test { name: "Channel open ack succeeds".to_string(), - msg: MsgEnvelope::ChannelMsg(ChannelMsg::ChannelOpenAck(msg_chan_ack)).into(), + msg: MsgEnvelope::Channel(ChannelMsg::OpenAck(msg_chan_ack)).into(), want_pass: true, state_check: None, }, @@ -492,7 +488,7 @@ mod tests { // msg_recv_packet has the same height as the packet TO height (see get_dummy_raw_msg_recv_packet) Test { name: "Client update successful #2".to_string(), - msg: MsgEnvelope::ClientMsg(ClientMsg::UpdateClient(MsgUpdateClient { + msg: MsgEnvelope::Client(ClientMsg::UpdateClient(MsgUpdateClient { client_id: client_id.clone(), header: MockHeader::new(update_client_height_after_send) .with_timestamp(Timestamp::now()) @@ -505,20 +501,20 @@ mod tests { }, Test { name: "Receive packet".to_string(), - msg: MsgEnvelope::PacketMsg(PacketMsg::RecvPacket(msg_recv_packet.clone())).into(), + msg: MsgEnvelope::Packet(PacketMsg::Recv(msg_recv_packet.clone())).into(), want_pass: true, state_check: None, }, Test { name: "Re-Receive packet".to_string(), - msg: MsgEnvelope::PacketMsg(PacketMsg::RecvPacket(msg_recv_packet)).into(), + msg: MsgEnvelope::Packet(PacketMsg::Recv(msg_recv_packet)).into(), want_pass: true, state_check: None, }, // Ack packet Test { name: "Ack packet".to_string(), - msg: MsgEnvelope::PacketMsg(PacketMsg::AckPacket(msg_ack_packet.clone())).into(), + msg: MsgEnvelope::Packet(PacketMsg::Ack(msg_ack_packet.clone())).into(), want_pass: true, state_check: Some(Box::new(move |ctx| { ctx.get_packet_commitment( @@ -537,7 +533,7 @@ mod tests { }, Test { name: "Client update successful".to_string(), - msg: MsgEnvelope::ClientMsg(ClientMsg::UpdateClient(MsgUpdateClient { + msg: MsgEnvelope::Client(ClientMsg::UpdateClient(MsgUpdateClient { client_id: client_id.clone(), header: MockHeader::new(update_client_height_after_second_send).into(), signer: default_signer.clone(), @@ -562,31 +558,26 @@ mod tests { //ICS04-close channel Test { name: "Channel close init succeeds".to_string(), - msg: MsgEnvelope::ChannelMsg(ChannelMsg::ChannelCloseInit(msg_chan_close_init)) - .into(), + msg: MsgEnvelope::Channel(ChannelMsg::CloseInit(msg_chan_close_init)).into(), want_pass: true, state_check: None, }, Test { name: "Channel close confirm fails cause channel is already closed".to_string(), - msg: MsgEnvelope::ChannelMsg(ChannelMsg::ChannelCloseConfirm( - msg_chan_close_confirm, - )) - .into(), + msg: MsgEnvelope::Channel(ChannelMsg::CloseConfirm(msg_chan_close_confirm)).into(), want_pass: false, state_check: None, }, //ICS04-to_on_close Test { name: "Timeout on close".to_string(), - msg: MsgEnvelope::PacketMsg(PacketMsg::TimeoutOnClosePacket(msg_to_on_close)) - .into(), + msg: MsgEnvelope::Packet(PacketMsg::TimeoutOnClose(msg_to_on_close)).into(), want_pass: true, state_check: None, }, Test { name: "Client upgrade successful".to_string(), - msg: MsgEnvelope::ClientMsg(ClientMsg::UpgradeClient(MsgUpgradeClient::new( + msg: MsgEnvelope::Client(ClientMsg::UpgradeClient(MsgUpgradeClient::new( client_id.clone(), MockClientState::new(MockHeader::new(upgrade_client_height)).into(), MockConsensusState::new(MockHeader::new(upgrade_client_height)).into(), @@ -600,7 +591,7 @@ mod tests { }, Test { name: "Client upgrade un-successful".to_string(), - msg: MsgEnvelope::ClientMsg(ClientMsg::UpgradeClient(MsgUpgradeClient::new( + msg: MsgEnvelope::Client(ClientMsg::UpgradeClient(MsgUpgradeClient::new( client_id, MockClientState::new(MockHeader::new(upgrade_client_height_second)).into(), MockConsensusState::new(MockHeader::new(upgrade_client_height_second)).into(), @@ -696,7 +687,7 @@ mod tests { let res = dispatch( &mut ctx, - MsgEnvelope::ChannelMsg(ChannelMsg::ChannelOpenInit(msg_chan_open_init)), + MsgEnvelope::Channel(ChannelMsg::OpenInit(msg_chan_open_init)), ) .unwrap(); @@ -716,7 +707,7 @@ mod tests { let res = dispatch( &mut ctx, - MsgEnvelope::ChannelMsg(ChannelMsg::ChannelOpenTry(msg_chan_open_try)), + MsgEnvelope::Channel(ChannelMsg::OpenTry(msg_chan_open_try)), ) .unwrap(); @@ -746,7 +737,7 @@ mod tests { let res = dispatch( &mut ctx, - MsgEnvelope::ChannelMsg(ChannelMsg::ChannelOpenAck(msg_chan_open_ack)), + MsgEnvelope::Channel(ChannelMsg::OpenAck(msg_chan_open_ack)), ) .unwrap(); @@ -776,7 +767,7 @@ mod tests { let res = dispatch( &mut ctx, - MsgEnvelope::ChannelMsg(ChannelMsg::ChannelOpenConfirm(msg_chan_open_confirm)), + MsgEnvelope::Channel(ChannelMsg::OpenConfirm(msg_chan_open_confirm)), ) .unwrap(); @@ -806,7 +797,7 @@ mod tests { let res = dispatch( &mut ctx, - MsgEnvelope::ChannelMsg(ChannelMsg::ChannelCloseInit(msg_chan_close_init)), + MsgEnvelope::Channel(ChannelMsg::CloseInit(msg_chan_close_init)), ) .unwrap(); @@ -836,7 +827,7 @@ mod tests { let res = dispatch( &mut ctx, - MsgEnvelope::ChannelMsg(ChannelMsg::ChannelCloseConfirm(msg_chan_close_confirm)), + MsgEnvelope::Channel(ChannelMsg::CloseConfirm(msg_chan_close_confirm)), ) .unwrap(); diff --git a/crates/ibc/src/core/ics26_routing/msgs.rs b/crates/ibc/src/core/ics26_routing/msgs.rs index 99ecd5929..bad168e67 100644 --- a/crates/ibc/src/core/ics26_routing/msgs.rs +++ b/crates/ibc/src/core/ics26_routing/msgs.rs @@ -16,10 +16,10 @@ use ibc_proto::protobuf::Protobuf; /// Enumeration of all messages that the local ICS26 module is capable of routing. #[derive(Clone, Debug)] pub enum MsgEnvelope { - ClientMsg(ClientMsg), - ConnectionMsg(ConnectionMsg), - ChannelMsg(ChannelMsg), - PacketMsg(PacketMsg), + Client(ClientMsg), + Connection(ConnectionMsg), + Channel(ChannelMsg), + Packet(PacketMsg), } impl TryFrom for MsgEnvelope { @@ -32,117 +32,97 @@ impl TryFrom for MsgEnvelope { // Pop out the message and then wrap it in the corresponding type. let domain_msg = create_client::MsgCreateClient::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::ClientMsg(ClientMsg::CreateClient(domain_msg))) + Ok(MsgEnvelope::Client(ClientMsg::CreateClient(domain_msg))) } update_client::TYPE_URL => { let domain_msg = update_client::MsgUpdateClient::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::ClientMsg(ClientMsg::UpdateClient(domain_msg))) + Ok(MsgEnvelope::Client(ClientMsg::UpdateClient(domain_msg))) } upgrade_client::TYPE_URL => { let domain_msg = upgrade_client::MsgUpgradeClient::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::ClientMsg(ClientMsg::UpgradeClient(domain_msg))) + Ok(MsgEnvelope::Client(ClientMsg::UpgradeClient(domain_msg))) } // ICS03 conn_open_init::TYPE_URL => { let domain_msg = conn_open_init::MsgConnectionOpenInit::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::ConnectionMsg( - ConnectionMsg::ConnectionOpenInit(domain_msg), - )) + Ok(MsgEnvelope::Connection(ConnectionMsg::OpenInit(domain_msg))) } conn_open_try::TYPE_URL => { let domain_msg = conn_open_try::MsgConnectionOpenTry::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::ConnectionMsg( - ConnectionMsg::ConnectionOpenTry(domain_msg), - )) + Ok(MsgEnvelope::Connection(ConnectionMsg::OpenTry(domain_msg))) } conn_open_ack::TYPE_URL => { let domain_msg = conn_open_ack::MsgConnectionOpenAck::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::ConnectionMsg( - ConnectionMsg::ConnectionOpenAck(domain_msg), - )) + Ok(MsgEnvelope::Connection(ConnectionMsg::OpenAck(domain_msg))) } conn_open_confirm::TYPE_URL => { let domain_msg = conn_open_confirm::MsgConnectionOpenConfirm::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::ConnectionMsg( - ConnectionMsg::ConnectionOpenConfirm(domain_msg), - )) + Ok(MsgEnvelope::Connection(ConnectionMsg::OpenConfirm( + domain_msg, + ))) } // ICS04 channel messages chan_open_init::TYPE_URL => { let domain_msg = chan_open_init::MsgChannelOpenInit::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::ChannelMsg(ChannelMsg::ChannelOpenInit( - domain_msg, - ))) + Ok(MsgEnvelope::Channel(ChannelMsg::OpenInit(domain_msg))) } chan_open_try::TYPE_URL => { let domain_msg = chan_open_try::MsgChannelOpenTry::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::ChannelMsg(ChannelMsg::ChannelOpenTry( - domain_msg, - ))) + Ok(MsgEnvelope::Channel(ChannelMsg::OpenTry(domain_msg))) } chan_open_ack::TYPE_URL => { let domain_msg = chan_open_ack::MsgChannelOpenAck::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::ChannelMsg(ChannelMsg::ChannelOpenAck( - domain_msg, - ))) + Ok(MsgEnvelope::Channel(ChannelMsg::OpenAck(domain_msg))) } chan_open_confirm::TYPE_URL => { let domain_msg = chan_open_confirm::MsgChannelOpenConfirm::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::ChannelMsg(ChannelMsg::ChannelOpenConfirm( - domain_msg, - ))) + Ok(MsgEnvelope::Channel(ChannelMsg::OpenConfirm(domain_msg))) } chan_close_init::TYPE_URL => { let domain_msg = chan_close_init::MsgChannelCloseInit::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::ChannelMsg(ChannelMsg::ChannelCloseInit( - domain_msg, - ))) + Ok(MsgEnvelope::Channel(ChannelMsg::CloseInit(domain_msg))) } chan_close_confirm::TYPE_URL => { let domain_msg = chan_close_confirm::MsgChannelCloseConfirm::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::ChannelMsg(ChannelMsg::ChannelCloseConfirm( - domain_msg, - ))) + Ok(MsgEnvelope::Channel(ChannelMsg::CloseConfirm(domain_msg))) } // ICS04 packet messages recv_packet::TYPE_URL => { let domain_msg = recv_packet::MsgRecvPacket::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::PacketMsg(PacketMsg::RecvPacket(domain_msg))) + Ok(MsgEnvelope::Packet(PacketMsg::Recv(domain_msg))) } acknowledgement::TYPE_URL => { let domain_msg = acknowledgement::MsgAcknowledgement::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::PacketMsg(PacketMsg::AckPacket(domain_msg))) + Ok(MsgEnvelope::Packet(PacketMsg::Ack(domain_msg))) } timeout::TYPE_URL => { let domain_msg = timeout::MsgTimeout::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::PacketMsg(PacketMsg::TimeoutPacket(domain_msg))) + Ok(MsgEnvelope::Packet(PacketMsg::Timeout(domain_msg))) } timeout_on_close::TYPE_URL => { let domain_msg = timeout_on_close::MsgTimeoutOnClose::decode_vec(&any_msg.value) .map_err(RouterError::MalformedMessageBytes)?; - Ok(MsgEnvelope::PacketMsg(PacketMsg::TimeoutOnClosePacket( - domain_msg, - ))) + Ok(MsgEnvelope::Packet(PacketMsg::TimeoutOnClose(domain_msg))) } _ => Err(RouterError::UnknownMessageTypeUrl { url: any_msg.type_url, diff --git a/crates/ibc/src/mock/ics18_relayer/context.rs b/crates/ibc/src/mock/ics18_relayer/context.rs index 6d60c2bfe..57d153165 100644 --- a/crates/ibc/src/mock/ics18_relayer/context.rs +++ b/crates/ibc/src/mock/ics18_relayer/context.rs @@ -55,7 +55,7 @@ mod tests { /// Builds a `ClientMsg::UpdateClient` for a client with id `client_id` running on the `dest` /// context, assuming that the latest header on the source context is `src_header`. - pub fn build_client_update_datagram( + pub(crate) fn build_client_update_datagram( dest: &Ctx, client_id: &ClientId, src_header: &dyn Header, @@ -154,7 +154,7 @@ mod tests { // - send the message to B. We bypass ICS18 interface and call directly into // MockContext `recv` method (to avoid additional serialization steps). - let dispatch_res_b = ctx_b.deliver(MsgEnvelope::ClientMsg(client_msg_b)); + let dispatch_res_b = ctx_b.deliver(MsgEnvelope::Client(client_msg_b)); let validation_res = ctx_b.validate(); assert!( validation_res.is_ok(), @@ -198,7 +198,7 @@ mod tests { debug!("client_msg_a = {:?}", client_msg_a); // - send the message to A - let dispatch_res_a = ctx_a.deliver(MsgEnvelope::ClientMsg(client_msg_a)); + let dispatch_res_a = ctx_a.deliver(MsgEnvelope::Client(client_msg_a)); let validation_res = ctx_a.validate(); assert!( validation_res.is_ok(),