Skip to content
Merged
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
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
target
Dockerfile
.dockerignore
.git
.gitignore
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ jobs:
uses: actions/checkout@v4
with:
ref: "stable"
fetch-depth: 0

- name: Log commit hash
run: |
echo "Releasing commit: $(git rev-parse HEAD)"

- name: Cache Cargo registry
uses: actions/cache@v3
Expand Down Expand Up @@ -107,6 +112,7 @@ jobs:
uses: actions/checkout@v4
with:
ref: "stable"
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down Expand Up @@ -141,6 +147,7 @@ jobs:
uses: actions/checkout@v4
with:
ref: "stable"
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down
2 changes: 1 addition & 1 deletion bin/pbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ async fn main() -> Result<()> {

let pbs_config = load_pbs_config().await?;

PbsService::init_metrics(pbs_config.chain)?;
let state = PbsState::new(pbs_config);
PbsService::init_metrics()?;
let server = PbsService::run::<_, DefaultBuilderApi>(state);

tokio::select! {
Expand Down
1 change: 1 addition & 0 deletions bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod prelude {
},
pbs::{BuilderEvent, BuilderEventClient, OnBuilderApiEvent},
signer::{BlsPublicKey, BlsSignature, EcdsaPublicKey, EcdsaSignature},
types::Chain,
utils::{
initialize_pbs_tracing_log, initialize_tracing_log, utcnow_ms, utcnow_ns, utcnow_sec,
utcnow_us,
Expand Down
1 change: 1 addition & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version.workspace = true
edition.workspace = true
rust-version.workspace = true
publish = false
build = "build.rs"

[dependencies]
# ethereum
Expand Down
7 changes: 7 additions & 0 deletions crates/common/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::process::Command;

fn main() {
let output = Command::new("git").args(["rev-parse", "HEAD"]).output().unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
}
1 change: 1 addition & 0 deletions crates/common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub const APPLICATION_BUILDER_DOMAIN: [u8; 4] = [0, 0, 0, 1];
pub const GENESIS_VALIDATORS_ROOT: [u8; 32] = [0; 32];
pub const COMMIT_BOOST_DOMAIN: [u8; 4] = [109, 109, 111, 67];
pub const COMMIT_BOOST_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const COMMIT_BOOST_COMMIT: &str = env!("GIT_HASH");
9 changes: 9 additions & 0 deletions crates/common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ pub enum Chain {

pub type ForkVersion = [u8; 4];

impl std::fmt::Display for Chain {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Mainnet | Self::Holesky | Self::Sepolia | Self::Helder => write!(f, "{:?}", self),
Self::Custom { .. } => write!(f, "Custom"),
}
}
}

impl std::fmt::Debug for Chain {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down
30 changes: 22 additions & 8 deletions crates/metrics/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,33 @@ use axum::{
response::{IntoResponse, Response},
routing::get,
};
use cb_common::config::ModuleMetricsConfig;
use cb_common::{
config::ModuleMetricsConfig,
constants::{COMMIT_BOOST_COMMIT, COMMIT_BOOST_VERSION},
types::Chain,
};
use eyre::bail;
use prometheus::{Encoder, Registry, TextEncoder};
use prometheus::{Encoder, IntGauge, Opts, Registry, TextEncoder};
use tokio::net::TcpListener;
use tracing::{error, info, trace, warn};

pub struct MetricsProvider {
network: Chain,
config: ModuleMetricsConfig,
registry: Registry,
}

impl MetricsProvider {
pub fn new(config: ModuleMetricsConfig, registry: Registry) -> Self {
MetricsProvider { config, registry }
pub fn new(network: Chain, config: ModuleMetricsConfig, registry: Registry) -> Self {
MetricsProvider { network, config, registry }
}

pub fn from_registry(registry: Registry) -> eyre::Result<Option<Self>> {
Ok(ModuleMetricsConfig::load_from_env()?.map(|config| MetricsProvider { config, registry }))
pub fn from_registry(network: Chain, registry: Registry) -> eyre::Result<Option<Self>> {
Ok(ModuleMetricsConfig::load_from_env()?.map(|config| Self::new(network, config, registry)))
}

pub fn load_and_run(registry: Registry) -> eyre::Result<()> {
if let Some(provider) = MetricsProvider::from_registry(registry)? {
pub fn load_and_run(network: Chain, registry: Registry) -> eyre::Result<()> {
if let Some(provider) = MetricsProvider::from_registry(network, registry)? {
tokio::spawn(async move {
if let Err(err) = provider.run().await {
error!("Metrics server error: {:?}", err);
Expand All @@ -44,6 +49,15 @@ impl MetricsProvider {
pub async fn run(self) -> eyre::Result<()> {
info!("Starting metrics server on port {}", self.config.server_port);

let opts = Opts::new("info", "Commit Boost info")
.const_label("version", COMMIT_BOOST_VERSION)
.const_label("commit", COMMIT_BOOST_COMMIT)
.const_label("network", self.network.to_string());
let info = IntGauge::with_opts(opts).unwrap();
info.set(1);

self.registry.register(Box::new(info)).unwrap();

let router = axum::Router::new()
.route("/metrics", get(handle_metrics))
.route("/status", get(handle_status))
Expand Down
9 changes: 5 additions & 4 deletions crates/pbs/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::time::Duration;

use cb_common::{
constants::COMMIT_BOOST_VERSION,
constants::{COMMIT_BOOST_COMMIT, COMMIT_BOOST_VERSION},
pbs::{BUILDER_API_PATH, GET_STATUS_PATH},
types::Chain,
};
use cb_metrics::provider::MetricsProvider;
use eyre::{bail, Context, Result};
Expand All @@ -25,7 +26,7 @@ impl PbsService {
let addr = state.config.endpoint;
let events_subs =
state.config.event_publisher.as_ref().map(|e| e.n_subscribers()).unwrap_or_default();
info!(version = COMMIT_BOOST_VERSION, ?addr, events_subs, chain =? state.config.chain, "starting PBS service");
info!(version = COMMIT_BOOST_VERSION, commit = COMMIT_BOOST_COMMIT, ?addr, events_subs, chain =? state.config.chain, "starting PBS service");

let app = create_app_router::<S, A>(state);
let listener = TcpListener::bind(addr).await?;
Expand All @@ -52,7 +53,7 @@ impl PbsService {
PBS_METRICS_REGISTRY.register(c).expect("failed to register metric");
}

pub fn init_metrics() -> Result<()> {
MetricsProvider::load_and_run(PBS_METRICS_REGISTRY.clone())
pub fn init_metrics(network: Chain) -> Result<()> {
MetricsProvider::load_and_run(network, PBS_METRICS_REGISTRY.clone())
}
}
1 change: 1 addition & 0 deletions crates/signer/proto
Submodule proto added at 4aaf36
12 changes: 6 additions & 6 deletions crates/signer/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use cb_common::{
},
},
config::StartSignerConfig,
constants::COMMIT_BOOST_VERSION,
types::{Jwt, ModuleId},
constants::{COMMIT_BOOST_COMMIT, COMMIT_BOOST_VERSION},
types::{Chain, Jwt, ModuleId},
};
use cb_metrics::provider::MetricsProvider;
use eyre::{Context, Result};
Expand Down Expand Up @@ -74,10 +74,10 @@ impl SigningService {
let proxies = manager.proxies();
let loaded_proxies = proxies.bls_signers.len() + proxies.ecdsa_signers.len();

info!(version = COMMIT_BOOST_VERSION, modules =? module_ids, port =? config.server_port, loaded_consensus, loaded_proxies, "Starting signing service");
info!(version = COMMIT_BOOST_VERSION, commit = COMMIT_BOOST_COMMIT, modules =? module_ids, port =? config.server_port, loaded_consensus, loaded_proxies, "Starting signing service");

let state = SigningState { manager: RwLock::new(manager).into(), jwts: config.jwts.into() };
SigningService::init_metrics()?;
SigningService::init_metrics(config.chain)?;

let app = axum::Router::new()
.route(REQUEST_SIGNATURE_PATH, post(handle_request_signature))
Expand All @@ -96,8 +96,8 @@ impl SigningService {
.wrap_err("signer server exited")
}

fn init_metrics() -> Result<()> {
MetricsProvider::load_and_run(SIGNER_METRICS_REGISTRY.clone())
fn init_metrics(network: Chain) -> Result<()> {
MetricsProvider::load_and_run(network, SIGNER_METRICS_REGISTRY.clone())
}
}

Expand Down
3 changes: 2 additions & 1 deletion examples/configs/pbs_metrics.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ id = "example-relay"
url = "http://0xa1cec75a3f0661e99299274182938151e8433c61a19222347ea1313d839229cb4ce4e3e5aa2bdeb71c8fcf1b084963c2@abc.xyz"

[metrics]
prometheus_config = "./docker/prometheus.yml"
prometheus_config = "./provisioning/prometheus.yml"
use_grafana = true
use_cadvisor = false
grafana_path = "./provisioning/grafana"

[logs]
log_dir_path = "./logs"
2 changes: 1 addition & 1 deletion examples/da_commit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async fn main() -> Result<()> {
// Remember to register all your metrics before starting the process
MY_CUSTOM_REGISTRY.register(Box::new(SIG_RECEIVED_COUNTER.clone()))?;
// Spin up a server that exposes the /metrics endpoint to Prometheus
MetricsProvider::load_and_run(MY_CUSTOM_REGISTRY.clone())?;
MetricsProvider::load_and_run(Chain::Mainnet, MY_CUSTOM_REGISTRY.clone())?;

match load_commit_module_config::<ExtraConfig>() {
Ok(config) => {
Expand Down
3 changes: 2 additions & 1 deletion examples/status_api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ async fn main() -> Result<()> {
color_eyre::install()?;

let (pbs_config, extra) = load_pbs_custom_config::<ExtraConfig>().await?;
let chain = pbs_config.chain;
let _guard = initialize_pbs_tracing_log()?;

let custom_state = MyBuilderState::from_config(extra);
let state = PbsState::new(pbs_config).with_data(custom_state);

PbsService::register_metric(Box::new(CHECK_RECEIVED_COUNTER.clone()));
PbsService::init_metrics()?;
PbsService::init_metrics(chain)?;

PbsService::run::<MyBuilderState, MyBuilderApi>(state).await
}
Loading
Loading