Skip to content

Commit 127cc70

Browse files
committed
wip
1 parent 8344617 commit 127cc70

File tree

9 files changed

+390
-9
lines changed

9 files changed

+390
-9
lines changed

Cargo.lock

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ members = [
165165
"voyager/modules/client/state-lens/ics23-smt",
166166
"voyager/modules/client/sui",
167167
"voyager/modules/client/trusted-mpt",
168+
"voyager/modules/client/attested",
168169

169170
"voyager/modules/client-bootstrap/base",
170171
"voyager/modules/client-bootstrap/bob",
@@ -180,6 +181,7 @@ members = [
180181
"voyager/modules/client-bootstrap/state-lens/ics23-smt",
181182
"voyager/modules/client-bootstrap/state-lens/ics23-ics23",
182183
"voyager/modules/client-bootstrap/sui",
184+
"voyager/modules/client-bootstrap/attested",
183185

184186
"voyager/modules/finality/base",
185187
"voyager/modules/finality/bob",

lib/voyager-plugin/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{env::VarError, time::Duration};
33
use opentelemetry::KeyValue;
44
use opentelemetry_otlp::WithExportConfig;
55
use serde::de::DeserializeOwned;
6-
use tracing::{Instrument, debug_span, instrument};
6+
use tracing::{Instrument, debug_span, error, instrument};
77
use tracing_subscriber::{EnvFilter, Layer, layer::SubscriberExt, util::SubscriberInitExt};
88
use unionlabs::ErrorReporter;
99
pub use voyager_plugin_protocol as protocol;
@@ -344,12 +344,12 @@ fn init(metrics_endpoint: Option<String>) {
344344
}
345345
}
346346

347-
#[instrument(level = "debug", fields(%config_str))]
347+
#[instrument(level = "info", fields(%config_str, current_exe = ?std::env::current_exe().unwrap_or_default()))]
348348
fn must_parse<T: DeserializeOwned>(config_str: &str) -> T {
349349
match serde_json::from_str::<T>(config_str) {
350350
Ok(ok) => ok,
351351
Err(err) => {
352-
eprintln!("invalid config: {}", ErrorReporter(err));
352+
error!("invalid config: {}", ErrorReporter(err));
353353
std::process::exit(INVALID_CONFIG_EXIT_CODE as i32);
354354
}
355355
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[package]
2+
name = "voyager-client-bootstrap-module-attested"
3+
version = "0.0.0"
4+
5+
authors = { workspace = true }
6+
edition = { workspace = true }
7+
license-file = { workspace = true }
8+
publish = { workspace = true }
9+
repository = { workspace = true }
10+
11+
[lints]
12+
workspace = true
13+
14+
[dependencies]
15+
alloy = { workspace = true, features = ["rpc", "rpc-types", "transports", "transport-http", "transport-ws", "reqwest", "reqwest-rustls-tls", "provider-ws"] }
16+
attested-light-client = { workspace = true }
17+
attested-light-client-types = { workspace = true, features = ["serde"] }
18+
embed-commit = { workspace = true }
19+
ibc-union-spec = { workspace = true, features = ["serde"] }
20+
jsonrpsee = { workspace = true, features = ["macros", "server", "tracing"] }
21+
prost = { workspace = true }
22+
protos = { workspace = true }
23+
serde = { workspace = true, features = ["derive"] }
24+
serde_json = { workspace = true }
25+
thiserror = { workspace = true }
26+
tokio = { workspace = true }
27+
tracing = { workspace = true }
28+
unionlabs = { workspace = true }
29+
voyager-sdk = { workspace = true }
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
use alloy::{
2+
network::AnyNetwork,
3+
providers::{DynProvider, Provider, ProviderBuilder},
4+
};
5+
use attested_light_client_types::{ClientState, ClientStateV1, ConsensusState};
6+
use ibc_union_spec::Timestamp;
7+
use jsonrpsee::{
8+
Extensions,
9+
core::{RpcResult, async_trait},
10+
};
11+
use serde::{Deserialize, Serialize};
12+
use serde_json::Value;
13+
use tracing::instrument;
14+
use unionlabs::ibc::core::client::height::Height;
15+
use voyager_sdk::{
16+
anyhow, ensure_null, into_value,
17+
plugin::ClientBootstrapModule,
18+
primitives::ChainId,
19+
rpc::{ClientBootstrapModuleServer, types::ClientBootstrapModuleInfo},
20+
};
21+
22+
#[tokio::main(flavor = "multi_thread")]
23+
async fn main() {
24+
Module::run().await;
25+
}
26+
27+
#[derive(Debug, Clone)]
28+
pub struct Module {
29+
pub chain_id: ChainId,
30+
pub provider: DynProvider<AnyNetwork>,
31+
}
32+
33+
#[derive(Debug, Clone, Serialize, Deserialize)]
34+
#[serde(deny_unknown_fields)]
35+
pub struct Config {
36+
pub rpc_url: String,
37+
}
38+
39+
impl ClientBootstrapModule for Module {
40+
type Config = Config;
41+
42+
async fn new(config: Self::Config, info: ClientBootstrapModuleInfo) -> anyhow::Result<Self> {
43+
let provider = DynProvider::new(
44+
ProviderBuilder::new()
45+
.network::<AnyNetwork>()
46+
.connect(&config.rpc_url)
47+
.await?,
48+
);
49+
50+
let chain_id = provider.get_chain_id().await?.to_string();
51+
52+
info.ensure_chain_id(&chain_id)?;
53+
54+
Ok(Self {
55+
chain_id: ChainId::new(chain_id),
56+
provider,
57+
})
58+
}
59+
}
60+
61+
#[async_trait]
62+
impl ClientBootstrapModuleServer for Module {
63+
#[instrument(skip_all, fields(chain_id = %self.chain_id, %height))]
64+
async fn self_client_state(
65+
&self,
66+
_: &Extensions,
67+
height: Height,
68+
config: Value,
69+
) -> RpcResult<Value> {
70+
ensure_null(config)?;
71+
72+
Ok(serde_json::to_value(ClientState::V1(ClientStateV1 {
73+
chain_id: self.chain_id.to_string(),
74+
latest_height: height.height(),
75+
}))
76+
.expect("infallible"))
77+
}
78+
79+
#[instrument(skip_all, fields(chain_id = %self.chain_id, %height))]
80+
async fn self_consensus_state(
81+
&self,
82+
_: &Extensions,
83+
height: Height,
84+
config: Value,
85+
) -> RpcResult<Value> {
86+
ensure_null(config)?;
87+
88+
let timestamp = self
89+
.provider
90+
.get_block_by_number(height.height().into())
91+
.await
92+
.unwrap()
93+
.unwrap()
94+
.header
95+
.timestamp;
96+
97+
Ok(into_value(ConsensusState {
98+
timestamp: Timestamp::from_secs(timestamp),
99+
}))
100+
}
101+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
name = "voyager-client-module-attested"
3+
version = "0.0.0"
4+
5+
authors = { workspace = true }
6+
edition = { workspace = true }
7+
license-file = { workspace = true }
8+
publish = { workspace = true }
9+
repository = { workspace = true }
10+
11+
[lints]
12+
workspace = true
13+
14+
[dependencies]
15+
attested-light-client-types = { workspace = true, features = ["serde", "bincode", "ethabi"] }
16+
embed-commit = { workspace = true }
17+
jsonrpsee = { workspace = true, features = ["macros", "server", "tracing"] }
18+
serde = { workspace = true, features = ["derive"] }
19+
serde_json = { workspace = true }
20+
tokio = { workspace = true }
21+
tracing = { workspace = true }
22+
unionlabs = { workspace = true, features = ["bincode"] }
23+
voyager-sdk = { workspace = true }

0 commit comments

Comments
 (0)