Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Jan 15, 2024
1 parent 2148727 commit 7526033
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 69 deletions.
5 changes: 0 additions & 5 deletions crates/core/component/ibc/src/component/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
101 changes: 56 additions & 45 deletions crates/core/component/ibc/src/component/rpc/client_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C: ChainStateReadExt + Snapshot + 'static, S: Storage<C>> ClientQuery for IbcQuery<C, S> {
Expand All @@ -46,36 +46,36 @@ impl<C: ChainStateReadExt + Snapshot + 'static, S: Storage<C>> 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
Expand Down Expand Up @@ -141,7 +141,7 @@ impl<C: ChainStateReadExt + Snapshot + 'static, S: Storage<C>> ClientQuery for I
async fn consensus_state(
&self,
request: tonic::Request<QueryConsensusStateRequest>,
) -> std::result::Result<tonic::Response<QueryConsensusStateResponse>, tonic::Status>
) -> std::result::Result<tonic::Response<QueryConsensusStateResponse>, tonic::Status> {
let Some(height_val) = request.metadata().get("height") else {
return Err(tonic::Status::aborted("missing height"));
};
Expand All @@ -150,28 +150,39 @@ impl<C: ChainStateReadExt + Snapshot + 'static, S: Storage<C>> 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}")))?;
Expand Down
26 changes: 16 additions & 10 deletions crates/core/component/ibc/src/component/rpc/connection_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C: ChainStateReadExt + Snapshot + 'static, S: Storage<C>> ConnectionQuery for IbcQuery<C, S> {
Expand All @@ -46,18 +46,24 @@ impl<C: ChainStateReadExt + Snapshot + 'static, S: Storage<C>> 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)
Expand Down
2 changes: 1 addition & 1 deletion crates/core/component/ibc/src/component/rpc/utils.rs
Original file line number Diff line number Diff line change
@@ -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<Height> {
let split: Vec<&str> = value.split('-').collect();
Expand Down

0 comments on commit 7526033

Please sign in to comment.