Skip to content

Commit e39e84d

Browse files
authored
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.
1 parent c67f1fc commit e39e84d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

relayer/relay/src/query/client_consensus_state.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ use crate::chain::Chain;
1414
use crate::error;
1515

1616
pub struct QueryClientConsensusState<CS> {
17-
pub height: Height,
17+
pub chain_height: Height,
1818
pub client_id: ClientId,
19+
pub consensus_height: Height,
1920
pub consensus_state_path: ConsensusStatePath,
2021
marker: PhantomData<CS>,
2122
}
2223

2324
impl<CS> QueryClientConsensusState<CS> {
24-
pub fn new(height: Height, client_id: ClientId) -> Self {
25+
pub fn new(chain_height: Height, client_id: ClientId, consensus_height: Height) -> Self {
2526
Self {
26-
height,
27+
chain_height,
2728
client_id: client_id.clone(),
28-
consensus_state_path: ConsensusStatePath::new(client_id, height),
29+
consensus_height,
30+
consensus_state_path: ConsensusStatePath::new(client_id, consensus_height),
2931
marker: PhantomData,
3032
}
3133
}
@@ -42,7 +44,7 @@ where
4244
}
4345

4446
fn height(&self) -> Height {
45-
self.height
47+
self.chain_height
4648
}
4749

4850
fn prove(&self) -> bool {
@@ -69,6 +71,7 @@ impl<CS> ConsensusStateResponse<CS> {
6971
proof_height: Height,
7072
) -> Self {
7173
let proof = CommitmentProof::from_bytes(abci_proof.as_ref());
74+
7275
let proof_path =
7376
CommitmentPath::from_path(ConsensusStatePath::new(client_id, proof_height));
7477

@@ -107,13 +110,14 @@ where
107110

108111
pub async fn query_client_consensus_state<C>(
109112
chain: &C,
113+
chain_height: Height,
110114
client_id: ClientId,
111-
height: Height,
115+
consensus_height: Height,
112116
) -> Result<ConsensusStateResponse<C::ConsensusState>, error::Error>
113117
where
114118
C: Chain,
115119
{
116-
let query = QueryClientConsensusState::new(height, client_id);
120+
let query = QueryClientConsensusState::new(chain_height, client_id, consensus_height);
117121

118122
ibc_query(chain, query).await
119123
}

0 commit comments

Comments
 (0)