From e64f13780a8a41ef24c9cd856aea7624eaac45a8 Mon Sep 17 00:00:00 2001 From: benluelo Date: Tue, 30 Apr 2024 14:46:36 -0400 Subject: [PATCH] feat(voyager): query the head of the chain when waiting for trusted height --- dictionary.txt | 1 + .../src/chain_impls/cosmos_sdk.rs | 5 +++-- lib/relay-message/src/chain_impls/ethereum.rs | 6 ++--- lib/relay-message/src/chain_impls/scroll.rs | 15 +++++-------- lib/relay-message/src/data.rs | 7 ++++++ lib/relay-message/src/fetch.rs | 22 +++++++++++++++++++ lib/relay-message/src/lib.rs | 3 +-- lib/relay-message/src/wait.rs | 4 +--- lib/scroll-api/src/lib.rs | 15 +++++++++++++ voyager-config.json | 6 ++--- 10 files changed, 61 insertions(+), 23 deletions(-) diff --git a/dictionary.txt b/dictionary.txt index 52be236109..9e88218679 100644 --- a/dictionary.txt +++ b/dictionary.txt @@ -925,6 +925,7 @@ undelegate undelegations unergonomic unescrow +unfinalized uninit unionbuild unionbundle diff --git a/lib/relay-message/src/chain_impls/cosmos_sdk.rs b/lib/relay-message/src/chain_impls/cosmos_sdk.rs index 440c3c4a5f..d46d2ee171 100644 --- a/lib/relay-message/src/chain_impls/cosmos_sdk.rs +++ b/lib/relay-message/src/chain_impls/cosmos_sdk.rs @@ -247,11 +247,12 @@ where ]) } - async fn query_client_state( + async fn query_unfinalized_trusted_client_state( hc: &Hc, client_id: Hc::ClientId, - height: Hc::Height, ) -> Hc::StoredClientState { + let height = hc.query_latest_height().await.unwrap(); + let QueueMsg::Data(relayer_msg) = fetch_abci_query::( hc, ClientStatePath { client_id }.into(), diff --git a/lib/relay-message/src/chain_impls/ethereum.rs b/lib/relay-message/src/chain_impls/ethereum.rs index fe84ad49ac..2ee7cba5c7 100644 --- a/lib/relay-message/src/chain_impls/ethereum.rs +++ b/lib/relay-message/src/chain_impls/ethereum.rs @@ -392,15 +392,13 @@ where )) } - async fn query_client_state( + async fn query_unfinalized_trusted_client_state( hc: &Self, client_id: Self::ClientId, - height: Self::Height, ) -> Tr::SelfClientState { hc.ibc_handler() .ibc_state_read::<_, Ethereum, Tr>( - hc.execution_height_of_beacon_slot(height.revision_height) - .await, + hc.provider.get_block_number().await.unwrap().as_u64(), ClientStatePath { client_id }, ) .await diff --git a/lib/relay-message/src/chain_impls/scroll.rs b/lib/relay-message/src/chain_impls/scroll.rs index 23fbd5da65..dec1c6503f 100644 --- a/lib/relay-message/src/chain_impls/scroll.rs +++ b/lib/relay-message/src/chain_impls/scroll.rs @@ -18,7 +18,7 @@ use unionlabs::{ encoding::{Decode, Encode, EthAbi}, hash::{H160, H256}, ibc::{ - core::client::{height::IsHeight, msg_update_client::MsgUpdateClient}, + core::client::msg_update_client::MsgUpdateClient, lightclients::{ ethereum::{account_proof::AccountProof, storage_proof::StorageProof}, scroll, @@ -104,17 +104,14 @@ where )) } - async fn query_client_state( + async fn query_unfinalized_trusted_client_state( hc: &Self, client_id: Self::ClientId, - height: Self::Height, - ) -> Tr::SelfClientState { + ) -> Self::StoredClientState { + let latest_scroll_height = hc.provider.get_block_number().await.unwrap().as_u64(); + hc.ibc_handler() - .ibc_state_read::<_, Scroll, Tr>( - hc.execution_height_of_beacon_slot(height.revision_height()) - .await, - ClientStatePath { client_id }, - ) + .ibc_state_read::<_, Scroll, Tr>(latest_scroll_height, ClientStatePath { client_id }) .await .unwrap() } diff --git a/lib/relay-message/src/data.rs b/lib/relay-message/src/data.rs index 8f943ae68e..0cec33ba8e 100644 --- a/lib/relay-message/src/data.rs +++ b/lib/relay-message/src/data.rs @@ -24,6 +24,7 @@ pub enum Data { SelfConsensusState(SelfConsensusState), LatestHeight(LatestHeight), + UnfinalizedClientState(UnfinalizedTrustedClientState), PacketAcknowledgement(PacketAcknowledgement), @@ -84,6 +85,12 @@ pub struct LatestHeight { pub height: HeightOf, } +#[queue_msg] +pub struct UnfinalizedTrustedClientState { + pub height: HeightOf, + pub client_state: Hc::StoredClientState, +} + #[queue_msg] pub struct Header { pub header: HeaderOf, diff --git a/lib/relay-message/src/fetch.rs b/lib/relay-message/src/fetch.rs index b9b0f1f2f1..acf54df7eb 100644 --- a/lib/relay-message/src/fetch.rs +++ b/lib/relay-message/src/fetch.rs @@ -31,6 +31,8 @@ pub enum Fetch { LatestHeight(FetchLatestHeight), + UnfinalizedTrustedClientState(FetchUnfinalizedTrustedClientState), + SelfClientState(FetchSelfClientState), SelfConsensusState(FetchSelfConsensusState), @@ -106,6 +108,11 @@ pub struct FetchUpdateHeaders { #[queue_msg] pub struct FetchLatestHeight<#[cover] Hc: ChainExt, #[cover] Tr: ChainExt> {} +#[queue_msg] +pub struct FetchUnfinalizedTrustedClientState { + client_id: Hc::ClientId, +} + #[queue_msg] pub struct LightClientSpecificFetch(pub Hc::Fetch); @@ -140,6 +147,21 @@ where __marker: PhantomData, }, )), + Fetch::UnfinalizedTrustedClientState(FetchUnfinalizedTrustedClientState { + client_id, + __marker: _, + }) => { + let _client_state = Hc::query_unfinalized_trusted_client_state(&c, client_id).await; + + // data(id( + // c.chain_id(), + // UnfinalizedTrustedClientState { + // height, + // client_state, + // }, + // )) + todo!() + } Fetch::SelfClientState(FetchSelfClientState { at: height, __marker: _, diff --git a/lib/relay-message/src/lib.rs b/lib/relay-message/src/lib.rs index 4f5724cf28..ea30243a1e 100644 --- a/lib/relay-message/src/lib.rs +++ b/lib/relay-message/src/lib.rs @@ -394,10 +394,9 @@ pub trait DoFetchState: ChainExt { fn state(hc: &Hc, at: Hc::Height, path: PathOf) -> QueueMsg; // SEE: - fn query_client_state( + fn query_unfinalized_trusted_client_state( hc: &Hc, client_id: Hc::ClientId, - height: Hc::Height, ) -> impl Future> + '_; } diff --git a/lib/relay-message/src/wait.rs b/lib/relay-message/src/wait.rs index e66012e66f..9e29923b92 100644 --- a/lib/relay-message/src/wait.rs +++ b/lib/relay-message/src/wait.rs @@ -134,10 +134,8 @@ where counterparty_chain_id, height, }) => { - let latest_height = c.query_latest_height_as_destination().await.unwrap(); - let trusted_client_state = - Hc::query_client_state(c, client_id.clone(), latest_height).await; + Hc::query_unfinalized_trusted_client_state(c, client_id.clone()).await; if trusted_client_state.height().revision_height() >= height.revision_height() { tracing::debug!( diff --git a/lib/scroll-api/src/lib.rs b/lib/scroll-api/src/lib.rs index 23284826fc..6210971870 100644 --- a/lib/scroll-api/src/lib.rs +++ b/lib/scroll-api/src/lib.rs @@ -28,6 +28,21 @@ impl ScrollClient { .await .unwrap() } + + // #[instrument(level = "debug", skip(self))] + // pub async fn batches(&self, page: u64, per_page: u64) -> BatchResponse { + // self.client + // .get(format!( + // "{}/api/batches?page={page}&per_page={per_page}", + // self.base_url + // )) + // .send() + // .await + // .unwrap() + // .json() + // .await + // .unwrap() + // } } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] diff --git a/voyager-config.json b/voyager-config.json index 9a17012e15..cea0c2d638 100644 --- a/voyager-config.json +++ b/voyager-config.json @@ -1,7 +1,7 @@ { "chain": { "scroll-testnet": { - "enabled": true, + "enabled": false, "chain_type": "scroll", "ibc_handler_address": "0x915eccda242f8353f901e26466a54e67396653c0", "signers": [ @@ -27,7 +27,7 @@ "union_grpc_url": "https://grpc.testnet.bonlulu.uno:443" }, "ethereum-devnet": { - "enabled": false, + "enabled": true, "chain_type": "ethereum", "preset_base": "minimal", "ibc_handler_address": "0xed2af2ad7fe0d92011b26a2e5d1b4dc7d12a47c5", @@ -53,7 +53,7 @@ }, "union-devnet": { "chain_type": "union", - "enabled": false, + "enabled": true, "signers": [ { "raw": "0xaa820fa947beb242032a41b6dc9a8b9c37d8f5fbcda0966b1ec80335b10a7d6f"