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

Remove ConnectionMsg variant connection{Try, Ack} Box Wrap #285

Merged
merged 4 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- ConnectionMsg::ConnectionOpen{Try, Ack} should not wrap a Box
([#258](https://github.com/cosmos/ibc-rs/issues/258))
12 changes: 4 additions & 8 deletions crates/ibc/src/core/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,8 @@ pub trait ValidationContext {
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::ConnectionOpenTry(message) => conn_open_try::validate(self, message),
ConnectionMsg::ConnectionOpenAck(message) => conn_open_ack::validate(self, message),
ConnectionMsg::ConnectionOpenConfirm(ref message) => {
conn_open_confirm::validate(self, message)
}
Expand Down Expand Up @@ -325,8 +321,8 @@ pub trait ExecutionContext: ValidationContext {
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::ConnectionOpenTry(message) => conn_open_try::execute(self, message),
ConnectionMsg::ConnectionOpenAck(message) => conn_open_ack::execute(self, message),
ConnectionMsg::ConnectionOpenConfirm(ref message) => {
conn_open_confirm::execute(self, message)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/core/ics03_connection/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ where
{
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::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),
}
}
6 changes: 3 additions & 3 deletions crates/ibc/src/core/ics03_connection/handler/conn_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,15 @@ mod tests {
.clone()
.with_client(&client_id, proof_height)
.with_connection(conn_id.clone(), default_conn_end),
msg: ConnectionMsg::ConnectionOpenAck(Box::new(msg_ack.clone())),
msg: ConnectionMsg::ConnectionOpenAck(msg_ack.clone()),
want_pass: true,
match_error: Box::new(|_| panic!("should not have error")),
},
Test {
name: "Processing fails because the connection does not exist in the context"
.to_string(),
ctx: default_context.clone(),
msg: ConnectionMsg::ConnectionOpenAck(Box::new(msg_ack.clone())),
msg: ConnectionMsg::ConnectionOpenAck(msg_ack.clone()),
want_pass: false,
match_error: {
let right_connection_id = conn_id.clone();
Expand All @@ -430,7 +430,7 @@ mod tests {
ctx: default_context
.with_client(&client_id, proof_height)
.with_connection(conn_id.clone(), conn_end_open),
msg: ConnectionMsg::ConnectionOpenAck(Box::new(msg_ack)),
msg: ConnectionMsg::ConnectionOpenAck(msg_ack),
want_pass: false,
match_error: {
let right_connection_id = conn_id;
Expand Down
12 changes: 6 additions & 6 deletions crates/ibc/src/core/ics03_connection/handler/conn_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,37 +387,37 @@ mod tests {
Test {
name: "Processing fails because the height is too advanced".to_string(),
ctx: context.clone(),
msg: ConnectionMsg::ConnectionOpenTry(Box::new(msg_height_advanced)),
msg: ConnectionMsg::ConnectionOpenTry(msg_height_advanced),
want_pass: false,
},
Test {
name: "Processing fails because the height is too old".to_string(),
ctx: context.clone(),
msg: ConnectionMsg::ConnectionOpenTry(Box::new(msg_height_old)),
msg: ConnectionMsg::ConnectionOpenTry(msg_height_old),
want_pass: false,
},
Test {
name: "Processing fails because no client exists".to_string(),
ctx: context.clone(),
msg: ConnectionMsg::ConnectionOpenTry(Box::new(msg_conn_try.clone())),
msg: ConnectionMsg::ConnectionOpenTry(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(Box::new(msg_proof_height_missing)),
msg: ConnectionMsg::ConnectionOpenTry(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(Box::new(msg_conn_try.clone())),
msg: ConnectionMsg::ConnectionOpenTry(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(Box::new(msg_conn_try)),
msg: ConnectionMsg::ConnectionOpenTry(msg_conn_try),
want_pass: true,
},
]
Expand Down
5 changes: 2 additions & 3 deletions crates/ibc/src/core/ics03_connection/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::core::ics03_connection::msgs::conn_open_ack::MsgConnectionOpenAck;
use crate::core::ics03_connection::msgs::conn_open_confirm::MsgConnectionOpenConfirm;
use crate::core::ics03_connection::msgs::conn_open_init::MsgConnectionOpenInit;
use crate::core::ics03_connection::msgs::conn_open_try::MsgConnectionOpenTry;
use alloc::boxed::Box;

pub mod conn_open_ack;
pub mod conn_open_confirm;
Expand All @@ -27,8 +26,8 @@ pub mod conn_open_try;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ConnectionMsg {
ConnectionOpenInit(MsgConnectionOpenInit),
ConnectionOpenTry(Box<MsgConnectionOpenTry>),
ConnectionOpenAck(Box<MsgConnectionOpenAck>),
ConnectionOpenTry(MsgConnectionOpenTry),
ConnectionOpenAck(MsgConnectionOpenAck),
ConnectionOpenConfirm(MsgConnectionOpenConfirm),
}

Expand Down
14 changes: 6 additions & 8 deletions crates/ibc/src/core/ics26_routing/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,28 +436,26 @@ mod tests {
Test {
name: "Connection open try fails due to InvalidConsensusHeight (too high)"
.to_string(),
msg: MsgEnvelope::ConnectionMsg(ConnectionMsg::ConnectionOpenTry(Box::new(
msg: MsgEnvelope::ConnectionMsg(ConnectionMsg::ConnectionOpenTry(
incorrect_msg_conn_try,
)))
))
.into(),
want_pass: false,
state_check: None,
},
Test {
name: "Connection open try succeeds".to_string(),
msg: MsgEnvelope::ConnectionMsg(ConnectionMsg::ConnectionOpenTry(Box::new(
msg: MsgEnvelope::ConnectionMsg(ConnectionMsg::ConnectionOpenTry(
correct_msg_conn_try.with_client_id(client_id.clone()),
)))
))
.into(),
want_pass: true,
state_check: None,
},
Test {
name: "Connection open ack succeeds".to_string(),
msg: MsgEnvelope::ConnectionMsg(ConnectionMsg::ConnectionOpenAck(Box::new(
msg_conn_ack,
)))
.into(),
msg: MsgEnvelope::ConnectionMsg(ConnectionMsg::ConnectionOpenAck(msg_conn_ack))
.into(),
want_pass: true,
state_check: None,
},
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/core/ics26_routing/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ impl TryFrom<Any> for MsgEnvelope {
let domain_msg = conn_open_try::MsgConnectionOpenTry::decode_vec(&any_msg.value)
.map_err(RouterError::MalformedMessageBytes)?;
Ok(MsgEnvelope::ConnectionMsg(
ConnectionMsg::ConnectionOpenTry(Box::new(domain_msg)),
ConnectionMsg::ConnectionOpenTry(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(Box::new(domain_msg)),
ConnectionMsg::ConnectionOpenAck(domain_msg),
))
}
conn_open_confirm::TYPE_URL => {
Expand Down