Skip to content
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
9 changes: 5 additions & 4 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 @@ -45,6 +45,7 @@ prost-build = "0.14"
prost-types = "0.14"
rand = { version = "0.8", features = ["std_rng"] }
rand_core = "0.6"
regex = "1.12"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
thiserror = "2.0"
Expand All @@ -59,7 +60,6 @@ base64 = "0.22"
sha3 = "0.10"
k256 = { version = "0.13.4", features = ["ecdsa", "sha256"] }
criterion = "0.8.0"
regex = "1.12"
reqwest = "0.13"
http = "1.4"
tempfile = "3.24"
Expand Down
1 change: 1 addition & 0 deletions crates/charon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ tokio.workspace = true
tokio-util.workspace = true
prost.workspace = true
prost-types.workspace = true
regex.workspace = true
thiserror.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions crates/charon/src/eth2wrap/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// Validate Beacon Node versions
pub mod version;
155 changes: 155 additions & 0 deletions crates/charon/src/eth2wrap/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
use charon_core::version::{self};
use std::sync::LazyLock;
use tracing::warn;

type Result<T> = std::result::Result<T, BeaconNodeVersionError>;

#[derive(Debug, PartialEq, Eq, thiserror::Error)]
enum BeaconNodeVersionError {
#[error("Version string has an unexpected format")]
InvalidFormat,

#[error("Unknown beacon node client")]
UnknownClient,

#[error("Beacon node client version is too old")]
TooOld {
client: version::SemVer,
minimum: version::SemVer,
},
}

static MINIMUM_BEACON_NODE_VERSIONS: LazyLock<std::collections::HashMap<&str, version::SemVer>> =
LazyLock::new(|| {
#[allow(clippy::unwrap_used, reason = "literals should be valid semver")]
std::collections::HashMap::from([
("lighthouse", version::SemVer::parse("v8.0.0-rc.0").unwrap()),
Comment thread
emlautarom1 marked this conversation as resolved.
("teku", version::SemVer::parse("v25.9.3").unwrap()),
("lodestar", version::SemVer::parse("v1.35.0-rc.1").unwrap()),
Comment thread
emlautarom1 marked this conversation as resolved.
("nimbus", version::SemVer::parse("v25.9.2").unwrap()),
("prysm", version::SemVer::parse("v6.1.0").unwrap()),
("grandine", version::SemVer::parse("v2.0.0-rc0").unwrap()),
])
});

static VERSION_EXTRACT_REGEX: LazyLock<regex::Regex> = LazyLock::new(|| {
regex::Regex::new(r"^([^/]+)/v?([0-9]+\.[0-9]+\.[0-9]+)").expect("invalid regex")
});

fn check_beacon_node_version_status(bn_version: &str) -> Result<()> {
let matches = VERSION_EXTRACT_REGEX
.captures(bn_version)
.ok_or(BeaconNodeVersionError::InvalidFormat)?;

if matches.len() != 3 {
return Err(BeaconNodeVersionError::InvalidFormat);
}

let client = version::SemVer::parse(format!("v{}", &matches[2]))
.map_err(|_| BeaconNodeVersionError::InvalidFormat)?;

let name = &matches[1];
let minimum = MINIMUM_BEACON_NODE_VERSIONS
.get(&name.to_lowercase().as_str())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: golang implementation is case sensitive

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, but I think it's safe to use lowercase everywhere (could be an issue on their side).

.ok_or(BeaconNodeVersionError::UnknownClient)?
.clone();

if client < minimum {
return Err(BeaconNodeVersionError::TooOld { client, minimum });
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bad version checking: https://github.com/ObolNetwork/charon/blob/main/app/eth2wrap/version.go#L70-L74

But when i searched the golang implementation, it seems there are no places modify this map. Do we want to add that implementation here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not include it since - as you mention - there is no way at runtime to modify this map, and currently it's empty, so in practice is essentially dead code.

Ok(())
}

/// Checks the version of the beacon node client and logs a warning if the
/// version is below the minimum or if the client is not recognized.
pub fn check_beacon_node_version(bn_version: &str) {
match check_beacon_node_version_status(bn_version) {
Err(BeaconNodeVersionError::InvalidFormat) => {
warn!(
input = bn_version,
"Failed to parse beacon node version string due to unexpected format"
);
}
Err(BeaconNodeVersionError::UnknownClient) => {
warn!(
client = bn_version,
"Unknown beacon node client not in supported client list"
);
}
Err(BeaconNodeVersionError::TooOld { client, minimum }) => {
warn!(
client_version = %client,
minimum_required = %minimum,
"Beacon node client version is below the minimum supported version. Please upgrade your beacon node."
);
}
Ok(()) => { /* Do nothing */ }
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn check_beacon_node_version_status() {
let tc = vec![
// Teku
(
"teku/v25.9.3/linux-x86_64/-eclipseadoptium-openjdk64bitservervm-java-21",
Ok(()),
),
(
"teku/vUNKNOWN+g40561a9/linux-x86_64/-eclipseadoptium-openjdk64bitservervm-java-21",
Err(BeaconNodeVersionError::InvalidFormat),
),
// Lighthouse
("Lighthouse/v8.0.1-e42406d/x86_64-linux", Ok(())),
("Lighthouse/v8.0.0-54f7bc5/aarch64-linux", Ok(())),
// Lodestar
("Lodestar/v1.35.0/8335180", Ok(())),
("Lodestar/v1.36.0/1a34f98", Ok(())),
// Nimbus
("Nimbus/v26.4.1-77cfa7-stateofus", Ok(())),
("Nimbus/v26.5.0-d2f233-stateofus", Ok(())),
(
"Nimbus/v25.9.0-c7e5ca-stateofus",
Err(BeaconNodeVersionError::TooOld {
client: version::SemVer::parse("v25.9.0").unwrap(),
minimum: version::SemVer::parse("v25.9.2").unwrap(),
}),
),
// Prysm
(
"Prysm/v5.3.2 (linux amd64)",
Err(BeaconNodeVersionError::TooOld {
client: version::SemVer::parse("v5.3.2").unwrap(),
minimum: version::SemVer::parse("v6.1.0").unwrap(),
}),
),
("Prysm/v6.1.2 (linux amd64)", Ok(())),
("Prysm/v6.2.0 (linux amd64)", Ok(())),
// Grandine
("Grandine/2.1.0-29cb5c1/x86_64-linux2025-05-19", Ok(())),
// Additional error cases
("", Err(BeaconNodeVersionError::InvalidFormat)),
("justastring", Err(BeaconNodeVersionError::InvalidFormat)),
("/v7.0.0", Err(BeaconNodeVersionError::InvalidFormat)),
(
"UnknownClient/v7.0.0",
Err(BeaconNodeVersionError::UnknownClient),
),
("Lighthouse/", Err(BeaconNodeVersionError::InvalidFormat)),
(
"Lighthouse/vBAD",
Err(BeaconNodeVersionError::InvalidFormat),
),
];

for (input, expected) in tc {
let result = super::check_beacon_node_version_status(input);
assert_eq!(result, expected, "input = {input}");
}
}
}
5 changes: 4 additions & 1 deletion crates/charon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ pub mod retry;
/// Deadline
pub mod deadline;

/// Ethereum EL RPC client management
/// Ethereum EL RPC client management.
pub mod eth1wrap;

/// Featureset defines a set of global features and their rollout status.
pub mod featureset;

/// Obol API client for interacting with the Obol network API.
pub mod obolapi;

/// Ethereum CL RPC client management.
pub mod eth2wrap;
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
chmod +x .githooks/* && git config --local core.hooksPath .githooks/
'';

RUSTC_BOOTSTRAP = "1";
Comment thread
emlautarom1 marked this conversation as resolved.
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ pkgs.openssl ];
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
};
Expand Down