Skip to content

Commit

Permalink
Merge v0.21.x in main (#196)
Browse files Browse the repository at this point in the history
* Make `ClientType` allow any string value (#189)

* ClientType now wraps a str

* Make ClientType accept any string

* doctest

* changelog

* use client_type() fn instead of constant

* use client_type() for mock

* release v0.21.0 (#192)

* release v0.21.0

* version bumped to 0.21.0

* contributing edit

* Update .changelog/v0.21.0/summary.md

Co-authored-by: Romain Ruetschi <romain@informal.systems>
Signed-off-by: Philippe Laferrière <plafer@protonmail.com>

* Update CHANGELOG.md

Co-authored-by: Romain Ruetschi <romain@informal.systems>
Signed-off-by: Philippe Laferrière <plafer@protonmail.com>

Signed-off-by: Philippe Laferrière <plafer@protonmail.com>
Co-authored-by: Romain Ruetschi <romain@informal.systems>

Signed-off-by: Philippe Laferrière <plafer@protonmail.com>
Co-authored-by: Romain Ruetschi <romain@informal.systems>
  • Loading branch information
plafer and romac authored Oct 26, 2022
1 parent c202910 commit 4b18233
Show file tree
Hide file tree
Showing 25 changed files with 161 additions and 214 deletions.
2 changes: 2 additions & 0 deletions .changelog/v0.21.0/breaking-changes/188-clienttype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Make ClientType allow any string value as opposed to just Tendermint
([#188](https://github.com/cosmos/ibc-rs/issues/188))
1 change: 1 addition & 0 deletions .changelog/v0.21.0/summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a small release that allows new `ClientTypes` to be created, which was missed when implementing ADR 4. The changes are not consensus-breaking.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# CHANGELOG

## v0.21.0

*October 24, 2022*

This is a small release that allows new `ClientTypes` to be created, which was missed when implementing ADR 4. The changes are not consensus-breaking.

### BREAKING CHANGES

- Make ClientType allow any string value as opposed to just Tendermint
([#188](https://github.com/cosmos/ibc-rs/issues/188))

## v0.20.0

*October 19, 2022*
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ consent) who is more appropriate to shepherd the PR through to completion.

Our release process is as follows:

1. Update the [changelog](#changelog) to reflect and summarize all changes in
1. In a new branch `release/vX.Y.Z`, update the [changelog](#changelog) to reflect and summarize all changes in
the release. This involves:
1. Running `unclog build -u` and copy pasting the output at the top
of the `CHANGELOG.md` file, making sure to update the header with
Expand All @@ -234,11 +234,11 @@ Our release process is as follows:
2. All crates' `lib.rs` files documentation references' `html_root_url`
parameters must point to the new version.

4. Run `cargo doc --all-features --open` locally to double-check that all the
4. In the `crates/ibc/` directory, run `cargo doc --all-features --open` locally to double-check that all the
documentation compiles and seems up-to-date and coherent. Fix any potential
issues here and push them to the release PR.
5. Run `cargo publish --dry-run` to double-check that publishing will work. Fix
any potential issues here and push them to the release PR.
5. In the `crates/ibc/` directory, run `cargo publish --dry-run` to double-check that publishing will work. Fix
any potential issues here and push them to the release PR.
6. Mark the PR as **Ready for Review** and incorporate feedback on the release.
7. Once approved, merge the PR, and pull the `main` branch.
8. From the `crates/ibc` folder, run `cargo publish`
Expand Down
2 changes: 1 addition & 1 deletion crates/ibc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ibc"
version = "0.20.0"
version = "0.21.0"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
Expand Down
8 changes: 5 additions & 3 deletions crates/ibc/src/clients/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ use crate::core::ics24_host::identifier::{ChainId, ChannelId, ClientId, Connecti
use crate::timestamp::{Timestamp, ZERO_DURATION};
use crate::Height;

use super::client_type as tm_client_type;

pub const TENDERMINT_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ClientState";

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -262,7 +264,7 @@ impl Ics2ClientState for ClientState {
}

fn client_type(&self) -> ClientType {
ClientType::Tendermint
tm_client_type()
}

fn latest_height(&self) -> Height {
Expand Down Expand Up @@ -766,13 +768,13 @@ fn verify_delay_passed(
fn downcast_tm_client_state(cs: &dyn Ics2ClientState) -> Result<&ClientState, Ics02Error> {
cs.as_any()
.downcast_ref::<ClientState>()
.ok_or_else(|| Ics02Error::client_args_type_mismatch(ClientType::Tendermint))
.ok_or_else(|| Ics02Error::client_args_type_mismatch(tm_client_type()))
}

fn downcast_tm_consensus_state(cs: &dyn ConsensusState) -> Result<TmConsensusState, Ics02Error> {
cs.as_any()
.downcast_ref::<TmConsensusState>()
.ok_or_else(|| Ics02Error::client_args_type_mismatch(ClientType::Tendermint))
.ok_or_else(|| Ics02Error::client_args_type_mismatch(tm_client_type()))
.map(Clone::clone)
}

Expand Down
4 changes: 3 additions & 1 deletion crates/ibc/src/clients/ics07_tendermint/consensus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use crate::core::ics02_client::error::Error as Ics02Error;
use crate::core::ics23_commitment::commitment::CommitmentRoot;
use crate::timestamp::Timestamp;

use super::client_type as tm_client_type;

pub const TENDERMINT_CONSENSUS_STATE_TYPE_URL: &str =
"/ibc.lightclients.tendermint.v1.ConsensusState";

Expand All @@ -36,7 +38,7 @@ impl ConsensusState {

impl crate::core::ics02_client::consensus_state::ConsensusState for ConsensusState {
fn client_type(&self) -> ClientType {
ClientType::Tendermint
tm_client_type()
}

fn root(&self) -> &CommitmentRoot {
Expand Down
4 changes: 3 additions & 1 deletion crates/ibc/src/clients/ics07_tendermint/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use crate::timestamp::Timestamp;
use crate::utils::pretty::{PrettySignedHeader, PrettyValidatorSet};
use crate::Height;

use super::client_type as tm_client_type;

pub const TENDERMINT_HEADER_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.Header";

/// Tendermint consensus header
Expand Down Expand Up @@ -79,7 +81,7 @@ pub fn headers_compatible(header: &SignedHeader, other: &SignedHeader) -> bool {

impl crate::core::ics02_client::header::Header for Header {
fn client_type(&self) -> ClientType {
ClientType::Tendermint
tm_client_type()
}

fn height(&self) -> Height {
Expand Down
8 changes: 8 additions & 0 deletions crates/ibc/src/clients/ics07_tendermint/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
//! ICS 07: Tendermint Client implements a client verification algorithm for blockchains which use
//! the Tendermint consensus algorithm.
use crate::core::ics02_client::client_type::ClientType;

pub mod client_state;
pub mod consensus_state;
pub mod error;
pub mod header;
pub mod misbehaviour;

pub(crate) const TENDERMINT_CLIENT_TYPE: &str = "07-tendermint";

pub fn client_type() -> ClientType {
ClientType::new(TENDERMINT_CLIENT_TYPE)
}
99 changes: 5 additions & 94 deletions crates/ibc/src/core/ics02_client/client_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,17 @@ use crate::prelude::*;
use core::fmt::{Display, Error as FmtError, Formatter};
use serde_derive::{Deserialize, Serialize};

use super::error::Error;

/// Type of the client, depending on the specific consensus algorithm.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum ClientType {
Tendermint = 1,

#[cfg(any(test, feature = "mocks"))]
Mock = 9999,
}
pub struct ClientType(&'static str);

impl ClientType {
const TENDERMINT_STR: &'static str = "07-tendermint";

#[cfg_attr(not(test), allow(dead_code))]
const MOCK_STR: &'static str = "9999-mock";

pub fn new(s: &'static str) -> Self {
Self(s)
}
/// Yields the identifier of this client type as a string
pub fn as_str(&self) -> &'static str {
match self {
Self::Tendermint => Self::TENDERMINT_STR,

#[cfg(any(test, feature = "mocks"))]
Self::Mock => Self::MOCK_STR,
}
self.0
}
}

Expand All @@ -35,78 +21,3 @@ impl Display for ClientType {
write!(f, "ClientType({})", self.as_str())
}
}

impl core::str::FromStr for ClientType {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
Self::TENDERMINT_STR => Ok(Self::Tendermint),

#[cfg(any(test, feature = "mocks"))]
Self::MOCK_STR => Ok(Self::Mock),

_ => Err(Error::unknown_client_type(s.to_string())),
}
}
}

#[cfg(test)]
mod tests {
use core::str::FromStr;
use test_log::test;

use super::ClientType;
use crate::core::ics02_client::error::{Error, ErrorDetail};

#[test]
fn parse_tendermint_client_type() {
let client_type = ClientType::from_str("07-tendermint");

match client_type {
Ok(ClientType::Tendermint) => (),
_ => panic!("parse failed"),
}
}

#[test]
fn parse_mock_client_type() {
let client_type = ClientType::from_str("9999-mock");

match client_type {
Ok(ClientType::Mock) => (),
_ => panic!("parse failed"),
}
}

#[test]
fn parse_unknown_client_type() {
let client_type_str = "some-random-client-type";
let result = ClientType::from_str(client_type_str);

match result {
Err(Error(ErrorDetail::UnknownClientType(e), _)) => {
assert_eq!(&e.client_type, client_type_str)
}
_ => {
panic!("Expected ClientType::from_str to fail with UnknownClientType, instead got",)
}
}
}

#[test]
fn parse_mock_as_string_result() {
let client_type = ClientType::Mock;
let type_string = client_type.as_str();
let client_type_from_str = ClientType::from_str(type_string).unwrap();
assert_eq!(client_type_from_str, client_type);
}

#[test]
fn parse_tendermint_as_string_result() {
let client_type = ClientType::Tendermint;
let type_string = client_type.as_str();
let client_type_from_str = ClientType::from_str(type_string).unwrap();
assert_eq!(client_type_from_str, client_type);
}
}
14 changes: 7 additions & 7 deletions crates/ibc/src/core/ics02_client/handler/create_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub fn process(ctx: &dyn ClientReader, msg: MsgCreateClient) -> HandlerResult<Cl

#[cfg(test)]
mod tests {
use crate::clients::ics07_tendermint::client_type as tm_client_type;
use crate::prelude::*;

use core::time::Duration;
Expand All @@ -87,15 +88,14 @@ mod tests {
};
use crate::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState;
use crate::clients::ics07_tendermint::header::test_util::get_dummy_tendermint_header;
use crate::core::ics02_client::client_type::ClientType;
use crate::core::ics02_client::handler::{dispatch, ClientResult};
use crate::core::ics02_client::msgs::create_client::MsgCreateClient;
use crate::core::ics02_client::msgs::ClientMsg;
use crate::core::ics02_client::trust_threshold::TrustThreshold;
use crate::core::ics23_commitment::specs::ProofSpecs;
use crate::core::ics24_host::identifier::ClientId;
use crate::handler::HandlerOutput;
use crate::mock::client_state::MockClientState;
use crate::mock::client_state::{client_type as mock_client_type, MockClientState};
use crate::mock::consensus_state::MockConsensusState;
use crate::mock::context::MockContext;
use crate::mock::header::MockHeader;
Expand All @@ -119,10 +119,10 @@ mod tests {

match output {
Ok(HandlerOutput { result, .. }) => {
let expected_client_id = ClientId::new(ClientType::Mock, 0).unwrap();
let expected_client_id = ClientId::new(mock_client_type(), 0).unwrap();
match result {
ClientResult::Create(create_result) => {
assert_eq!(create_result.client_type, ClientType::Mock);
assert_eq!(create_result.client_type, mock_client_type());
assert_eq!(create_result.client_id, expected_client_id);
assert_eq!(
create_result.client_state.as_ref().clone_into(),
Expand Down Expand Up @@ -180,7 +180,7 @@ mod tests {
// The expected client id that will be generated will be identical to "9999-mock-0" for all
// tests. This is because we're not persisting any client results (which is done via the
// tests for `ics26_routing::dispatch`.
let expected_client_id = ClientId::new(ClientType::Mock, 0).unwrap();
let expected_client_id = ClientId::new(mock_client_type(), 0).unwrap();

for msg in create_client_msgs {
let output = dispatch(&ctx, ClientMsg::CreateClient(msg.clone()));
Expand Down Expand Up @@ -250,10 +250,10 @@ mod tests {

match output {
Ok(HandlerOutput { result, .. }) => {
let expected_client_id = ClientId::new(ClientType::Tendermint, 0).unwrap();
let expected_client_id = ClientId::new(tm_client_type(), 0).unwrap();
match result {
ClientResult::Create(create_res) => {
assert_eq!(create_res.client_type, ClientType::Tendermint);
assert_eq!(create_res.client_type, tm_client_type());
assert_eq!(create_res.client_id, expected_client_id);
assert_eq!(
create_res.client_state.as_ref().clone_into(),
Expand Down
Loading

0 comments on commit 4b18233

Please sign in to comment.