Skip to content

Commit

Permalink
Merge pull request #573 from chainbound/feat/sidecar-version
Browse files Browse the repository at this point in the history
feat(sidecar): add git commit hash to version tag
  • Loading branch information
merklefruit authored Dec 16, 2024
2 parents 5449ae4 + cec242c commit ca7c8e9
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 24 deletions.
48 changes: 48 additions & 0 deletions bolt-sidecar/Cargo.lock

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

8 changes: 5 additions & 3 deletions bolt-sidecar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,15 @@ thiserror = "2.0"
rand = "0.8.5"
dotenvy = "0.15.7"
regex = "1.10.5"
lazy_static = "1.5.0"

# tracing
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "fmt"] }

# telemetry
metrics = "0.23"
metrics-exporter-prometheus = { version = "0.15.3", features = [
"http-listener",
] }
metrics-exporter-prometheus = { version = "0.15.3", features = ["http-listener"] }

# commit-boost
commit-boost = { git = "https://github.com/Commit-Boost/commit-boost-client", rev = "0f8f69b" }
Expand All @@ -84,6 +83,9 @@ cb-common = { git = "https://github.com/Commit-Boost/commit-boost-client", rev =
alloy-node-bindings = "0.8.0" # must match alloy version
criterion = { version = "0.5", features = ["html_reports"] }

[build-dependencies]
built = { version = "0.7.5", features = ["git2"] }

[package.metadata.cargo-machete]
ignored = ["ethereum_ssz"]

Expand Down
5 changes: 4 additions & 1 deletion bolt-sidecar/bin/sidecar.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use eyre::bail;
use tracing::info;

use bolt_sidecar::{config::Opts, telemetry::init_telemetry_stack, SidecarDriver};
use bolt_sidecar::{
common::BOLT_SIDECAR_VERSION, config::Opts, telemetry::init_telemetry_stack, SidecarDriver,
};

const BOLT: &str = r#"
██████╗ ██████╗ ██╗ ████████╗
Expand All @@ -14,6 +16,7 @@ const BOLT: &str = r#"
#[tokio::main]
async fn main() -> eyre::Result<()> {
println!("{}", BOLT);
println!("Running version: {}", BOLT_SIDECAR_VERSION.clone());

let opts = Opts::try_parse()?;

Expand Down
3 changes: 3 additions & 0 deletions bolt-sidecar/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
built::write_built_file().expect("Failed to acquire build-time information");
}
15 changes: 6 additions & 9 deletions bolt-sidecar/src/api/commitments/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tracing::{debug, error, info, instrument};

use crate::{
api::commitments::headers::auth_from_headers,
common::CARGO_PKG_VERSION,
common::BOLT_SIDECAR_VERSION,
primitives::{commitment::SignatureError, InclusionRequest},
};

Expand All @@ -36,14 +36,11 @@ pub async fn rpc_entrypoint(
debug!("Received new request");

match payload.method.as_str() {
GET_VERSION_METHOD => {
let version_string = format!("bolt-sidecar-v{CARGO_PKG_VERSION}");
Ok(Json(JsonResponse {
id: payload.id,
result: Value::String(version_string),
..Default::default()
}))
}
GET_VERSION_METHOD => Ok(Json(JsonResponse {
id: payload.id,
result: Value::String(BOLT_SIDECAR_VERSION.clone()),
..Default::default()
})),

GET_METADATA_METHOD => {
let response = JsonResponse {
Expand Down
23 changes: 14 additions & 9 deletions bolt-sidecar/src/client/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ use alloy_transport_http::{
AuthLayer, AuthService, HyperClient,
};
use http_body_util::Full;
use lazy_static::lazy_static;
use reqwest::Url;
use tower::ServiceBuilder;

use crate::common::BOLT_SIDECAR_VERSION;

/// A Hyper HTTP client with a JWT authentication layer.
type HyperAuthClient<B = Full<Bytes>> = HyperClient<B, AuthService<Client<HttpConnector, B>>>;

Expand Down Expand Up @@ -56,14 +59,16 @@ impl EngineClient {

/// Send a request to identify the engine client version.
pub async fn engine_client_version(&self) -> TransportResult<Vec<ClientVersionV1>> {
// Send a mocked client info to the EL, since this is a required request argument
let mocked_cl_info = ClientVersionV1 {
code: ClientCode::RH, // pretend we are Reth
version: format!("v{}", env!("CARGO_PKG_VERSION")),
name: "BoltSidecar".to_string(),
commit: "unstable".to_string(),
};

self.inner.get_client_version_v1(mocked_cl_info).await
self.inner.get_client_version_v1(MOCKED_ENGINE_VERSION.clone()).await
}
}

lazy_static! {
/// The mocked engine version for the Bolt sidecar.
pub static ref MOCKED_ENGINE_VERSION: ClientVersionV1 = ClientVersionV1 {
code: ClientCode::RH, // pretend we are Reth
version: BOLT_SIDECAR_VERSION.clone(),
name: "BoltSidecar".to_string(),
commit: "unstable".to_string(),
};
}
12 changes: 10 additions & 2 deletions bolt-sidecar/src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
use lazy_static::lazy_static;

/// Utilities for retrying a future with backoff.
pub mod backoff;

/// A hash map-like bounded data structure with an additional scoring mechanism.
pub mod score_cache;

/// Secret key types wrappers for BLS, ECDSA and JWT.
pub mod secrets;

/// Utility functions for working with transactions.
pub mod transactions;

/// The version of the Bolt sidecar binary.
pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
lazy_static! {
/// The version of the Bolt sidecar binary.
pub static ref BOLT_SIDECAR_VERSION: String =
format!("v{}-{}", env!("CARGO_PKG_VERSION"), crate::built_info::GIT_COMMIT_HASH_SHORT.unwrap_or("unknown"));
}
6 changes: 6 additions & 0 deletions bolt-sidecar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ pub mod chain_io;
/// Utilities for testing
#[cfg(test)]
mod test_util;

/// Built-time information about the sidecar binary.
pub mod built_info {
// Docs: https://docs.rs/built/latest/built/
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}

0 comments on commit ca7c8e9

Please sign in to comment.