Skip to content

Commit

Permalink
Nonallocating ConnectionEnd::versions method (#1889)
Browse files Browse the repository at this point in the history
* Make `ConnectionEnd::versions` non-allocating.

* Elide lifetimes

* Add changelog entry.
  • Loading branch information
seanchen1991 authored Feb 17, 2022
1 parent f1a4481 commit fd84737
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Changed `ConnectionEnd::versions` method to be non-allocating by having it return a `&[Version]` instead of `Vec<Version>`. ([#1880](https://github.com/informalsystems/ibc-rs/pull/1880))
4 changes: 2 additions & 2 deletions modules/src/core/ics03_connection/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ impl ConnectionEnd {
}

/// Getter for the list of versions in this connection end.
pub fn versions(&self) -> Vec<Version> {
self.versions.clone()
pub fn versions(&self) -> &[Version] {
&self.versions
}

/// Getter for the counterparty.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);

Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics04_channel/handler/chan_open_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
};
Expand Down
2 changes: 1 addition & 1 deletion modules/src/core/ics04_channel/handler/chan_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
};
Expand Down
2 changes: 1 addition & 1 deletion relayer/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ impl<ChainA: ChainHandle, ChainB: ChainHandle> Connection<ChainA, ChainB> {
.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
Expand Down

0 comments on commit fd84737

Please sign in to comment.