From 752603311c724b6bacbc491f685ea357252b5e80 Mon Sep 17 00:00:00 2001 From: elizabeth Date: Mon, 15 Jan 2024 17:17:40 -0500 Subject: [PATCH] cleanup --- .../component/ibc/src/component/client.rs | 5 - .../msg_handler/connection_open_try.rs | 8 -- .../ibc/src/component/rpc/client_query.rs | 101 ++++++++++-------- .../ibc/src/component/rpc/connection_query.rs | 26 +++-- .../component/ibc/src/component/rpc/utils.rs | 2 +- 5 files changed, 73 insertions(+), 69 deletions(-) diff --git a/crates/core/component/ibc/src/component/client.rs b/crates/core/component/ibc/src/component/client.rs index fb801fb24d..1de6a2ec8e 100644 --- a/crates/core/component/ibc/src/component/client.rs +++ b/crates/core/component/ibc/src/component/client.rs @@ -120,11 +120,6 @@ pub trait ConsensusStateWriteExt: StateWrite + ChainStateReadExt { client_id: ClientId, consensus_state: TendermintConsensusState, ) -> Result<()> { - println!( - "putting verified consensus state for client {} at height {}", - client_id, height - ); - self.put( IBC_COMMITMENT_PREFIX .apply_string(ClientConsensusStatePath::new(&client_id, &height).to_string()), diff --git a/crates/core/component/ibc/src/component/msg_handler/connection_open_try.rs b/crates/core/component/ibc/src/component/msg_handler/connection_open_try.rs index 7e6d946f0c..6c739d859f 100644 --- a/crates/core/component/ibc/src/component/msg_handler/connection_open_try.rs +++ b/crates/core/component/ibc/src/component/msg_handler/connection_open_try.rs @@ -92,14 +92,6 @@ impl MsgHandler for MsgConnectionOpenTry { anyhow::bail!("client is frozen"); } - // TODO: why is hermes using a lower height... - //let height = state.prev_verified_consensus_state(&self.client_id_on_b, &self.proofs_height_on_a).await?; - println!("proofs height: {:?}", self.proofs_height_on_a); - println!( - "client state latest height: {:?}", - trusted_client_state.latest_height - ); - // get the stored consensus state for the counterparty let trusted_consensus_state = state .get_verified_consensus_state(&self.proofs_height_on_a, &self.client_id_on_b) diff --git a/crates/core/component/ibc/src/component/rpc/client_query.rs b/crates/core/component/ibc/src/component/rpc/client_query.rs index 787fdcaa67..9b17d9f7c6 100644 --- a/crates/core/component/ibc/src/component/rpc/client_query.rs +++ b/crates/core/component/ibc/src/component/rpc/client_query.rs @@ -23,12 +23,12 @@ use ibc_types::DomainType; use std::str::FromStr; use tonic::{Response, Status}; +use super::utils::height_from_str; use crate::component::rpc::Snapshot; use crate::component::rpc::{IbcQuery, Storage}; use crate::component::ClientStateReadExt; use crate::prefix::MerklePrefixExt; use crate::IBC_COMMITMENT_PREFIX; -use super::utils::height_from_str; #[async_trait] impl> ClientQuery for IbcQuery { @@ -46,36 +46,36 @@ impl> ClientQuery for I let (snapshot, height) = if height_str == "0" { let snapshot = self.0.latest_snapshot(); - let height = snapshot.get_block_height().await.map_err(|e| { - tonic::Status::aborted(format!("couldn't get block height: {e}")) - })? as u64; - (snapshot, Height { - revision_number: 0, - revision_height: height, - }) + let height = + snapshot.get_block_height().await.map_err(|e| { + tonic::Status::aborted(format!("couldn't get block height: {e}")) + })? as u64; + ( + snapshot, + Height { + revision_number: 0, + revision_height: height, + }, + ) } else { let height = height_from_str(height_str) - .map_err(|e| tonic::Status::aborted(format!("couldn't get snapshot: {e}")))?; + .map_err(|e| tonic::Status::aborted(format!("couldn't get snapshot: {e}")))?; - let snapshot = self.0.snapshot(height.revision_height as u64) + let snapshot = self + .0 + .snapshot(height.revision_height as u64) .ok_or(tonic::Status::aborted(format!("invalid height")))?; - (snapshot, height.try_into().map_err(|e| tonic::Status::aborted(format!("invalid height: {e}")))?) + ( + snapshot, + height + .try_into() + .map_err(|e| tonic::Status::aborted(format!("invalid height: {e}")))?, + ) }; - //let snapshot = self.0.latest_snapshot(); let client_id = ClientId::from_str(&request.get_ref().client_id) .map_err(|e| tonic::Status::invalid_argument(format!("invalid client id: {e}")))?; - // let height = Height { - // revision_number: snapshot - // .get_revision_number() - // .await - // .map_err(|e| tonic::Status::aborted(e.to_string()))?, - // revision_height: snapshot - // .get_block_height() - // .await - // .map_err(|e| tonic::Status::aborted(format!("couldn't get block height: {e}")))?, - // }; // Query for client_state and associated proof. let (cs_opt, proof) = snapshot @@ -141,7 +141,7 @@ impl> ClientQuery for I async fn consensus_state( &self, request: tonic::Request, - ) -> std::result::Result, tonic::Status> + ) -> std::result::Result, tonic::Status> { let Some(height_val) = request.metadata().get("height") else { return Err(tonic::Status::aborted("missing height")); }; @@ -150,28 +150,39 @@ impl> ClientQuery for I .to_str() .map_err(|e| tonic::Status::aborted(format!("invalid height: {e}")))?; - let (snapshot, query_height) = if height_str == "0" { - let snapshot = self.0.latest_snapshot(); - let height = snapshot.get_block_height().await.map_err(|e| { - tonic::Status::aborted(format!("couldn't get block height: {e}")) - })? as u64; - (snapshot, Height { - revision_number: 0, - revision_height: height, - }) - } else { - let height = height_from_str(height_str) - .map_err(|e| tonic::Status::aborted(format!("couldn't get snapshot: {e}")))?; - - let snapshot = self.0.snapshot(height.revision_height as u64) - .ok_or(tonic::Status::aborted(format!("invalid height")))?; - - let snapshot_height = snapshot.get_block_height().await.map_err(|e| { - tonic::Status::aborted(format!("couldn't get block height: {e}")) - })? as u64; - - (snapshot, height.try_into().map_err(|e| tonic::Status::aborted(format!("invalid height: {e}")))?) - }; + let (snapshot, query_height) = + if height_str == "0" { + let snapshot = self.0.latest_snapshot(); + let height = snapshot.get_block_height().await.map_err(|e| { + tonic::Status::aborted(format!("couldn't get block height: {e}")) + })? as u64; + ( + snapshot, + Height { + revision_number: 0, + revision_height: height, + }, + ) + } else { + let height = height_from_str(height_str) + .map_err(|e| tonic::Status::aborted(format!("couldn't get snapshot: {e}")))?; + + let snapshot = self + .0 + .snapshot(height.revision_height as u64) + .ok_or(tonic::Status::aborted(format!("invalid height")))?; + + let snapshot_height = snapshot.get_block_height().await.map_err(|e| { + tonic::Status::aborted(format!("couldn't get block height: {e}")) + })? as u64; + + ( + snapshot, + height + .try_into() + .map_err(|e| tonic::Status::aborted(format!("invalid height: {e}")))?, + ) + }; let client_id = ClientId::from_str(&request.get_ref().client_id) .map_err(|e| tonic::Status::invalid_argument(format!("invalid client id: {e}")))?; diff --git a/crates/core/component/ibc/src/component/rpc/connection_query.rs b/crates/core/component/ibc/src/component/rpc/connection_query.rs index 298f012470..da92085f30 100644 --- a/crates/core/component/ibc/src/component/rpc/connection_query.rs +++ b/crates/core/component/ibc/src/component/rpc/connection_query.rs @@ -25,8 +25,8 @@ use crate::component::ConnectionStateReadExt; use crate::prefix::MerklePrefixExt; use crate::IBC_COMMITMENT_PREFIX; -use super::IbcQuery; use super::utils::height_from_str; +use super::IbcQuery; #[async_trait] impl> ConnectionQuery for IbcQuery { @@ -46,18 +46,24 @@ impl> ConnectionQuery f let (snapshot, height) = if height_str == "0" { let snapshot = self.0.latest_snapshot(); - let height = snapshot.get_block_height().await.map_err(|e| { - tonic::Status::aborted(format!("couldn't get block height: {e}")) - })? as u64; - (snapshot, Height { - revision_number: 0, - revision_height: height, - }) + let height = + snapshot.get_block_height().await.map_err(|e| { + tonic::Status::aborted(format!("couldn't get block height: {e}")) + })? as u64; + ( + snapshot, + Height { + revision_number: 0, + revision_height: height, + }, + ) } else { let height = height_from_str(height_str) - .map_err(|e| tonic::Status::aborted(format!("couldn't get snapshot: {e}")))?; + .map_err(|e| tonic::Status::aborted(format!("couldn't get snapshot: {e}")))?; - let snapshot = self.0.snapshot(height.revision_height as u64) + let snapshot = self + .0 + .snapshot(height.revision_height as u64) .ok_or(tonic::Status::aborted(format!("invalid height")))?; (snapshot, height) diff --git a/crates/core/component/ibc/src/component/rpc/utils.rs b/crates/core/component/ibc/src/component/rpc/utils.rs index 729fc505bb..108a14248a 100644 --- a/crates/core/component/ibc/src/component/rpc/utils.rs +++ b/crates/core/component/ibc/src/component/rpc/utils.rs @@ -1,5 +1,5 @@ use anyhow::anyhow; -use ibc_proto::ibc::core::client::v1::{Height}; +use ibc_proto::ibc::core::client::v1::Height; pub(crate) fn height_from_str(value: &str) -> anyhow::Result { let split: Vec<&str> = value.split('-').collect();