From e14ac65eb03b9a7d10bf33043f288c065e4a0ab1 Mon Sep 17 00:00:00 2001 From: Ben Luelo Date: Wed, 30 Aug 2023 11:01:29 -0400 Subject: [PATCH] feat: `LightClient::UpdateClientMessage` -> `Chain::Header` also a bit of cleanup I noticed as I was going through the code --- Cargo.lock | 2 +- .../lightclients/ethereum/execution_payload_header.rs | 2 -- .../ibc/lightclients/ethereum/light_client_update.rs | 2 +- voyager/src/chain.rs | 6 +++--- voyager/src/chain/cosmos.rs | 10 +++++----- voyager/src/chain/evm.rs | 9 ++++----- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 09e6fb6aec..f224636219 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3451,7 +3451,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.29", ] [[package]] diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/execution_payload_header.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/execution_payload_header.rs index 568d35bd2b..4b7bd6e217 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/execution_payload_header.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/execution_payload_header.rs @@ -13,7 +13,6 @@ use crate::{ #[derive(Clone, Debug, PartialEq, Encode, Decode, TreeHash, Serialize, Deserialize)] #[serde(bound(serialize = "", deserialize = ""))] -// REVIEW: Do we want to use primitive_types here? pub struct ExecutionPayloadHeader { pub parent_hash: H256, pub fee_recipient: Address, @@ -128,7 +127,6 @@ impl .extra_data .try_into() .map_err(TryFromExecutionPayloadHeaderError::ExtraData)?, - // .into_iter().rev().collect::>() base_fee_per_gas: U256::from_little_endian( &<[u8; 32]>::try_from(value.base_fee_per_gas) .map_err(TryFromExecutionPayloadHeaderError::BaseFeePerGas)?, diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/light_client_update.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/light_client_update.rs index 41a4b67e06..539a25b677 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/light_client_update.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/light_client_update.rs @@ -26,7 +26,7 @@ pub struct LightClientUpdate, /// Next sync committee corresponding to `attested_header.state_root` // TODO: Merge these fields into one - #[serde(default = "Option::default")] + #[serde(default)] pub next_sync_committee: Option>, #[serde(default)] pub next_sync_committee_branch: Option, diff --git a/voyager/src/chain.rs b/voyager/src/chain.rs index d3ec31ec5b..c090eb5c2c 100644 --- a/voyager/src/chain.rs +++ b/voyager/src/chain.rs @@ -77,8 +77,6 @@ pub enum AnyLightClient { /// The IBC interface on a [`Chain`] that knows how to connect to a counterparty. pub trait LightClient: Send + Sync + Sized { - type UpdateClientMessage; - /// The chain that this light client is on. type HostChain: Chain; @@ -94,7 +92,7 @@ pub trait LightClient: Send + Sync + Sized { fn update_client( &self, client_id: String, - _: Self::UpdateClientMessage, + header: HeaderOf, ) -> impl Future + '_; // TODO: Use state_proof instead @@ -108,12 +106,14 @@ pub trait LightClient: Send + Sync + Sized { pub type ClientStateOf = ::SelfClientState; pub type ConsensusStateOf = ::SelfConsensusState; +pub type HeaderOf = ::Header; /// Represents a block chain. One [`Chain`] may have many related [`LightClient`]s for connecting to /// various other [`Chain`]s, all sharing a common config. pub trait Chain { type SelfClientState: ClientState + Debug + Serialize; type SelfConsensusState: Debug + Serialize; + type Header; fn chain_id(&self) -> impl Future + '_; diff --git a/voyager/src/chain/cosmos.rs b/voyager/src/chain/cosmos.rs index fde86b62bd..fec14844ba 100644 --- a/voyager/src/chain/cosmos.rs +++ b/voyager/src/chain/cosmos.rs @@ -47,7 +47,7 @@ use unionlabs::{ }, }, google::protobuf::{any::Any, duration::Duration, timestamp::Timestamp}, - lightclients::{cometbls, ethereum, tendermint::fraction::Fraction, wasm}, + lightclients::{cometbls, tendermint::fraction::Fraction, wasm}, }, tendermint::{ abci::{event::Event, event_attribute::EventAttribute}, @@ -73,7 +73,7 @@ use crate::{ ChannelEndPath, ClientConsensusStatePath, ClientStatePath, CommitmentPath, ConnectionPath, IbcPath, StateProof, }, - Chain, ChainConnection, ClientStateOf, Connect, ConsensusStateOf, CreateClient, + Chain, ChainConnection, ClientStateOf, Connect, ConsensusStateOf, CreateClient, HeaderOf, IbcStateRead, LightClient, }, config::UnionChainConfig, @@ -306,6 +306,8 @@ impl Chain for Union { type SelfConsensusState = Any>; + type Header = cometbls::header::Header; + fn chain_id(&self) -> impl Future + '_ { async move { self.chain_id.clone() } } @@ -582,8 +584,6 @@ impl Chain for Union { } impl LightClient for Ethereum { - type UpdateClientMessage = wasm::header::Header>; - type HostChain = Union; type CounterpartyChain = Evm; @@ -597,7 +597,7 @@ impl LightClient for Ethereum { fn update_client( &self, client_id: String, - msg: Self::UpdateClientMessage, + msg: HeaderOf, ) -> impl Future + '_ { self.send_msg_and_read_event(MsgUpdateClient { client_id, diff --git a/voyager/src/chain/evm.rs b/voyager/src/chain/evm.rs index 3235f4d290..95e017222b 100644 --- a/voyager/src/chain/evm.rs +++ b/voyager/src/chain/evm.rs @@ -59,7 +59,6 @@ use unionlabs::{ }, google::protobuf::any::Any, lightclients::{ - cometbls, ethereum::{ self, account_update::AccountUpdate, @@ -86,7 +85,7 @@ use crate::{ ChannelEndPath, ClientConsensusStatePath, ClientStatePath, CommitmentPath, ConnectionPath, IbcPath, }, - Chain, ChainConnection, ClientStateOf, Connect, ConsensusStateOf, CreateClient, + Chain, ChainConnection, ClientStateOf, Connect, ConsensusStateOf, CreateClient, HeaderOf, IbcStateRead, LightClient, StateProof, }, config::EvmChainConfigFields, @@ -386,6 +385,8 @@ impl Chain for Evm { type SelfConsensusState = Any>; + type Header = wasm::header::Header>; + fn chain_id(&self) -> impl Future + '_ { // TODO: Cache this in `self`, it only needs to be fetched once async move { self.provider.get_chainid().await.unwrap().to_string() } @@ -652,8 +653,6 @@ impl CreateClient> for Evm { } impl LightClient for Cometbls { - type UpdateClientMessage = cometbls::header::Header; - type HostChain = Evm; type CounterpartyChain = Union; @@ -667,7 +666,7 @@ impl LightClient for Cometbls { fn update_client( &self, client_id: String, - msg: Self::UpdateClientMessage, + msg: HeaderOf, ) -> impl Future + '_ { async move { let tx_rcp = self