Skip to content

Commit

Permalink
Fix ClientConsensusState query (#31)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
romac authored Mar 17, 2020
1 parent c67f1fc commit e39e84d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions relayer/relay/src/query/client_consensus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ use crate::chain::Chain;
use crate::error;

pub struct QueryClientConsensusState<CS> {
pub height: Height,
pub chain_height: Height,
pub client_id: ClientId,
pub consensus_height: Height,
pub consensus_state_path: ConsensusStatePath,
marker: PhantomData<CS>,
}

impl<CS> QueryClientConsensusState<CS> {
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,
}
}
Expand All @@ -42,7 +44,7 @@ where
}

fn height(&self) -> Height {
self.height
self.chain_height
}

fn prove(&self) -> bool {
Expand All @@ -69,6 +71,7 @@ impl<CS> ConsensusStateResponse<CS> {
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));

Expand Down Expand Up @@ -107,13 +110,14 @@ where

pub async fn query_client_consensus_state<C>(
chain: &C,
chain_height: Height,
client_id: ClientId,
height: Height,
consensus_height: Height,
) -> Result<ConsensusStateResponse<C::ConsensusState>, 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
}
Expand Down

0 comments on commit e39e84d

Please sign in to comment.