From e39e84d9e03aff35b2b8ee7fbc6d1617d2b9fdde Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Tue, 17 Mar 2020 13:48:19 +0100 Subject: [PATCH] Fix ClientConsensusState query (#31) Closes: #30 Query of client consensus now distinguishes between query height and consensus height. Specifically: - `chain_height` is the height at which the query is made (can be 0 if the latest state on chain is queried). - `consensus_height` is the consensus height of the client running on this chain but it represents a height of the client's chain and should be used to construct the query path. --- .../relay/src/query/client_consensus_state.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/relayer/relay/src/query/client_consensus_state.rs b/relayer/relay/src/query/client_consensus_state.rs index d6bb09804..c2209a24b 100644 --- a/relayer/relay/src/query/client_consensus_state.rs +++ b/relayer/relay/src/query/client_consensus_state.rs @@ -14,18 +14,20 @@ use crate::chain::Chain; use crate::error; pub struct QueryClientConsensusState { - pub height: Height, + pub chain_height: Height, pub client_id: ClientId, + pub consensus_height: Height, pub consensus_state_path: ConsensusStatePath, marker: PhantomData, } impl QueryClientConsensusState { - pub fn new(height: Height, client_id: ClientId) -> Self { + pub fn new(chain_height: Height, client_id: ClientId, consensus_height: Height) -> Self { Self { - height, + chain_height, client_id: client_id.clone(), - consensus_state_path: ConsensusStatePath::new(client_id, height), + consensus_height, + consensus_state_path: ConsensusStatePath::new(client_id, consensus_height), marker: PhantomData, } } @@ -42,7 +44,7 @@ where } fn height(&self) -> Height { - self.height + self.chain_height } fn prove(&self) -> bool { @@ -69,6 +71,7 @@ impl ConsensusStateResponse { proof_height: Height, ) -> Self { let proof = CommitmentProof::from_bytes(abci_proof.as_ref()); + let proof_path = CommitmentPath::from_path(ConsensusStatePath::new(client_id, proof_height)); @@ -107,13 +110,14 @@ where pub async fn query_client_consensus_state( chain: &C, + chain_height: Height, client_id: ClientId, - height: Height, + consensus_height: Height, ) -> Result, error::Error> where C: Chain, { - let query = QueryClientConsensusState::new(height, client_id); + let query = QueryClientConsensusState::new(chain_height, client_id, consensus_height); ibc_query(chain, query).await }