diff --git a/Cargo.lock b/Cargo.lock index 6bc1964cca..ed3ff9fd40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13353,55 +13353,19 @@ dependencies = [ ] [[package]] -name = "voyager-client-update-plugin-state-lens-evm" +name = "voyager-client-update-plugin-state-lens" version = "0.1.0" dependencies = [ "alloy", - "cometbft-rpc", - "cometbft-types", - "dashmap 5.5.3", "enumorph", - "futures", "ibc-union-spec", "ics23", "jsonrpsee", "macros", - "num-bigint 0.4.6", - "prost 0.12.6", "protos", "serde", "serde_json", "state-lens-light-client-types", - "thiserror", - "tokio", - "tracing", - "tracing-subscriber 0.3.18", - "unionlabs", - "voyager-message", - "voyager-vm", -] - -[[package]] -name = "voyager-client-update-plugin-state-lens-ics23-ics23" -version = "0.1.0" -dependencies = [ - "alloy", - "cometbft-rpc", - "cometbft-types", - "dashmap 5.5.3", - "enumorph", - "futures", - "ibc-union-spec", - "ics23", - "jsonrpsee", - "macros", - "num-bigint 0.4.6", - "prost 0.12.6", - "protos", - "serde", - "serde_json", - "state-lens-ics23-ics23-light-client-types", - "thiserror", "tokio", "tracing", "tracing-subscriber 0.3.18", diff --git a/Cargo.toml b/Cargo.toml index 404f545cff..bfd64da127 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -139,8 +139,7 @@ members = [ "voyager/plugins/client-update/ethereum", "voyager/plugins/client-update/movement", "voyager/plugins/client-update/tendermint", - "voyager/plugins/client-update/state-lens/evm", - "voyager/plugins/client-update/state-lens/ics23-ics23", + "voyager/plugins/client-update/state-lens", "voyager/plugins/periodic-client-update", diff --git a/voyager/plugins/client-update/state-lens/evm/Cargo.toml b/voyager/plugins/client-update/state-lens/Cargo.toml similarity index 72% rename from voyager/plugins/client-update/state-lens/evm/Cargo.toml rename to voyager/plugins/client-update/state-lens/Cargo.toml index a99c3bffff..8f4a300953 100644 --- a/voyager/plugins/client-update/state-lens/evm/Cargo.toml +++ b/voyager/plugins/client-update/state-lens/Cargo.toml @@ -1,26 +1,19 @@ [package] edition = "2021" -name = "voyager-client-update-plugin-state-lens-evm" +name = "voyager-client-update-plugin-state-lens" version = "0.1.0" [dependencies] alloy = { workspace = true, features = ["rpc", "rpc-types", "transports", "transport-http", "transport-ws", "reqwest", "provider-ws"] } -cometbft-rpc = { workspace = true } -cometbft-types = { workspace = true } -dashmap = { workspace = true } enumorph = { workspace = true } -futures = { workspace = true } ibc-union-spec = { workspace = true } ics23 = { workspace = true } jsonrpsee = { workspace = true, features = ["macros", "server", "tracing"] } macros = { workspace = true } -num-bigint = { workspace = true } -prost = { workspace = true } protos = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } state-lens-light-client-types = { workspace = true, features = ["serde"] } -thiserror = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } diff --git a/voyager/plugins/client-update/state-lens/ics23-ics23/Cargo.toml b/voyager/plugins/client-update/state-lens/ics23-ics23/Cargo.toml deleted file mode 100644 index 8827b42c43..0000000000 --- a/voyager/plugins/client-update/state-lens/ics23-ics23/Cargo.toml +++ /dev/null @@ -1,29 +0,0 @@ -[package] -edition = "2021" -name = "voyager-client-update-plugin-state-lens-ics23-ics23" -version = "0.1.0" - -[dependencies] -alloy = { workspace = true, features = ["rpc", "rpc-types", "transports", "transport-http", "transport-ws", "reqwest", "provider-ws"] } -cometbft-rpc = { workspace = true } -cometbft-types.workspace = true -dashmap = { workspace = true } -enumorph = { workspace = true } -futures = { workspace = true } -ibc-union-spec.workspace = true -ics23 = { workspace = true } -jsonrpsee = { workspace = true, features = ["macros", "server", "tracing"] } -macros = { workspace = true } -num-bigint = { workspace = true } -prost = { workspace = true } -protos = { workspace = true } -serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true } -state-lens-ics23-ics23-light-client-types = { workspace = true, features = ["serde"] } -thiserror = { workspace = true } -tokio = { workspace = true } -tracing = { workspace = true } -tracing-subscriber = { workspace = true } -unionlabs = { workspace = true } -voyager-message = { workspace = true } -voyager-vm = { workspace = true } diff --git a/voyager/plugins/client-update/state-lens/ics23-ics23/src/call.rs b/voyager/plugins/client-update/state-lens/ics23-ics23/src/call.rs deleted file mode 100644 index 3d9897aafd..0000000000 --- a/voyager/plugins/client-update/state-lens/ics23-ics23/src/call.rs +++ /dev/null @@ -1,25 +0,0 @@ -use enumorph::Enumorph; -use macros::model; -use unionlabs::ibc::core::client::height::Height; -use voyager_message::core::ChainId; - -#[model] -#[derive(Enumorph)] -pub enum ModuleCall { - FetchUpdate(FetchUpdate), - FetchUpdateAfterL1Update(FetchUpdateAfterL1Update), -} - -#[model] -pub struct FetchUpdate { - pub counterparty_chain_id: ChainId, - pub update_from: Height, - pub update_to: Height, -} - -#[model] -pub struct FetchUpdateAfterL1Update { - pub counterparty_chain_id: ChainId, - pub update_from: Height, - pub update_to: Height, -} diff --git a/voyager/plugins/client-update/state-lens/ics23-ics23/src/callback.rs b/voyager/plugins/client-update/state-lens/ics23-ics23/src/callback.rs deleted file mode 100644 index a332e95f9a..0000000000 --- a/voyager/plugins/client-update/state-lens/ics23-ics23/src/callback.rs +++ /dev/null @@ -1,6 +0,0 @@ -use enumorph::Enumorph; -use macros::model; - -#[model] -#[derive(Enumorph)] -pub enum ModuleCallback {} diff --git a/voyager/plugins/client-update/state-lens/ics23-ics23/src/data.rs b/voyager/plugins/client-update/state-lens/ics23-ics23/src/data.rs deleted file mode 100644 index f52f66d6b6..0000000000 --- a/voyager/plugins/client-update/state-lens/ics23-ics23/src/data.rs +++ /dev/null @@ -1,4 +0,0 @@ -use macros::model; - -#[model] -pub enum ModuleData {} diff --git a/voyager/plugins/client-update/state-lens/ics23-ics23/src/main.rs b/voyager/plugins/client-update/state-lens/ics23-ics23/src/main.rs deleted file mode 100644 index 1bf6c303cf..0000000000 --- a/voyager/plugins/client-update/state-lens/ics23-ics23/src/main.rs +++ /dev/null @@ -1,311 +0,0 @@ -use std::{collections::VecDeque, fmt::Debug}; - -use call::FetchUpdateAfterL1Update; -use ibc_union_spec::{ConsensusStatePath, IbcUnion}; -use jsonrpsee::{ - core::{async_trait, RpcResult}, - Extensions, -}; -use serde::{Deserialize, Serialize}; -use state_lens_ics23_ics23_light_client_types::Header; -use tracing::{debug, instrument}; -use unionlabs::ibc::core::commitment::merkle_proof::MerkleProof; -use voyager_message::{ - call::{Call, FetchUpdateHeaders, WaitForTrustedHeight}, - callback::AggregateMsgUpdateClientsFromOrderedHeaders, - core::{ChainId, ClientType, IbcSpec, QueryHeight}, - data::{Data, DecodedHeaderMeta, OrderedHeaders}, - hook::UpdateHook, - into_value, - module::{PluginInfo, PluginServer}, - DefaultCmd, ExtensionsExt, Plugin, PluginMessage, RawClientId, VoyagerClient, VoyagerMessage, -}; -use voyager_vm::{call, conc, data, pass::PassResult, promise, seq, BoxDynError, Op, Visit}; - -use crate::{ - call::{FetchUpdate, ModuleCall}, - callback::ModuleCallback, -}; - -pub mod call; -pub mod callback; - -#[tokio::main(flavor = "multi_thread")] -async fn main() { - Module::run().await -} - -#[derive(Debug, Clone)] -pub struct Module { - pub l0_client_id: u32, - pub l1_client_id: u32, - pub l1_chain_id: ChainId, - pub l2_chain_id: ChainId, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Config { - pub l0_client_id: u32, - pub l1_client_id: u32, - pub l1_chain_id: ChainId, - pub l2_chain_id: ChainId, -} - -impl Plugin for Module { - type Call = ModuleCall; - type Callback = ModuleCallback; - - type Config = Config; - type Cmd = DefaultCmd; - - async fn new(config: Self::Config) -> Result { - Ok(Self { - l0_client_id: config.l0_client_id, - l1_client_id: config.l1_client_id, - l1_chain_id: config.l1_chain_id, - l2_chain_id: config.l2_chain_id, - }) - } - - fn info(config: Self::Config) -> PluginInfo { - PluginInfo { - name: plugin_name(&config.l2_chain_id), - interest_filter: UpdateHook::filter( - &config.l2_chain_id, - &ClientType::new(ClientType::STATE_LENS_ICS23_ICS23), - ), - } - } - - async fn cmd(_config: Self::Config, cmd: Self::Cmd) { - match cmd {} - } -} - -fn plugin_name(chain_id: &ChainId) -> String { - pub const PLUGIN_NAME: &str = env!("CARGO_PKG_NAME"); - - format!("{PLUGIN_NAME}/{}", chain_id) -} - -impl Module { - fn plugin_name(&self) -> String { - plugin_name(&self.l2_chain_id) - } -} - -#[async_trait] -impl PluginServer for Module { - #[instrument(skip_all, fields(chain_id = %self.l2_chain_id))] - async fn run_pass( - &self, - _: &Extensions, - msgs: Vec>, - ) -> RpcResult> { - Ok(PassResult { - optimize_further: vec![], - ready: msgs - .into_iter() - .map(|mut op| { - UpdateHook::new( - &self.l2_chain_id, - &ClientType::new(ClientType::STATE_LENS_ICS23_ICS23), - |fetch| { - Call::Plugin(PluginMessage::new( - self.plugin_name(), - ModuleCall::from(FetchUpdate { - counterparty_chain_id: fetch.counterparty_chain_id.clone(), - update_from: fetch.update_from, - update_to: fetch.update_to, - }), - )) - }, - ) - .visit_op(&mut op); - - op - }) - .enumerate() - .map(|(i, op)| (vec![i], op)) - .collect(), - }) - } - - #[instrument(skip_all, fields(chain_id = %self.l2_chain_id))] - async fn call(&self, ext: &Extensions, msg: ModuleCall) -> RpcResult> { - match msg { - ModuleCall::FetchUpdate(FetchUpdate { - counterparty_chain_id, - update_from, - update_to, - }) => { - let voy_client = ext.try_get::()?; - let l1_latest_height = voy_client - .query_latest_height(self.l1_chain_id.clone(), true) - .await?; - let l2_consensus_state_proof = serde_json::from_value::( - voy_client - .query_ibc_proof( - self.l1_chain_id.clone(), - QueryHeight::Specific(l1_latest_height), - ConsensusStatePath { - client_id: self.l1_client_id, - height: update_to.height(), - }, - ) - .await - .expect("big trouble") - .proof, - ) - .expect("impossible"); - let l2_merkle_proof = unionlabs::union::ics23::merkle_proof::MerkleProof::try_from( - protos::ibc::core::commitment::v1::MerkleProof::from(l2_consensus_state_proof), - ) - .expect("impossible"); - let continuation = call(PluginMessage::new( - self.plugin_name(), - ModuleCall::from(FetchUpdateAfterL1Update { - counterparty_chain_id, - update_from, - update_to, - }), - )); - // If the L2 consensus proof exists on the L1, we don't have to update the L2 on the L1. - match l2_merkle_proof { - unionlabs::union::ics23::merkle_proof::MerkleProof::Membership(_, _) => { - Ok(continuation) - } - _ => Ok(conc([ - // Update the L2 (tm) client on L1 (union) and then dispatch the continuation - promise( - [call(FetchUpdateHeaders { - client_type: ClientType::new(ClientType::TENDERMINT), - chain_id: self.l2_chain_id.clone(), - counterparty_chain_id: self.l1_chain_id.clone(), - update_from, - update_to, - })], - [], - AggregateMsgUpdateClientsFromOrderedHeaders { - ibc_spec_id: IbcUnion::ID, - chain_id: self.l1_chain_id.clone(), - client_id: RawClientId::new(self.l1_client_id), - }, - ), - seq([ - call(WaitForTrustedHeight { - chain_id: self.l1_chain_id.clone(), - ibc_spec_id: IbcUnion::ID, - client_id: RawClientId::new(self.l1_client_id), - height: update_to, - finalized: true, - }), - continuation, - ]), - ])), - } - } - ModuleCall::FetchUpdateAfterL1Update(FetchUpdateAfterL1Update { - counterparty_chain_id, - .. - }) => { - let voy_client = ext.try_get::()?; - let l1_latest_height = voy_client - .query_latest_height(self.l1_chain_id.clone(), false) - .await?; - debug!("l1 latest height {}", l1_latest_height); - let l0_client_meta = voy_client - .client_meta::( - counterparty_chain_id.clone(), - QueryHeight::Latest, - self.l0_client_id, - ) - .await?; - let l1_client_meta = voy_client - .client_meta::( - self.l1_chain_id.clone(), - QueryHeight::Specific(l1_latest_height), - self.l1_client_id, - ) - .await?; - // The client has been updated to at least update_to - let update_to = l1_client_meta.counterparty_height; - debug!("l0 client meta {:#?}", l0_client_meta); - let l2_consensus_state_path = ConsensusStatePath { - client_id: self.l1_client_id, - height: update_to.height(), - }; - let l2_consensus_state = voy_client - .query_ibc_state( - self.l1_chain_id.clone(), - QueryHeight::Specific(l1_latest_height), - l2_consensus_state_path.clone(), - ) - .await? - .state; - debug!("l2 consensus state {:#?}", l2_consensus_state); - let l2_consensus_state_proof = serde_json::from_value::( - voy_client - .query_ibc_proof( - self.l1_chain_id.clone(), - QueryHeight::Specific(l1_latest_height), - l2_consensus_state_path, - ) - .await - .expect("big trouble") - .proof, - ) - .expect("impossible"); - debug!("l2 consensus state proof {:#?}", l2_consensus_state_proof); - // Dispatch an update for the L1 on the destination, then dispatch the L2 update on the destination - Ok(conc([ - promise( - [call(FetchUpdateHeaders { - client_type: ClientType::new(ClientType::COMETBLS), - chain_id: self.l1_chain_id.clone(), - counterparty_chain_id: counterparty_chain_id.clone(), - update_from: l0_client_meta.counterparty_height, - update_to: l1_latest_height, - })], - [], - AggregateMsgUpdateClientsFromOrderedHeaders { - ibc_spec_id: IbcUnion::ID, - chain_id: counterparty_chain_id.clone(), - client_id: RawClientId::new(self.l0_client_id), - }, - ), - seq([ - call(WaitForTrustedHeight { - chain_id: counterparty_chain_id, - ibc_spec_id: IbcUnion::ID, - client_id: RawClientId::new(self.l0_client_id), - height: l1_latest_height, - finalized: false, - }), - data(OrderedHeaders { - headers: vec![( - DecodedHeaderMeta { height: update_to }, - into_value(Header { - l1_height: l1_latest_height, - l2_height: update_to, - l2_consensus_state_proof, - l2_consensus_state, - }), - )], - }), - ]), - ])) - } - } - } - - #[instrument(skip_all, fields(chain_id = %self.l2_chain_id))] - async fn callback( - &self, - _: &Extensions, - callback: ModuleCallback, - _data: VecDeque, - ) -> RpcResult> { - match callback {} - } -} diff --git a/voyager/plugins/client-update/state-lens/evm/src/call.rs b/voyager/plugins/client-update/state-lens/src/call.rs similarity index 100% rename from voyager/plugins/client-update/state-lens/evm/src/call.rs rename to voyager/plugins/client-update/state-lens/src/call.rs diff --git a/voyager/plugins/client-update/state-lens/evm/src/callback.rs b/voyager/plugins/client-update/state-lens/src/callback.rs similarity index 100% rename from voyager/plugins/client-update/state-lens/evm/src/callback.rs rename to voyager/plugins/client-update/state-lens/src/callback.rs diff --git a/voyager/plugins/client-update/state-lens/evm/src/data.rs b/voyager/plugins/client-update/state-lens/src/data.rs similarity index 100% rename from voyager/plugins/client-update/state-lens/evm/src/data.rs rename to voyager/plugins/client-update/state-lens/src/data.rs diff --git a/voyager/plugins/client-update/state-lens/evm/src/main.rs b/voyager/plugins/client-update/state-lens/src/main.rs similarity index 98% rename from voyager/plugins/client-update/state-lens/evm/src/main.rs rename to voyager/plugins/client-update/state-lens/src/main.rs index c33de122a7..f92d3cc06c 100644 --- a/voyager/plugins/client-update/state-lens/evm/src/main.rs +++ b/voyager/plugins/client-update/state-lens/src/main.rs @@ -260,20 +260,20 @@ impl PluginServer for Module { .expect("big trouble") .proof; - // let state_lens_client_type = voy_client - // .client_info(counterparty_chain_id, l1_client_meta) - // .await?; + let state_lens_client = voy_client + .client_info::(counterparty_chain_id.clone(), self.l0_client_id) + .await?; + + debug!("l2 consensus state proof {:?}", l2_consensus_state_proof); let l2_consensus_state_proof_bytes = voy_client .encode_proof::( self.state_lens_client_type.clone(), - todo!(), + state_lens_client.ibc_interface, l2_consensus_state_proof, ) .await?; - debug!("l2 consensus state proof {:?}", l2_consensus_state_proof); - // Dispatch an update for the L1 on the destination, then dispatch the L2 update on the destination Ok(conc([ promise(