Skip to content

Commit

Permalink
bump ethereum-ibc-rs to v0.0.14
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Oct 30, 2024
1 parent 7ca39c0 commit 3676589
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 83 deletions.
9 changes: 4 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ displaydoc = { version = "0.2", default-features = false }
tiny-keccak = { version = "1.4" }

light-client = { git = "https://github.com/datachainlab/lcp", rev = "v0.2.11", default-features = false, features = ["ibc"] }
ethereum-ibc = { git = "https://github.com/datachainlab/ethereum-ibc-rs", rev = "v0.0.12", default-features = false }
ethereum-ibc = { git = "https://github.com/datachainlab/ethereum-ibc-rs", rev = "v0.0.14", default-features = false }
54 changes: 22 additions & 32 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,9 @@ use light_client::{
};
use tiny_keccak::Keccak;

pub struct EthereumLightClient<
const SYNC_COMMITTEE_SIZE: usize,
const EXECUTION_PAYLOAD_TREE_DEPTH: usize,
>;

impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize> LightClient
for EthereumLightClient<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>
{
pub struct EthereumLightClient<const SYNC_COMMITTEE_SIZE: usize>;

impl<const SYNC_COMMITTEE_SIZE: usize> LightClient for EthereumLightClient<SYNC_COMMITTEE_SIZE> {
fn client_type(&self) -> String {
eth_client_type().as_str().into()
}
Expand All @@ -47,7 +42,7 @@ impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize
ctx: &dyn HostClientReader,
client_id: &ClientId,
) -> Result<Height, light_client::Error> {
let client_state: ClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH> =
let client_state: ClientState<SYNC_COMMITTEE_SIZE> =
ctx.client_state(client_id)?.try_into()?;
Ok(client_state.latest_height().into())
}
Expand All @@ -58,10 +53,7 @@ impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize
any_client_state: Any,
any_consensus_state: Any,
) -> Result<light_client::CreateClientResult, light_client::Error> {
let client_state =
ClientState::<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>::try_from(
any_client_state.clone(),
)?;
let client_state = ClientState::<SYNC_COMMITTEE_SIZE>::try_from(any_client_state.clone())?;
let consensus_state = ConsensusState::try_from(any_consensus_state)?;
let _ = client_state
.initialise(consensus_state.0.clone().into())
Expand Down Expand Up @@ -181,9 +173,7 @@ impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize
}
}

impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize>
EthereumLightClient<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>
{
impl<const SYNC_COMMITTEE_SIZE: usize> EthereumLightClient<SYNC_COMMITTEE_SIZE> {
fn validate_args(
ctx: &dyn HostClientReader,
client_id: ClientId,
Expand All @@ -193,15 +183,15 @@ impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize
proof: Vec<u8>,
) -> Result<
(
ClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>,
ClientState<SYNC_COMMITTEE_SIZE>,
ConsensusState,
CommitmentPrefix,
Path,
CommitmentProofBytes,
),
light_client::Error,
> {
let client_state: ClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH> =
let client_state: ClientState<SYNC_COMMITTEE_SIZE> =
ctx.client_state(&client_id)?.try_into()?;

if client_state.is_frozen() {
Expand All @@ -227,7 +217,7 @@ impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize
any_message: Any,
header: Header<SYNC_COMMITTEE_SIZE>,
) -> Result<UpdateStateData, light_client::Error> {
let client_state: ClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH> =
let client_state: ClientState<SYNC_COMMITTEE_SIZE> =
ctx.client_state(&client_id)?.try_into()?;

if client_state.is_frozen() {
Expand Down Expand Up @@ -260,7 +250,7 @@ impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize
} = client_state
.check_header_and_update_state(
&IBCContext::<
EthereumClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>,
EthereumClientState<SYNC_COMMITTEE_SIZE>,
EthereumConsensusState,
>::new(ctx),
client_id.into(),
Expand All @@ -273,9 +263,9 @@ impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize
})?;

let new_client_state = ClientState(
downcast_client_state::<
EthereumClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>,
>(new_client_state.as_ref())
downcast_client_state::<EthereumClientState<SYNC_COMMITTEE_SIZE>>(
new_client_state.as_ref(),
)
.unwrap()
.clone(),
);
Expand Down Expand Up @@ -316,7 +306,7 @@ impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize
any_message: Any,
misbehaviour: Misbehaviour<SYNC_COMMITTEE_SIZE>,
) -> Result<MisbehaviourData, light_client::Error> {
let client_state: ClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH> =
let client_state: ClientState<SYNC_COMMITTEE_SIZE> =
ctx.client_state(&client_id)?.try_into()?;

if client_state.is_frozen() {
Expand All @@ -337,10 +327,10 @@ impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize
})?
.try_into()?;

let ibc_ctx = IBCContext::<
EthereumClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>,
EthereumConsensusState,
>::new(ctx);
let ibc_ctx =
IBCContext::<EthereumClientState<SYNC_COMMITTEE_SIZE>, EthereumConsensusState>::new(
ctx,
);

let new_client_state = client_state
.check_misbehaviour_and_update_state(
Expand All @@ -354,9 +344,9 @@ impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize
})
})?;
let new_client_state = ClientState(
downcast_client_state::<
EthereumClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>,
>(new_client_state.as_ref())
downcast_client_state::<EthereumClientState<SYNC_COMMITTEE_SIZE>>(
new_client_state.as_ref(),
)
.unwrap()
.clone(),
);
Expand Down Expand Up @@ -412,7 +402,7 @@ impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize
&self,
ctx: &dyn HostClientReader,
client_id: &ClientId,
client_state: &ClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>,
client_state: &ClientState<SYNC_COMMITTEE_SIZE>,
heights: Vec<Height>,
) -> Result<Vec<PrevState>, light_client::Error> {
let mut prev_states = Vec::new();
Expand Down
26 changes: 2 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use client::EthereumLightClient;
use ethereum_ibc::client_state::ETHEREUM_CLIENT_STATE_TYPE_URL;
use ethereum_ibc::consensus::{bellatrix, deneb};
use light_client::LightClientRegistry;
extern crate alloc;

Expand All @@ -24,34 +23,13 @@ mod internal_prelude {
}
use internal_prelude::*;

pub fn register_implementations<
const SYNC_COMMITTEE_SIZE: usize,
const EXECUTION_PAYLOAD_TREE_DEPTH: usize,
>(
pub fn register_implementations<const SYNC_COMMITTEE_SIZE: usize>(
registry: &mut dyn LightClientRegistry,
) {
registry
.put_light_client(
ETHEREUM_CLIENT_STATE_TYPE_URL.to_string(),
Box::new(EthereumLightClient::<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>),
Box::new(EthereumLightClient::<SYNC_COMMITTEE_SIZE>),
)
.unwrap()
}

/// Register the light client implementations for the bellatrix and capella testnets
pub fn register_bellatrix_implementations<const SYNC_COMMITTEE_SIZE: usize>(
registry: &mut dyn LightClientRegistry,
) {
register_implementations::<SYNC_COMMITTEE_SIZE, { bellatrix::EXECUTION_PAYLOAD_TREE_DEPTH }>(
registry,
);
}

/// Register the light client implementations for the deneb testnet
pub fn register_deneb_implementations<const SYNC_COMMITTEE_SIZE: usize>(
registry: &mut dyn LightClientRegistry,
) {
register_implementations::<SYNC_COMMITTEE_SIZE, { deneb::EXECUTION_PAYLOAD_TREE_DEPTH }>(
registry,
);
}
33 changes: 12 additions & 21 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,19 @@ use light_client::types::proto::google::protobuf::Any as IBCAny;
use light_client::types::Any;

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct ClientState<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize>(
pub(crate) EthereumClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>,
pub struct ClientState<const SYNC_COMMITTEE_SIZE: usize>(
pub(crate) EthereumClientState<SYNC_COMMITTEE_SIZE>,
);

impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize> Deref
for ClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>
{
type Target = EthereumClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>;
impl<const SYNC_COMMITTEE_SIZE: usize> Deref for ClientState<SYNC_COMMITTEE_SIZE> {
type Target = EthereumClientState<SYNC_COMMITTEE_SIZE>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize> TryFrom<Any>
for ClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>
{
impl<const SYNC_COMMITTEE_SIZE: usize> TryFrom<Any> for ClientState<SYNC_COMMITTEE_SIZE> {
type Error = Error;

fn try_from(value: Any) -> Result<Self, Self::Error> {
Expand All @@ -42,10 +38,8 @@ impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize
}
}

impl<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize>
From<ClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>> for Any
{
fn from(value: ClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>) -> Self {
impl<const SYNC_COMMITTEE_SIZE: usize> From<ClientState<SYNC_COMMITTEE_SIZE>> for Any {
fn from(value: ClientState<SYNC_COMMITTEE_SIZE>) -> Self {
IBCAny::from(value.0).into()
}
}
Expand Down Expand Up @@ -84,12 +78,9 @@ impl From<ConsensusState> for Any {

// canonicalize_client_state canonicalizes some fields of specified client state
// target fields: latest_slot, latest_execution_block_number, frozen_height
pub fn canonicalize_client_state<
const SYNC_COMMITTEE_SIZE: usize,
const EXECUTION_PAYLOAD_TREE_DEPTH: usize,
>(
client_state: ClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>,
) -> ClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH> {
pub fn canonicalize_client_state<const SYNC_COMMITTEE_SIZE: usize>(
client_state: ClientState<SYNC_COMMITTEE_SIZE>,
) -> ClientState<SYNC_COMMITTEE_SIZE> {
let mut client_state = client_state.0;
client_state.latest_slot = 0u64.into();
client_state.latest_execution_block_number = 0u64.into();
Expand All @@ -105,8 +96,8 @@ pub fn canonicalize_consensus_state(consensus_state: ConsensusState) -> Consensu
ConsensusState(consensus_state)
}

pub fn gen_state_id<const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize>(
client_state: ClientState<SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH>,
pub fn gen_state_id<const SYNC_COMMITTEE_SIZE: usize>(
client_state: ClientState<SYNC_COMMITTEE_SIZE>,
consensus_state: ConsensusState,
) -> Result<StateID, Error> {
Ok(gen_state_id_from_any(
Expand Down

0 comments on commit 3676589

Please sign in to comment.