From 3602a61ec258e84641971308a3795cf75eca7887 Mon Sep 17 00:00:00 2001 From: varun-doshi Date: Fri, 13 Dec 2024 16:09:23 +0530 Subject: [PATCH] resolved comments + added containers --- Cargo.lock | 10 ++++++++++ Cargo.toml | 3 ++- crates/common/Cargo.toml | 3 ++- crates/common/src/lib.rs | 1 + crates/common/src/phase0/constants.rs | 15 ++++++--------- crates/common/src/phase0/containers.rs | 23 +++++++++++++++++++++++ crates/common/src/phase0/primitives.rs | 14 ++++++++++++-- 7 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 crates/common/src/phase0/containers.rs diff --git a/Cargo.lock b/Cargo.lock index 3310354..749ef50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -307,6 +307,9 @@ name = "bytes" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" +dependencies = [ + "serde", +] [[package]] name = "cc" @@ -640,6 +643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" dependencies = [ "foldhash", + "serde", ] [[package]] @@ -653,6 +657,9 @@ name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +dependencies = [ + "serde", +] [[package]] name = "hex-literal" @@ -697,6 +704,7 @@ checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" dependencies = [ "equivalent", "hashbrown", + "serde", ] [[package]] @@ -958,6 +966,7 @@ dependencies = [ "libc", "rand_chacha", "rand_core", + "serde", ] [[package]] @@ -1000,6 +1009,7 @@ name = "ream-common" version = "0.1.0" dependencies = [ "alloy-primitives", + "serde", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 0bede60..2e6ca25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,4 +24,5 @@ version = "0.1.0" [workspace.dependencies] clap = "4" -alloy-primitives = "0.8.15" \ No newline at end of file +alloy-primitives ={version = "0.8.15", features = ['serde']} +serde = { version = '1.0.216', features = ['derive'] } diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index d4da6d8..e62b8ef 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -10,4 +10,5 @@ rust-version.workspace = true version.workspace = true [dependencies] -alloy-primitives = {workspace = true} \ No newline at end of file +alloy-primitives.workspace = true +serde.workspace = true diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index 06a2a26..5028100 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -1,4 +1,5 @@ pub mod phase0 { pub mod constants; pub mod primitives; + pub mod containers; } diff --git a/crates/common/src/phase0/constants.rs b/crates/common/src/phase0/constants.rs index 1980a4b..be49aa8 100644 --- a/crates/common/src/phase0/constants.rs +++ b/crates/common/src/phase0/constants.rs @@ -1,4 +1,4 @@ -use alloy_primitives::{aliases::B32,FixedBytes}; +use alloy_primitives::{FixedBytes, aliases::B32}; pub const NODE_ID_BITS: u16 = 256; pub const GOSSIP_MAX_SIZE: u32 = 10_485_760; @@ -11,11 +11,8 @@ pub const ATTESTATION_PROPAGATION_SLOT_RANGE: u8 = 32; pub const MAXIMUM_GOSSIP_CLOCK_DISPARITY: u16 = 500; pub const MESSAGE_DOMAIN_INVALID_SNAPPY: B32 = FixedBytes([0x00, 0x00, 0x00, 0x00]); pub const MESSAGE_DOMAIN_VALID_SNAPPY: B32 = FixedBytes([0x10, 0x00, 0x00, 0x00]); -pub const SUBNETS_PER_NODE:u8=2; -pub const ATTESTATION_SUBNET_COUNT:u8=64; -pub const ATTESTATION_SUBNET_EXTRA_BITS:u8=0; -// ATTESTATION_SUBNET_PREFIX_BITS -pub const MAX_CONCURRENT_REQUESTS:u8=2; - - - +pub const SUBNETS_PER_NODE: u8 = 2; +pub const ATTESTATION_SUBNET_COUNT: u8 = 64; +pub const ATTESTATION_SUBNET_EXTRA_BITS: u8 = 0; +// ATTESTATION_SUBNET_PREFIX_BITS +pub const MAX_CONCURRENT_REQUESTS: u8 = 2; diff --git a/crates/common/src/phase0/containers.rs b/crates/common/src/phase0/containers.rs new file mode 100644 index 0000000..e0ff632 --- /dev/null +++ b/crates/common/src/phase0/containers.rs @@ -0,0 +1,23 @@ +use alloy_primitives::B256; +use serde::{Deserialize, Serialize}; + +use crate::phase0::primitives::{Epoch, Version}; + +#[derive(Clone, Copy, PartialEq, Eq, Default, Debug, Deserialize, Serialize)] +pub struct Fork { + pub previous_version: Version, + pub current_version: Version, + pub epoch: Epoch, +} + +#[derive(Clone, Copy, PartialEq, Eq, Default, Debug, Deserialize, Serialize)] +pub struct ForkData { + pub curent_version: Version, + pub genesis_validators: B256, +} + +#[derive(Clone, Copy, PartialEq, Eq, Default, Debug, Deserialize, Serialize)] +pub struct Checkpoint { + pub epock: Epoch, + pub root: B256, +} diff --git a/crates/common/src/phase0/primitives.rs b/crates/common/src/phase0/primitives.rs index 4ae1364..184d271 100644 --- a/crates/common/src/phase0/primitives.rs +++ b/crates/common/src/phase0/primitives.rs @@ -1,4 +1,14 @@ -use alloy_primitives::{U256,U64}; +use alloy_primitives::{U256, U64,aliases::B32}; +pub type CommiteeIndex = u64; //commitee index at a slot +pub type Domain = B32; //signature Domain +pub type DomainType = B32; // Domain type +pub type Epoch = u64; //epoch number +pub type ForkDigest = B32; //digest of current fork data +pub type Gwei = u64; //amount in gwei pub type NodeID = U256; //Node Idnetifier -pub type SubnetID=U64; //Subnet Identifier \ No newline at end of file +pub type Slot = u64; //slot number +pub type SubnetID = U64; //Subnet Identifier +pub type ValidatorIndex = u64; //validator registry index +pub type Version = B32; //fork version number +