Skip to content

Commit

Permalink
Merge pull request #3 from datachainlab/generic-fork-parameters
Browse files Browse the repository at this point in the history
make fork parameters generic

Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele authored May 11, 2023
2 parents 4842536 + c77de76 commit 0ee8e57
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 59 deletions.
4 changes: 2 additions & 2 deletions crates/ibc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ hex = { version = "0.4.3", default-features = false, features = ["alloc", "serde
ssz-rs = { git = "https://github.com/bluele/ssz_rs", branch = "serde-no-std", default-features = false, features = ["serde"] }

ethereum-ibc-proto = { path = "../../proto", default-features = false }
ethereum-consensus = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "1ac6905ad7020fd377e66e0ac116d41509cca1fe", default-features = false }
ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "1ac6905ad7020fd377e66e0ac116d41509cca1fe", default-features = false }
ethereum-consensus = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "aac304f27372e8a0fb950522ee9cd6f41e43f56f", default-features = false }
ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "aac304f27372e8a0fb950522ee9cd6f41e43f56f", default-features = false }
60 changes: 19 additions & 41 deletions crates/ibc/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{eth_client_type, internal_prelude::*};
use core::time::Duration;
use ethereum_consensus::beacon::{Epoch, Root, Slot, Version};
use ethereum_consensus::context::ChainContext;
use ethereum_consensus::fork::ForkParameters;
use ethereum_consensus::fork::{ForkParameter, ForkParameters};
use ethereum_consensus::preset;
use ethereum_consensus::types::{Address, H256, U64};
use ethereum_ibc_proto::ibc::lightclients::ethereum::v1::{ClientState as RawClientState, Fork};
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<const SYNC_COMMITTEE_SIZE: usize> ClientState<SYNC_COMMITTEE_SIZE> {
.unix_timestamp() as u64,
);
let current_slot = (current_timestamp - self.genesis_time) / self.seconds_per_slot
+ self.fork_parameters.genesis_slot;
+ self.fork_parameters.genesis_slot();
LightClientContext::new(
self.fork_parameters.clone(),
self.seconds_per_slot,
Expand Down Expand Up @@ -549,32 +549,22 @@ impl<const SYNC_COMMITTEE_SIZE: usize> TryFrom<RawClientState>
version
}

let fork_parameters = value.fork_parameters.unwrap();
let raw_fork_parameters = value.fork_parameters.unwrap();
let fork_parameters = ForkParameters::new(
bytes_to_version(raw_fork_parameters.genesis_fork_version),
raw_fork_parameters
.forks
.into_iter()
.map(|f| ForkParameter::new(bytes_to_version(f.version), f.epoch.into()))
.collect(),
);
fork_parameters.validate()?;
let trust_level = value.trust_level.unwrap();
Ok(Self {
genesis_validators_root: H256::from_slice(&value.genesis_validators_root),
min_sync_committee_participants: value.min_sync_committee_participants.into(),
genesis_time: value.genesis_time.into(),
fork_parameters: ForkParameters {
genesis_fork_version: bytes_to_version(fork_parameters.genesis_fork_version),
genesis_slot: fork_parameters.genesis_slot.into(),
altair_fork_version: bytes_to_version(
fork_parameters.altair.clone().unwrap().version,
),
altair_fork_epoch: fork_parameters.altair.unwrap().epoch.into(),
bellatrix_fork_version: bytes_to_version(
fork_parameters.bellatrix.clone().unwrap().version,
),
bellatrix_fork_epoch: fork_parameters.bellatrix.unwrap().epoch.into(),
capella_fork_version: bytes_to_version(
fork_parameters.capella.clone().unwrap().version,
),
capella_fork_epoch: fork_parameters.capella.unwrap().epoch.into(),
eip4844_fork_version: bytes_to_version(
fork_parameters.eip4844.clone().unwrap().version,
),
eip4844_fork_epoch: fork_parameters.eip4844.unwrap().epoch.into(),
},
fork_parameters,
seconds_per_slot: value.seconds_per_slot.into(),
slots_per_epoch: value.slots_per_epoch.into(),
epochs_per_sync_committee_period: value.epochs_per_sync_committee_period.into(),
Expand Down Expand Up @@ -618,24 +608,12 @@ impl<const SYNC_COMMITTEE_SIZE: usize> From<ClientState<SYNC_COMMITTEE_SIZE>> fo
min_sync_committee_participants: value.min_sync_committee_participants.into(),
genesis_time: value.genesis_time.into(),
fork_parameters: Some(ProtoForkParameters {
genesis_fork_version: version_to_bytes(fork_parameters.genesis_fork_version),
genesis_slot: fork_parameters.genesis_slot.into(),
altair: Some(make_fork(
fork_parameters.altair_fork_version,
fork_parameters.altair_fork_epoch,
)),
bellatrix: Some(make_fork(
fork_parameters.bellatrix_fork_version,
fork_parameters.bellatrix_fork_epoch,
)),
capella: Some(make_fork(
fork_parameters.capella_fork_version,
fork_parameters.capella_fork_epoch,
)),
eip4844: Some(make_fork(
fork_parameters.eip4844_fork_version,
fork_parameters.eip4844_fork_epoch,
)),
genesis_fork_version: version_to_bytes(fork_parameters.genesis_version),
forks: fork_parameters
.forks
.into_iter()
.map(|f| make_fork(f.version, f.epoch))
.collect(),
}),
seconds_per_slot: value.seconds_per_slot.into(),
slots_per_epoch: value.slots_per_epoch.into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ message TrustedSyncCommittee {

message ForkParameters {
bytes genesis_fork_version = 1;
uint64 genesis_slot = 2;

Fork altair = 3;
Fork bellatrix = 4;
Fork capella = 5;
Fork eip4844 = 6;
repeated Fork forks = 2;
}

message Fraction {
Expand Down
12 changes: 2 additions & 10 deletions proto/src/prost/ibc.lightclients.ethereum.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,8 @@ pub struct TrustedSyncCommittee {
pub struct ForkParameters {
#[prost(bytes = "vec", tag = "1")]
pub genesis_fork_version: ::prost::alloc::vec::Vec<u8>,
#[prost(uint64, tag = "2")]
pub genesis_slot: u64,
#[prost(message, optional, tag = "3")]
pub altair: ::core::option::Option<Fork>,
#[prost(message, optional, tag = "4")]
pub bellatrix: ::core::option::Option<Fork>,
#[prost(message, optional, tag = "5")]
pub capella: ::core::option::Option<Fork>,
#[prost(message, optional, tag = "6")]
pub eip4844: ::core::option::Option<Fork>,
#[prost(message, repeated, tag = "2")]
pub forks: ::prost::alloc::vec::Vec<Fork>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down

0 comments on commit 0ee8e57

Please sign in to comment.