diff --git a/crates/core/component/ibc/src/component.rs b/crates/core/component/ibc/src/component.rs index 4cd8ecd42c..10490adf97 100644 --- a/crates/core/component/ibc/src/component.rs +++ b/crates/core/component/ibc/src/component.rs @@ -4,6 +4,7 @@ mod client; mod client_counter; mod connection; mod connection_counter; +mod ics02_validation; #[cfg(feature = "rpc")] pub mod rpc; diff --git a/crates/core/component/ibc/src/component/client_counter.rs b/crates/core/component/ibc/src/component/client_counter.rs index 01cc64f5d7..5b0a7b08b3 100644 --- a/crates/core/component/ibc/src/component/client_counter.rs +++ b/crates/core/component/ibc/src/component/client_counter.rs @@ -1,4 +1,4 @@ -use crate::IBC_PROOF_SPECS; +use crate::{component::ics02_validation, IBC_PROOF_SPECS}; use ibc_proto::google::protobuf::Any; use ibc_types::core::client::Height; use ibc_types::core::connection::{ChainId, ConnectionId}; @@ -90,91 +90,6 @@ impl From for pb::ClientConnections { } } -pub(crate) mod ics02_validation { - use anyhow::{anyhow, Result}; - use ibc_proto::google::protobuf::Any; - use ibc_types::lightclients::tendermint::client_state::{ - ClientState as TendermintClientState, TENDERMINT_CLIENT_STATE_TYPE_URL, - }; - use ibc_types::lightclients::tendermint::consensus_state::{ - ConsensusState as TendermintConsensusState, TENDERMINT_CONSENSUS_STATE_TYPE_URL, - }; - use ibc_types::lightclients::tendermint::header::{ - Header as TendermintHeader, TENDERMINT_HEADER_TYPE_URL, - }; - use ibc_types::lightclients::tendermint::misbehaviour::{ - Misbehaviour as TendermintMisbehavior, TENDERMINT_MISBEHAVIOUR_TYPE_URL, - }; - - pub fn is_tendermint_header_state(header: &Any) -> bool { - header.type_url.as_str() == TENDERMINT_HEADER_TYPE_URL - } - pub fn is_tendermint_consensus_state(consensus_state: &Any) -> bool { - consensus_state.type_url.as_str() == TENDERMINT_CONSENSUS_STATE_TYPE_URL - } - pub fn is_tendermint_client_state(client_state: &Any) -> bool { - client_state.type_url.as_str() == TENDERMINT_CLIENT_STATE_TYPE_URL - } - pub fn is_tendermint_misbehavior(misbehavior: &Any) -> bool { - misbehavior.type_url.as_str() == TENDERMINT_MISBEHAVIOUR_TYPE_URL - } - - pub fn get_tendermint_misbehavior(misbehavior: Any) -> Result { - if is_tendermint_misbehavior(&misbehavior) { - TendermintMisbehavior::try_from(misbehavior) - .map_err(|e| anyhow!(format!("failed to deserialize tendermint misbehavior: {e}"))) - } else { - anyhow::bail!(format!( - "expected a tendermint light client misbehavior, got: {}", - misbehavior.type_url.as_str() - )) - } - } - - pub fn get_tendermint_header(header: Any) -> Result { - if is_tendermint_header_state(&header) { - TendermintHeader::try_from(header) - .map_err(|e| anyhow!(format!("failed to deserialize tendermint header: {e}"))) - } else { - anyhow::bail!(format!( - "expected a tendermint light client header, got: {}", - header.type_url.as_str() - )) - } - } - - pub fn get_tendermint_consensus_state( - consensus_state: Any, - ) -> Result { - if is_tendermint_consensus_state(&consensus_state) { - TendermintConsensusState::try_from(consensus_state).map_err(|e| { - anyhow!(format!( - "failed to deserialize tendermint consensus state: {e}" - )) - }) - } else { - anyhow::bail!(format!( - "expected tendermint consensus state, got: {}", - consensus_state.type_url.as_str() - )) - } - } - pub fn get_tendermint_client_state(client_state: Any) -> Result { - if is_tendermint_client_state(&client_state) { - TendermintClientState::try_from(client_state).map_err(|e| { - anyhow!(format!( - "failed to deserialize tendermint client state: {e}" - )) - }) - } else { - anyhow::bail!(format!( - "expected tendermint client state, got: {}", - client_state.type_url.as_str() - )) - } - } -} - // Check that the trust threshold is: // // a) non-zero diff --git a/crates/core/component/ibc/src/component/ics02_validation.rs b/crates/core/component/ibc/src/component/ics02_validation.rs new file mode 100644 index 0000000000..82f22bf470 --- /dev/null +++ b/crates/core/component/ibc/src/component/ics02_validation.rs @@ -0,0 +1,80 @@ +use anyhow::{anyhow, Result}; +use ibc_proto::google::protobuf::Any; +use ibc_types::lightclients::tendermint::client_state::{ + ClientState as TendermintClientState, TENDERMINT_CLIENT_STATE_TYPE_URL, +}; +use ibc_types::lightclients::tendermint::consensus_state::{ + ConsensusState as TendermintConsensusState, TENDERMINT_CONSENSUS_STATE_TYPE_URL, +}; +use ibc_types::lightclients::tendermint::header::{ + Header as TendermintHeader, TENDERMINT_HEADER_TYPE_URL, +}; +use ibc_types::lightclients::tendermint::misbehaviour::{ + Misbehaviour as TendermintMisbehavior, TENDERMINT_MISBEHAVIOUR_TYPE_URL, +}; + +pub fn is_tendermint_header_state(header: &Any) -> bool { + header.type_url.as_str() == TENDERMINT_HEADER_TYPE_URL +} +pub fn is_tendermint_consensus_state(consensus_state: &Any) -> bool { + consensus_state.type_url.as_str() == TENDERMINT_CONSENSUS_STATE_TYPE_URL +} +pub fn is_tendermint_client_state(client_state: &Any) -> bool { + client_state.type_url.as_str() == TENDERMINT_CLIENT_STATE_TYPE_URL +} +pub fn is_tendermint_misbehavior(misbehavior: &Any) -> bool { + misbehavior.type_url.as_str() == TENDERMINT_MISBEHAVIOUR_TYPE_URL +} + +pub fn get_tendermint_misbehavior(misbehavior: Any) -> Result { + if is_tendermint_misbehavior(&misbehavior) { + TendermintMisbehavior::try_from(misbehavior) + .map_err(|e| anyhow!(format!("failed to deserialize tendermint misbehavior: {e}"))) + } else { + anyhow::bail!(format!( + "expected a tendermint light client misbehavior, got: {}", + misbehavior.type_url.as_str() + )) + } +} + +pub fn get_tendermint_header(header: Any) -> Result { + if is_tendermint_header_state(&header) { + TendermintHeader::try_from(header) + .map_err(|e| anyhow!(format!("failed to deserialize tendermint header: {e}"))) + } else { + anyhow::bail!(format!( + "expected a tendermint light client header, got: {}", + header.type_url.as_str() + )) + } +} + +pub fn get_tendermint_consensus_state(consensus_state: Any) -> Result { + if is_tendermint_consensus_state(&consensus_state) { + TendermintConsensusState::try_from(consensus_state).map_err(|e| { + anyhow!(format!( + "failed to deserialize tendermint consensus state: {e}" + )) + }) + } else { + anyhow::bail!(format!( + "expected tendermint consensus state, got: {}", + consensus_state.type_url.as_str() + )) + } +} +pub fn get_tendermint_client_state(client_state: Any) -> Result { + if is_tendermint_client_state(&client_state) { + TendermintClientState::try_from(client_state).map_err(|e| { + anyhow!(format!( + "failed to deserialize tendermint client state: {e}" + )) + }) + } else { + anyhow::bail!(format!( + "expected tendermint client state, got: {}", + client_state.type_url.as_str() + )) + } +} diff --git a/crates/core/component/ibc/src/component/msg_handler/create_client.rs b/crates/core/component/ibc/src/component/msg_handler/create_client.rs index ccc1f9cc84..93350861f8 100644 --- a/crates/core/component/ibc/src/component/msg_handler/create_client.rs +++ b/crates/core/component/ibc/src/component/msg_handler/create_client.rs @@ -8,8 +8,8 @@ use ibc_types::{ use crate::component::{ client::{StateReadExt as _, StateWriteExt as _}, - client_counter::{ics02_validation, ClientCounter}, - MsgHandler, + client_counter::ClientCounter, + ics02_validation, MsgHandler, }; #[async_trait] diff --git a/crates/core/component/ibc/src/component/msg_handler/misbehavior.rs b/crates/core/component/ibc/src/component/msg_handler/misbehavior.rs index 4e4fc5d581..8bcde276cf 100644 --- a/crates/core/component/ibc/src/component/msg_handler/misbehavior.rs +++ b/crates/core/component/ibc/src/component/msg_handler/misbehavior.rs @@ -13,12 +13,9 @@ use tendermint_light_client_verifier::{ ProdVerifier, Verdict, Verifier, }; -use crate::component::client::StateWriteExt as _; -use crate::component::client_counter::ics02_validation; -use crate::component::ClientStateReadExt as _; - use super::update_client::verify_header_validator_set; use super::MsgHandler; +use crate::component::{client::StateWriteExt as _, ics02_validation, ClientStateReadExt as _}; #[async_trait] impl MsgHandler for MsgSubmitMisbehaviour { diff --git a/crates/core/component/ibc/src/component/msg_handler/update_client.rs b/crates/core/component/ibc/src/component/msg_handler/update_client.rs index 8acddf9c3c..635e622c03 100644 --- a/crates/core/component/ibc/src/component/msg_handler/update_client.rs +++ b/crates/core/component/ibc/src/component/msg_handler/update_client.rs @@ -18,8 +18,7 @@ use tendermint_light_client_verifier::{ use crate::component::{ client::{Ics2ClientExt as _, StateReadExt as _, StateWriteExt as _}, - client_counter::ics02_validation, - MsgHandler, + ics02_validation, MsgHandler, }; #[async_trait]