Skip to content

Commit

Permalink
Remove into_any trait methods
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchen1991 committed Apr 25, 2024
1 parent 2525d5f commit c1c8165
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 17 deletions.
4 changes: 0 additions & 4 deletions ibc-clients/ics07-tendermint/src/consensus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,4 @@ impl ConsensusStateTrait for ConsensusState {
fn timestamp(&self) -> Timestamp {
self.0.timestamp.into()
}

fn into_any(self) -> Any {
self.into()
}
}
14 changes: 8 additions & 6 deletions ibc-core/ics02-client/context/src/consensus_state.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
//! Defines the trait to be implemented by all concrete consensus state types
use ibc_core_client_types::error::ClientError;
use ibc_core_commitment_types::commitment::CommitmentRoot;
use ibc_primitives::prelude::*;
use ibc_primitives::proto::Any;
use ibc_primitives::Timestamp;

/// Convenient trait to decode a consensus state from an `Any` type and obtain
/// a handle to the local instance of `ConsensusState`.
pub trait ConsensusStateDecoder: Into<Any> + TryFrom<Any, Error = ClientError> {}

impl<T> ConsensusStateDecoder for T where T: Into<Any> + TryFrom<Any, Error = ClientError> {}

/// Defines methods that all `ConsensusState`s should provide.
///
/// One can think of a "consensus state" as a pruned header, to be stored on chain. In other words,
/// a consensus state only contains the header's information needed by IBC message handlers.
pub trait ConsensusState: Send + Sync {
pub trait ConsensusState: Send + Sync + ConsensusStateDecoder {
/// Commitment root of the consensus state, which is used for key-value pair verification.
fn root(&self) -> &CommitmentRoot;

/// The timestamp of the consensus state
fn timestamp(&self) -> Timestamp;

/// Serializes the `ConsensusState`. This is expected to be implemented as
/// first converting to the raw type (i.e. the protobuf definition), and then
/// serializing that.
fn into_any(self) -> Any;
}
2 changes: 1 addition & 1 deletion ibc-core/ics02-client/src/handler/recover_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ where
ctx.get_client_execution_context(),
&subject_client_id,
substitute_client_state.into(),
substitute_consensus_state.into_any(),
substitute_consensus_state.into(),
)?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion ibc-core/ics03-connection/src/handler/conn_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ where
&msg.proof_consensus_state_of_a_on_b,
consensus_state_of_b_on_a.root(),
Path::ClientConsensusState(client_cons_state_path_on_b),
expected_consensus_state_of_a_on_b.into_any().to_vec(),
expected_consensus_state_of_a_on_b.into().to_vec(),
)
.map_err(|e| ConnectionError::ConsensusStateVerificationFailure {
height: msg.proofs_height_on_b,
Expand Down
2 changes: 1 addition & 1 deletion ibc-core/ics03-connection/src/handler/conn_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ where
&msg.proof_consensus_state_of_b_on_a,
consensus_state_of_a_on_b.root(),
Path::ClientConsensusState(client_cons_state_path_on_a),
expected_consensus_state_of_b_on_a.into_any().to_vec(),
expected_consensus_state_of_b_on_a.into().to_vec(),
)
.map_err(|e| ConnectionError::ConsensusStateVerificationFailure {
height: msg.proofs_height_on_a,
Expand Down
4 changes: 0 additions & 4 deletions ibc-testkit/src/testapp/ibc/clients/mock/consensus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,4 @@ impl ConsensusState for MockConsensusState {
fn timestamp(&self) -> Timestamp {
self.header.timestamp
}

fn into_any(self) -> Any {
self.into()
}
}

0 comments on commit c1c8165

Please sign in to comment.