Skip to content

Commit 6203a0e

Browse files
committed
wip
1 parent f33b5b5 commit 6203a0e

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

relayer/cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ authors = [
99

1010
[dependencies]
1111
relayer = { path = "../relay" }
12-
tendermint = { git = "https://github.com/romac/tendermint-rs.git", branch = "rpc-client-new-sync" }
12+
tendermint = { git = "https://github.com/interchainio/tendermint-rs.git" }
1313

1414
anomaly = "0.2.0"
1515
gumdrop = "0.7"

relayer/relay/src/chain.rs

+37
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
use anomaly::fail;
2+
13
use ::tendermint::lite::types as tmlite;
4+
use ::tendermint::lite::Height;
25
use ::tendermint::rpc::Client as RpcClient;
36

47
use relayer_modules::ics02_client::state::ConsensusState;
58

69
use crate::config::ChainConfig;
10+
use crate::error;
711

812
pub mod tendermint;
913

@@ -18,3 +22,36 @@ pub trait Chain {
1822
fn rpc_client(&self) -> &RpcClient;
1923
fn requester(&self) -> &Self::Requester;
2024
}
25+
26+
pub async fn query_latest_height(chain: &impl Chain) -> Result<Height, error::Error> {
27+
let status = chain
28+
.rpc_client()
29+
.status()
30+
.await
31+
.map_err(|e| error::Kind::Rpc.context(e))?;
32+
33+
if status.sync_info.catching_up {
34+
fail!(
35+
error::Kind::LightClient,
36+
"node at {} running chain {} not caught up",
37+
chain.config().rpc_addr,
38+
chain.config().id,
39+
);
40+
}
41+
42+
Ok(status.sync_info.latest_block_height.into())
43+
}
44+
45+
pub async fn query_header_at_height<C>(chain: &C, height: Height) -> Result<C::Header, error::Error>
46+
where
47+
C: Chain,
48+
{
49+
use tmlite::Requester;
50+
51+
let header = chain
52+
.requester()
53+
.signed_header(height)
54+
.map_err(|e| error::Kind::Rpc.context(e))?;
55+
56+
Ok(header)
57+
}

relayer/relay/src/light_client.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use std::marker::PhantomData;
22

3+
use anomaly::fail;
4+
35
use tendermint::lite::types::{Header, Requester};
46
use tendermint::lite::{TrustThreshold, TrustedState};
57

6-
use crate::chain::Chain;
8+
use crate::chain::{query_latest_height, Chain};
79
use crate::error;
810
use crate::store::{Store, StoreHeight};
911

@@ -55,7 +57,7 @@ where
5557
}
5658
}
5759

58-
pub fn init_without_trust(
60+
pub fn init_without_trusted_state(
5961
self,
6062
) -> Result<LightClient<'a, C, S, state::InitUntrusted>, error::Error> {
6163
let req = &self.chain.requester();
@@ -96,7 +98,17 @@ where
9698
Ok(self.to())
9799
}
98100

99-
pub fn init_with_trust(
101+
pub async fn init_with_node_trusted_state(
102+
self,
103+
) -> Result<LightClient<'a, C, S, state::InitTrusted>, error::Error>
104+
where
105+
C: Chain,
106+
{
107+
let height = query_latest_height(self.chain).await?;
108+
todo!()
109+
}
110+
111+
pub fn init_with_trusted_state(
100112
self,
101113
_trust_options: TrustOptions<impl TrustThreshold>,
102114
) -> Result<LightClient<'a, C, S, state::InitTrusted>, error::Error> {

0 commit comments

Comments
 (0)