Skip to content

Commit

Permalink
feat(voyager): query the head of the chain when waiting for trusted h…
Browse files Browse the repository at this point in the history
…eight
  • Loading branch information
benluelo committed Apr 30, 2024
1 parent f4b6619 commit e64f137
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 23 deletions.
1 change: 1 addition & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ undelegate
undelegations
unergonomic
unescrow
unfinalized
uninit
unionbuild
unionbundle
Expand Down
5 changes: 3 additions & 2 deletions lib/relay-message/src/chain_impls/cosmos_sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tr> {
let height = hc.query_latest_height().await.unwrap();

let QueueMsg::Data(relayer_msg) = fetch_abci_query::<Hc, Tr>(
hc,
ClientStatePath { client_id }.into(),
Expand Down
6 changes: 2 additions & 4 deletions lib/relay-message/src/chain_impls/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C>, Tr>(
hc.execution_height_of_beacon_slot(height.revision_height)
.await,
hc.provider.get_block_number().await.unwrap().as_u64(),
ClientStatePath { client_id },
)
.await
Expand Down
15 changes: 6 additions & 9 deletions lib/relay-message/src/chain_impls/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Tr> {
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()
}
Expand Down
7 changes: 7 additions & 0 deletions lib/relay-message/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum Data<Hc: ChainExt, Tr: ChainExt> {
SelfConsensusState(SelfConsensusState<Hc, Tr>),

LatestHeight(LatestHeight<Hc, Tr>),
UnfinalizedClientState(UnfinalizedTrustedClientState<Hc, Tr>),

PacketAcknowledgement(PacketAcknowledgement<Hc, Tr>),

Expand Down Expand Up @@ -84,6 +85,12 @@ pub struct LatestHeight<Hc: ChainExt, #[cover] Tr: ChainExt> {
pub height: HeightOf<Hc>,
}

#[queue_msg]
pub struct UnfinalizedTrustedClientState<Hc: ChainExt, Tr: ChainExt> {
pub height: HeightOf<Hc>,
pub client_state: Hc::StoredClientState<Tr>,
}

#[queue_msg]
pub struct Header<Hc: ChainExt, #[cover] Tr: ChainExt> {
pub header: HeaderOf<Hc>,
Expand Down
22 changes: 22 additions & 0 deletions lib/relay-message/src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum Fetch<Hc: ChainExt, Tr: ChainExt> {

LatestHeight(FetchLatestHeight<Hc, Tr>),

UnfinalizedTrustedClientState(FetchUnfinalizedTrustedClientState<Hc, Tr>),

SelfClientState(FetchSelfClientState<Hc, Tr>),
SelfConsensusState(FetchSelfConsensusState<Hc, Tr>),

Expand Down Expand Up @@ -106,6 +108,11 @@ pub struct FetchUpdateHeaders<Hc: ChainExt, Tr: ChainExt> {
#[queue_msg]
pub struct FetchLatestHeight<#[cover] Hc: ChainExt, #[cover] Tr: ChainExt> {}

#[queue_msg]
pub struct FetchUnfinalizedTrustedClientState<Hc: ChainExt, #[cover] Tr: ChainExt> {
client_id: Hc::ClientId,
}

#[queue_msg]
pub struct LightClientSpecificFetch<Hc: ChainExt, Tr: ChainExt>(pub Hc::Fetch<Tr>);

Expand Down Expand Up @@ -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: _,
Expand Down
3 changes: 1 addition & 2 deletions lib/relay-message/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,9 @@ pub trait DoFetchState<Hc: ChainExt, Tr: ChainExt>: ChainExt {
fn state(hc: &Hc, at: Hc::Height, path: PathOf<Hc, Tr>) -> QueueMsg<RelayMessageTypes>;

// SEE: <https://github.com/unionlabs/union/issues/1813>
fn query_client_state(
fn query_unfinalized_trusted_client_state(
hc: &Hc,
client_id: Hc::ClientId,
height: Hc::Height,
) -> impl Future<Output = Hc::StoredClientState<Tr>> + '_;
}

Expand Down
4 changes: 1 addition & 3 deletions lib/relay-message/src/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
15 changes: 15 additions & 0 deletions lib/scroll-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions voyager-config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"chain": {
"scroll-testnet": {
"enabled": true,
"enabled": false,
"chain_type": "scroll",
"ibc_handler_address": "0x915eccda242f8353f901e26466a54e67396653c0",
"signers": [
Expand All @@ -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",
Expand All @@ -53,7 +53,7 @@
},
"union-devnet": {
"chain_type": "union",
"enabled": false,
"enabled": true,
"signers": [
{
"raw": "0xaa820fa947beb242032a41b6dc9a8b9c37d8f5fbcda0966b1ec80335b10a7d6f"
Expand Down

0 comments on commit e64f137

Please sign in to comment.