From afadeffca336c3c111243ee4701801c2b41f710e Mon Sep 17 00:00:00 2001 From: CharlyCst Date: Thu, 29 Oct 2020 11:18:04 +0100 Subject: [PATCH 1/2] ConnectionReader.connection_end returns owned val --- modules/src/ics03_connection/context.rs | 2 +- modules/src/mock_context.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/src/ics03_connection/context.rs b/modules/src/ics03_connection/context.rs index 9afefd0e9f..fc2c28d165 100644 --- a/modules/src/ics03_connection/context.rs +++ b/modules/src/ics03_connection/context.rs @@ -13,7 +13,7 @@ use crate::Height; /// A context supplying all the necessary read-only dependencies for processing any `ConnectionMsg`. pub trait ConnectionReader { /// Returns the ConnectionEnd for the given identifier `conn_id`. - fn connection_end(&self, conn_id: &ConnectionId) -> Option<&ConnectionEnd>; + fn connection_end(&self, conn_id: &ConnectionId) -> Option; /// Returns the ClientState for the given identifier `client_id`. fn client_state(&self, client_id: &ClientId) -> Option; diff --git a/modules/src/mock_context.rs b/modules/src/mock_context.rs index 551e407eca..137c00b7f3 100644 --- a/modules/src/mock_context.rs +++ b/modules/src/mock_context.rs @@ -202,8 +202,8 @@ impl MockContext { impl ICS26Context for MockContext {} impl ConnectionReader for MockContext { - fn connection_end(&self, cid: &ConnectionId) -> Option<&ConnectionEnd> { - self.connections.get(cid) + fn connection_end(&self, cid: &ConnectionId) -> Option { + self.connections.get(cid).cloned() } fn client_state(&self, client_id: &ClientId) -> Option { From 02f1e6be42a0d083b8c3299ed56ebc6d2e6ef750 Mon Sep 17 00:00:00 2001 From: Adi Seredinschi Date: Fri, 30 Oct 2020 15:38:32 +0100 Subject: [PATCH 2/2] Removed redundant clones, updated changelog; ready to fix #347. --- CHANGELOG.md | 4 ++++ modules/src/ics03_connection/handler/conn_open_ack.rs | 2 +- modules/src/ics03_connection/handler/conn_open_confirm.rs | 2 +- modules/src/ics03_connection/handler/conn_open_try.rs | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3c1db8059..72cfb2e1ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased Changes +Special thanks to external contributors for this release: @CharlyCst ([#347]). + ### FEATURES - [changelog] Added "unreleased" section in `CHANGELOG.MD` to help streamline releases ([#274]) @@ -17,8 +19,10 @@ ### IMPROVEMENTS - [relayer-cli] Split tasks spawned by CLI commands into their own modules ([#331]) +- [modules] Homogenize ConnectionReader trait so that all functions return owned objects ([#347]) [#331]: https://github.com/informalsystems/ibc-rs/pulls/331 +[#347]: https://github.com/informalsystems/ibc-rs/issues/347 ## v0.0.4 *October 19, 2020* diff --git a/modules/src/ics03_connection/handler/conn_open_ack.rs b/modules/src/ics03_connection/handler/conn_open_ack.rs index 78b4af56ec..a1be2f1122 100644 --- a/modules/src/ics03_connection/handler/conn_open_ack.rs +++ b/modules/src/ics03_connection/handler/conn_open_ack.rs @@ -35,7 +35,7 @@ pub(crate) fn process( || old_conn_end.counterparty().connection_id() == msg.counterparty_connection_id(); if state_is_consistent && counterparty_matches { - Ok(old_conn_end.clone()) + Ok(old_conn_end) } else { // Old connection end is in incorrect state, propagate the error. Err(Into::::into(Kind::ConnectionMismatch( diff --git a/modules/src/ics03_connection/handler/conn_open_confirm.rs b/modules/src/ics03_connection/handler/conn_open_confirm.rs index 220646d210..8268ae6c34 100644 --- a/modules/src/ics03_connection/handler/conn_open_confirm.rs +++ b/modules/src/ics03_connection/handler/conn_open_confirm.rs @@ -25,7 +25,7 @@ pub(crate) fn process( msg.connection_id().clone(), ))) } else { - Ok(old_conn_end.clone()) + Ok(old_conn_end) } } None => { diff --git a/modules/src/ics03_connection/handler/conn_open_try.rs b/modules/src/ics03_connection/handler/conn_open_try.rs index ec4f4cc481..9621ba3a51 100644 --- a/modules/src/ics03_connection/handler/conn_open_try.rs +++ b/modules/src/ics03_connection/handler/conn_open_try.rs @@ -37,7 +37,7 @@ pub(crate) fn process( && old_conn_end.client_id_matches(msg.client_id()) { // A ConnectionEnd already exists and all validation passed. - Ok(old_conn_end.clone()) + Ok(old_conn_end) } else { // A ConnectionEnd already exists and validation failed. Err(Into::::into(