Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ethereum-ibc-rs version to v0.1.15 #22

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 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.14", default-features = false }
ethereum-ibc = { git = "https://github.com/datachainlab/ethereum-ibc-rs", rev = "v0.0.15", default-features = false }
37 changes: 5 additions & 32 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use crate::internal_prelude::*;
use crate::message::{ClientMessage, Header, Misbehaviour};
use crate::state::{gen_state_id, ClientState, ConsensusState};
use core::str::FromStr;
use core::time::Duration;
use ethereum_ibc::client_state::ClientState as EthereumClientState;
use ethereum_ibc::consensus::compute::compute_timestamp_at_slot;
use ethereum_ibc::consensus_state::ConsensusState as EthereumConsensusState;
use ethereum_ibc::eth_client_type;
use ethereum_ibc::light_client_verifier::updates::ConsensusUpdate;
use ibc::core::ics02_client::client_state::{
downcast_client_state, ClientState as Ics02ClientState, UpdatedState,
};
Expand Down Expand Up @@ -351,20 +350,6 @@ impl<const SYNC_COMMITTEE_SIZE: usize> EthereumLightClient<SYNC_COMMITTEE_SIZE>
.clone(),
);

let cctx = client_state.build_context(&ibc_ctx);
let (update_0, update_1) = misbehaviour.data.clone().updates();

let update_0_timestamp = Time::from_unix_timestamp_nanos(
compute_timestamp_at_slot(&cctx, update_0.finalized_beacon_header().slot).0 as u128
* 1_000_000_000,
)
.unwrap();
let update_1_timestamp = Time::from_unix_timestamp_nanos(
compute_timestamp_at_slot(&cctx, update_1.finalized_beacon_header().slot).0 as u128
* 1_000_000_000,
)
.unwrap();

Ok(MisbehaviourData {
new_any_client_state: new_client_state.into(),
message: MisbehaviourProxyMessage {
Expand All @@ -374,25 +359,13 @@ impl<const SYNC_COMMITTEE_SIZE: usize> EthereumLightClient<SYNC_COMMITTEE_SIZE>
&client_state,
vec![trusted_height.into()],
)?,
// For misbehaviour, it is acceptable if the header's timestamp points to the future.
context: ValidationContext::TrustingPeriod(TrustingPeriodContext::new(
client_state.trusting_period,
client_state.max_clock_drift,
update_0_timestamp,
Duration::ZERO,
Time::unix_epoch(),
trusted_consensus_state.timestamp.into(),
))
.aggregate(ValidationContext::TrustingPeriod(
TrustingPeriodContext::new(
client_state.trusting_period,
client_state.max_clock_drift,
update_1_timestamp,
trusted_consensus_state.timestamp.into(),
),
))
.map_err(|e| {
Error::ICS02(ClientError::ClientSpecific {
description: e.to_string(),
})
})?,
)),
client_message: Any::from(misbehaviour),
},
})
Expand Down
13 changes: 2 additions & 11 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,22 @@ 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
// target fields: latest_execution_block_number, frozen_height
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();
client_state.frozen_height = None;
ClientState(client_state)
}

// canonicalize_consensus_state canonicalizes some fields of specified consensus state
// target field: next_sync_committee
pub fn canonicalize_consensus_state(consensus_state: ConsensusState) -> ConsensusState {
let mut consensus_state = consensus_state.0;
consensus_state.next_sync_committee = None;
ConsensusState(consensus_state)
}

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(
&canonicalize_client_state(client_state).into(),
&canonicalize_consensus_state(consensus_state).into(),
&consensus_state.into(),
)?)
}
Loading