From fd8473751f04b2df9847a5f76d171174393ead74 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 17 Feb 2022 11:59:58 -0600 Subject: [PATCH] Nonallocating `ConnectionEnd::versions` method (#1889) * Make `ConnectionEnd::versions` non-allocating. * Elide lifetimes * Add changelog entry. --- .../ibc-relayer/1880-nonallocating-verions-method.md | 1 + modules/src/core/ics03_connection/connection.rs | 4 ++-- .../src/core/ics03_connection/handler/conn_open_confirm.rs | 2 +- modules/src/core/ics04_channel/handler/chan_open_init.rs | 2 +- modules/src/core/ics04_channel/handler/chan_open_try.rs | 2 +- relayer/src/connection.rs | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 .changelog/unreleased/improvements/ibc-relayer/1880-nonallocating-verions-method.md diff --git a/.changelog/unreleased/improvements/ibc-relayer/1880-nonallocating-verions-method.md b/.changelog/unreleased/improvements/ibc-relayer/1880-nonallocating-verions-method.md new file mode 100644 index 0000000000..ecba32327b --- /dev/null +++ b/.changelog/unreleased/improvements/ibc-relayer/1880-nonallocating-verions-method.md @@ -0,0 +1 @@ +- Changed `ConnectionEnd::versions` method to be non-allocating by having it return a `&[Version]` instead of `Vec`. ([#1880](https://github.com/informalsystems/ibc-rs/pull/1880)) diff --git a/modules/src/core/ics03_connection/connection.rs b/modules/src/core/ics03_connection/connection.rs index 1702ce1fec..793501f35b 100644 --- a/modules/src/core/ics03_connection/connection.rs +++ b/modules/src/core/ics03_connection/connection.rs @@ -217,8 +217,8 @@ impl ConnectionEnd { } /// Getter for the list of versions in this connection end. - pub fn versions(&self) -> Vec { - self.versions.clone() + pub fn versions(&self) -> &[Version] { + &self.versions } /// Getter for the counterparty. diff --git a/modules/src/core/ics03_connection/handler/conn_open_confirm.rs b/modules/src/core/ics03_connection/handler/conn_open_confirm.rs index a284921735..731b4eb284 100644 --- a/modules/src/core/ics03_connection/handler/conn_open_confirm.rs +++ b/modules/src/core/ics03_connection/handler/conn_open_confirm.rs @@ -35,7 +35,7 @@ pub(crate) fn process( Some(msg.connection_id.clone()), // Local connection id. ctx.commitment_prefix(), // Local commitment prefix. ), - conn_end.versions(), + conn_end.versions().to_vec(), conn_end.delay_period(), ); diff --git a/modules/src/core/ics04_channel/handler/chan_open_init.rs b/modules/src/core/ics04_channel/handler/chan_open_init.rs index d37edc6d74..a30e216662 100644 --- a/modules/src/core/ics04_channel/handler/chan_open_init.rs +++ b/modules/src/core/ics04_channel/handler/chan_open_init.rs @@ -30,7 +30,7 @@ pub(crate) fn process( // An IBC connection running on the local (host) chain should exist. let conn = ctx.connection_end(&msg.channel.connection_hops()[0])?; let get_versions = conn.versions(); - let version = match get_versions.as_slice() { + let version = match get_versions { [version] => version, _ => return Err(Error::invalid_version_length_connection()), }; diff --git a/modules/src/core/ics04_channel/handler/chan_open_try.rs b/modules/src/core/ics04_channel/handler/chan_open_try.rs index c8b59f3feb..78344cc128 100644 --- a/modules/src/core/ics04_channel/handler/chan_open_try.rs +++ b/modules/src/core/ics04_channel/handler/chan_open_try.rs @@ -77,7 +77,7 @@ pub(crate) fn process( } let get_versions = conn.versions(); - let version = match get_versions.as_slice() { + let version = match get_versions { [version] => version, _ => return Err(Error::invalid_version_length_connection()), }; diff --git a/relayer/src/connection.rs b/relayer/src/connection.rs index 2075291731..6441659301 100644 --- a/relayer/src/connection.rs +++ b/relayer/src/connection.rs @@ -891,7 +891,7 @@ impl Connection { .query_compatible_versions() .map_err(|e| ConnectionError::chain_query(self.src_chain().id(), e))? } else { - src_connection.versions() + src_connection.versions().to_vec() }; // Get signer