Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 33 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
'allocator',
'arithmetic',
'attestation_verifier',
'beacon_node_client',
'benches',
'binary_utils',
'bindings/c',
Expand Down Expand Up @@ -286,6 +287,7 @@ alloy-rlp = '0.3'
anyhow = { version = '1', features = ['backtrace'] }
arc-swap = '1'
assert-json-diff = '2'
async-trait = '0.1'
axum = { version = '0.8' }
axum-extra = { version = '0.12', features = ['typed-header', 'query'] }
base64 = '0.22'
Expand Down Expand Up @@ -480,6 +482,7 @@ zkm-sdk = { git = 'https://github.com/ProjectZKM/Ziren.git', tag = 'v1.2.5' }
allocator = { path = 'allocator' }
arithmetic = { path = 'arithmetic' }
attestation_verifier = { path = 'attestation_verifier' }
beacon_node_client = { path = 'beacon_node_client' }
binary_utils = { path = 'binary_utils' }
block_producer = { path = 'block_producer' }
# Replace the line below with `bls = { path = 'bls', features = ['blst'] }` for `ad_hoc_bench` and other utilities
Expand Down
38 changes: 38 additions & 0 deletions beacon_node_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = 'beacon_node_client'
edition = { workspace = true }
authors = ["Grandine <info@grandine.io>"]

[lints]
workspace = true

[features]
default = ['bls/blst', 'kzg_utils/blst']

[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
bls = { workspace = true }
block_producer = { workspace = true }
eth1_api = { workspace = true }
fork_choice_control = { workspace = true }
futures = { workspace = true }
genesis = { workspace = true }
helper_functions = { workspace = true }
itertools = { workspace = true }
kzg_utils = { workspace = true }
liveness_tracker = { workspace = true }
operation_pools = { workspace = true }
p2p = { workspace = true }
parse-display = { workspace = true }
prometheus_metrics = { workspace = true }
ssz = { workspace = true }
std_ext = { workspace = true }
tokio = { workspace = true }
tokio-stream = { workspace = true }
typenum = { workspace = true }
types = { workspace = true }

[dev-dependencies]
hex-literal = { workspace = true }
test-case = { workspace = true }
68 changes: 68 additions & 0 deletions beacon_node_client/src/ids.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use parse_display::{Display, FromStr};
use types::phase0::primitives::{H256, Slot};

#[derive(Clone, Copy, Display, FromStr)]
#[display(style = "lowercase")]
#[cfg_attr(test, derive(PartialEq, Eq, Debug))]
pub enum StateId {
Head,
Genesis,
Finalized,
Justified,
#[display("{0}")]
Slot(Slot),
#[display("{0:?}")]
Root(H256),
}

#[derive(Clone, Copy, Display, FromStr)]
#[display(style = "lowercase")]
#[cfg_attr(test, derive(PartialEq, Eq, Debug))]
pub enum BlockId {
Head,
Genesis,
Finalized,
#[display("{0}")]
Slot(Slot),
#[display("{0:?}")]
Root(H256),
}

#[cfg(test)]
mod tests {
use hex_literal::hex;
use test_case::test_case;

use super::*;

#[test_case("head", StateId::Head)]
#[test_case("genesis", StateId::Genesis)]
#[test_case("finalized", StateId::Finalized)]
#[test_case("justified", StateId::Justified)]
#[test_case("12", StateId::Slot(12))]
#[test_case(
"0x0000000000000000000000000000000000000000000000000000000000000000",
StateId::Root(H256::zero())
)]
#[test_case(
"0x286a9f59df6017029975682ba803d67efbb9daec7a012c193025a8e6e1e8f22e",
StateId::Root(H256(hex!("286a9f59df6017029975682ba803d67efbb9daec7a012c193025a8e6e1e8f22e")))
)]
fn state_id_string_round_trip(string: &str, state_id: StateId) {
assert_eq!(string.parse(), Ok(state_id));
assert_eq!(state_id.to_string(), string);
}

#[test_case("head", BlockId::Head)]
#[test_case("genesis", BlockId::Genesis)]
#[test_case("finalized", BlockId::Finalized)]
#[test_case("12", BlockId::Slot(12))]
#[test_case(
"0x0000000000000000000000000000000000000000000000000000000000000000",
BlockId::Root(H256::zero())
)]
fn block_id_string_round_trip(string: &str, block_id: BlockId) {
assert_eq!(string.parse(), Ok(block_id));
assert_eq!(block_id.to_string(), string);
}
}
17 changes: 17 additions & 0 deletions beacon_node_client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pub mod ids;
pub mod local;
pub mod traits;
pub mod types;

pub use crate::local::{LocalBeaconClient, LocalConfig};

pub use crate::{
ids::{BlockId, StateId},
traits::{BeaconChainReader, BeaconDutyEndpoints, BeaconEventStream, BeaconPublisher},
types::{
AttesterDuty, BlockEncoding, BlockHeaderSummary, BlockProductionOptions,
BroadcastValidation, CommitteeIndexAndSlot, DutiesResponse, GenesisData,
OwnSyncMessageAggregates, ProposerDuty, ProposerGasLimit, ProposerPreparation,
ProposerRegistrationStatus, SyncCommitteeDuty, SyncingStatus, ValidatorLiveness,
},
};
Loading