Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
93090fd
Initial `eth2wrap` module
emlautarom1 Jan 8, 2026
dfb913e
Add initial `version`
emlautarom1 Jan 8, 2026
97c021a
Add tests
emlautarom1 Jan 8, 2026
68c9c5e
Merge remote-tracking branch 'origin/main' into emlautarom1/eth2wrap
emlautarom1 Jan 14, 2026
0ee9636
Use `SemVer::parse` instead of `SemVer::try_from` for version parsing
emlautarom1 Jan 14, 2026
af04659
Replace function with static HashMap
emlautarom1 Jan 14, 2026
ccc41f1
Fix clippy lint errors
emlautarom1 Jan 14, 2026
894c9ba
Add `RUSTC_BOOTSTRAP`
emlautarom1 Jan 14, 2026
1d86e58
Prefer `&str` for `TryFrom`
emlautarom1 Jan 14, 2026
6340f89
Add `eth2api` and `anyhow` as deps
emlautarom1 Jan 14, 2026
c1ad4a2
Add `valcache` as module
emlautarom1 Jan 14, 2026
26a4396
Add `eth2api` extensions module
emlautarom1 Jan 14, 2026
b29fae6
Implement `get_by_head`
emlautarom1 Jan 14, 2026
54fb1f8
Add `get_by_slot`
emlautarom1 Jan 14, 2026
aece934
Extract common mapping code
emlautarom1 Jan 14, 2026
5b0cded
Reduce the scope of locks
emlautarom1 Jan 14, 2026
b4d835e
Apply suggestions
emlautarom1 Jan 14, 2026
e8e0de3
Update docs
emlautarom1 Jan 14, 2026
3e6bac4
Use raw Validator type
emlautarom1 Jan 14, 2026
6945e50
Apply clippy suggestions
emlautarom1 Jan 14, 2026
49df66e
Update docs
emlautarom1 Jan 14, 2026
5aff58e
Update lockfile
emlautarom1 Jan 15, 2026
edc0564
Include `Serialize` for all types
emlautarom1 Jan 15, 2026
4e8ec65
Initial test for `valcache`
emlautarom1 Jan 15, 2026
5f39a57
Add test for failing request
emlautarom1 Jan 15, 2026
ab5ae96
Test cache population
emlautarom1 Jan 15, 2026
1ef1f74
Test for cache population
emlautarom1 Jan 15, 2026
01a932f
Port `validator_cache` test
emlautarom1 Jan 15, 2026
e8d1725
Remove tests
emlautarom1 Jan 15, 2026
b3070eb
Add `get_by_slot_successful_fetch`
emlautarom1 Jan 15, 2026
1bac052
Refactor
emlautarom1 Jan 15, 2026
514a276
Add `get_by_slot_fallback_to_head`
emlautarom1 Jan 15, 2026
4a16327
Update lockfile
emlautarom1 Jan 15, 2026
77bff8f
Apply Slippy suggestions
emlautarom1 Jan 15, 2026
9e0778c
Apply Copilot suggestions
emlautarom1 Jan 15, 2026
95bc72b
Use tokio mutex
emlautarom1 Jan 15, 2026
fcfcfaa
Use `tokio::sync::RwLock` instead
emlautarom1 Jan 21, 2026
cf213ac
Merge remote-tracking branch 'origin/main' into emlautarom1/eth2wrap/…
emlautarom1 Jan 21, 2026
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
53 changes: 53 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ members = [
"crates/tracing",
"crates/peerinfo",
"crates/eth2api",
"crates/relay-server"
"crates/relay-server",
]
resolver = "3"

Expand Down Expand Up @@ -72,6 +72,7 @@ oas3-gen-support = "0.24"
bon = "3.8"
testcontainers = "0.26"
vise = "0.3"
wiremock = "0.6"

# Crates in the workspace
charon = { path = "crates/charon" }
Expand Down
10 changes: 5 additions & 5 deletions crates/charon-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ impl Serialize for PubKey {
}
}

impl TryFrom<String> for PubKey {
impl TryFrom<&str> for PubKey {
type Error = PubKeyError;

fn try_from(value: String) -> Result<Self, Self::Error> {
let value = value.strip_prefix("0x").unwrap_or(&value);
fn try_from(value: &str) -> Result<Self, Self::Error> {
let value = value.strip_prefix("0x").unwrap_or(value);
let hex_value = hex::decode(value).map_err(|_| PubKeyError::InvalidString)?;
PubKey::try_from(hex_value.as_slice())
}
Expand Down Expand Up @@ -890,7 +890,7 @@ mod tests {
#[test]
fn test_pub_key_from_string() {
let pk_str = "0x7f790ba343adf8891fac21a94b02d6ca93d0bc2199a5ec083ff6676e8c2f9f78b08bb122f1093675f9d24c8b5e7af241".to_string();
let pk = PubKey::try_from(pk_str).unwrap();
let pk = PubKey::try_from(pk_str.as_str()).unwrap();
assert_eq!(
pk,
PubKey::new([
Expand All @@ -904,7 +904,7 @@ mod tests {
#[test]
fn test_pub_key_from_string_invalid_length() {
let pk_str = "0x7f790ba343adf8891fac21a94b02d6ca93d0bc2199a5ec083ff6676e8c2f9f78b08bb121093675f9d24c8b5e7af241".to_string();
let result = PubKey::try_from(pk_str);
let result = PubKey::try_from(pk_str.as_str());
assert!(result.is_err());
}
}
6 changes: 5 additions & 1 deletion crates/charon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ backon.workspace = true
chrono.workspace = true
charon-core.workspace = true
charon-tracing.workspace = true
eth2api.workspace = true
anyhow.workspace = true
tokio.workspace = true
tokio-util.workspace = true
prost.workspace = true
Expand All @@ -30,10 +32,12 @@ bon.workspace = true
charon-cluster = { workspace = true }
charon-k1util = { workspace = true }
charon-crypto = { workspace = true }
eth2api = { workspace = true }

[build-dependencies]
charon-build-proto.workspace = true

[dev-dependencies]
wiremock.workspace = true

[lints]
workspace = true
38 changes: 38 additions & 0 deletions crates/charon/src/eth2wrap/eth2api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use eth2api::ValidatorStatus;

/// Error that can occur when using the [`eth2api::EthBeaconNodeApiClient`].
#[derive(Debug, thiserror::Error)]
pub enum EthBeaconNodeApiClientError {
/// Underlying error from [`eth2api::EthBeaconNodeApiClient`] when making a
/// request.
#[error("Request error: {0}")]
RequestError(#[from] anyhow::Error),

/// Unexpected response, e.g, got an error when an Ok response was expected
#[error("Unexpected response")]
UnexpectedResponse,

/// Unexpected type in response
#[error("Unexpected type in response")]
UnexpectedType,
}

/// Type alias for validator index.
pub type ValidatorIndex = u64;

/// Extension methods on [`ValidatorStatus`].
pub trait ValidatorStatusExt {
/// Returns true if the validator is in one of the active states.
fn is_active(&self) -> bool;
}

impl ValidatorStatusExt for ValidatorStatus {
fn is_active(&self) -> bool {
matches!(
self,
ValidatorStatus::ActiveOngoing
| ValidatorStatus::ActiveExiting
| ValidatorStatus::ActiveSlashed
)
}
}
11 changes: 10 additions & 1 deletion crates/charon/src/eth2wrap/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
/// Validate Beacon Node versions
/// Validate Beacon node versions
pub mod version;

/// Cache of Validators retrieved from the Beacon node
pub mod valcache;

/// Extensions module to the Eth2Api crate
///
/// Includes additional data types and functions to reduce the boilerplate when
/// interacting with `eth2api`.
pub mod eth2api;
Loading