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
1 change: 1 addition & 0 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions bin/pbs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cb_common::{
config::load_pbs_config,
utils::{initialize_pbs_tracing_log, wait_for_signal},
config::{load_pbs_config, LogsSettings, PBS_MODULE_NAME},
utils::{initialize_tracing_log, wait_for_signal},
};
use cb_pbs::{DefaultBuilderApi, PbsService, PbsState};
use clap::Parser;
Expand All @@ -15,7 +15,7 @@ async fn main() -> Result<()> {
if std::env::var_os("RUST_BACKTRACE").is_none() {
std::env::set_var("RUST_BACKTRACE", "1");
}
let _guard = initialize_pbs_tracing_log();
let _guard = initialize_tracing_log(PBS_MODULE_NAME, LogsSettings::from_env_config()?);

let _args = cb_cli::PbsArgs::parse();

Expand All @@ -29,6 +29,7 @@ async fn main() -> Result<()> {
maybe_err = server => {
if let Err(err) = maybe_err {
error!(%err, "PBS service unexpectedly stopped");
eprintln!("PBS service unexpectedly stopped: {}", err);
}
},
_ = wait_for_signal() => {
Expand Down
5 changes: 3 additions & 2 deletions bin/signer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cb_common::{
config::{StartSignerConfig, SIGNER_MODULE_NAME},
config::{LogsSettings, StartSignerConfig, SIGNER_MODULE_NAME},
utils::{initialize_tracing_log, wait_for_signal},
};
use cb_signer::service::SigningService;
Expand All @@ -15,7 +15,7 @@ async fn main() -> Result<()> {
if std::env::var_os("RUST_BACKTRACE").is_none() {
std::env::set_var("RUST_BACKTRACE", "1");
}
let _guard = initialize_tracing_log(SIGNER_MODULE_NAME);
let _guard = initialize_tracing_log(SIGNER_MODULE_NAME, LogsSettings::from_env_config()?);

let _args = cb_cli::SignerArgs::parse();

Expand All @@ -26,6 +26,7 @@ async fn main() -> Result<()> {
maybe_err = server => {
if let Err(err) = maybe_err {
error!(%err, "signing server unexpectedly stopped");
eprintln!("signing server unexpectedly stopped: {}", err);
}
},
_ = wait_for_signal() => {
Expand Down
7 changes: 2 additions & 5 deletions bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ pub mod prelude {
},
config::{
load_builder_module_config, load_commit_module_config, load_pbs_config,
load_pbs_custom_config, LogsSettings, StartCommitModuleConfig,
load_pbs_custom_config, LogsSettings, StartCommitModuleConfig, PBS_MODULE_NAME,
},
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,
},
utils::{initialize_tracing_log, utcnow_ms, utcnow_ns, utcnow_sec, utcnow_us},
};
pub use cb_metrics::provider::MetricsProvider;
pub use cb_pbs::{
Expand Down
38 changes: 30 additions & 8 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,37 @@ host = "127.0.0.1"
# OPTIONAL, DEFAULT: 10000
start_port = 10000

# Configuration for how logs should be collected and stored
# OPTIONAL, info to stdout if missing
[logs]
# Configuration stdout logs
# OPTIONAL, DEFAULT: enabled
[logs.stdout]
# Whether to enable stdout logging
# OPTIONAL, DEFAULT: true
enabled = true
# Log level. Supported values: trace, debug, info, warn, error
# OPTIONAL, DEFAULT: info
level = "info"
# Log in JSON format
# OPTIONAL, DEFAULT: false
use_json = false
# Whether to enable ANSI color codes
# OPTIONAL, DEFAULT: true
color = true

# Configuration file logs
# OPTIONAL, DEFAULT: disabled
[logs.file]
# Whether to enable file logging
# OPTIONAL, DEFAULT: false
enabled = true
# Log level. Supported values: trace, debug, info, warn, error
# OPTIONAL, DEFAULT: info
level = "debug"
# Log in JSON format
# OPTIONAL, DEFAULT: true
use_json = true
# Path to the log directory
# OPTIONAL, DEFAULT: /var/logs/commit-boost
log_dir_path = "./logs"
# Log level. Supported values: trace, debug, info, warn, error
# OPTIONAL, DEFAULT: debug to file, info to stdout
log_level = "debug"
dir_path = "./logs"
# Maximum number of log files to keep
# OPTIONAL
max_log_files = 30
max_files = 30
12 changes: 6 additions & 6 deletions crates/cli/src/docker_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re

let chain_spec_path = CommitBoostConfig::chain_spec_file(&config_path);

let log_to_file = cb_config.logs.is_some();
let log_to_file = cb_config.logs.file.enabled;
let mut metrics_port = cb_config.metrics.as_ref().map(|m| m.start_port).unwrap_or_default();

let mut services = IndexMap::new();
Expand Down Expand Up @@ -584,8 +584,8 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
println!()
}
// if file logging is enabled, warn about permissions
if let Some(logs_config) = cb_config.logs {
let log_dir = logs_config.log_dir_path;
if cb_config.logs.file.enabled {
let log_dir = cb_config.logs.file.dir_path;
println!(
"Warning: file logging is enabled, you may need to update permissions for the logs directory. e.g. with:\n\t`sudo chown -R 10001:10001 {}`",
log_dir.display()
Expand Down Expand Up @@ -654,9 +654,9 @@ fn get_env_uval(k: &str, v: u64) -> (String, Option<SingleValue>) {
// (k.into(), Some(SingleValue::Bool(v)))
// }

fn get_log_volume(maybe_config: &Option<LogsSettings>, module_id: &str) -> Option<Volumes> {
maybe_config.as_ref().map(|config| {
let p = config.log_dir_path.join(module_id.to_lowercase());
fn get_log_volume(config: &LogsSettings, module_id: &str) -> Option<Volumes> {
config.file.enabled.then_some({
let p = config.file.dir_path.join(module_id.to_lowercase());
Volumes::Simple(format!(
"{}:{}",
p.to_str().expect("could not convert pathbuf to str"),
Expand Down
75 changes: 52 additions & 23 deletions crates/common/src/config/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,21 @@ use eyre::Result;
use serde::{Deserialize, Serialize};

use super::{load_optional_env_var, CommitBoostConfig, LOGS_DIR_DEFAULT, LOGS_DIR_ENV};
use crate::utils::default_bool;

#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
pub struct LogsSettings {
#[serde(default = "default_log_dir_path")]
pub log_dir_path: PathBuf,
#[serde(default = "default_log_level")]
pub log_level: String,
#[serde(default)]
pub max_log_files: Option<usize>,
}

impl Default for LogsSettings {
fn default() -> Self {
LogsSettings {
log_dir_path: default_log_dir_path(),
log_level: default_log_level(),
max_log_files: None,
}
}
pub stdout: StdoutLogSettings,
pub file: FileLogSettings,
}

impl LogsSettings {
pub fn from_env_config() -> Result<Option<Self>> {
pub fn from_env_config() -> Result<Self> {
let mut config = CommitBoostConfig::from_env_path()?;

// Override log dir path if env var is set
if let Some(log_config) = config.logs.as_mut() {
if let Some(log_dir) = load_optional_env_var(LOGS_DIR_ENV) {
log_config.log_dir_path = log_dir.into();
}
if let Some(log_dir) = load_optional_env_var(LOGS_DIR_ENV) {
config.logs.file.dir_path = log_dir.into();
}

Ok(config.logs)
Expand All @@ -44,6 +29,50 @@ fn default_log_dir_path() -> PathBuf {
LOGS_DIR_DEFAULT.into()
}

pub fn default_log_level() -> String {
fn default_level() -> String {
"info".into()
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct StdoutLogSettings {
#[serde(default = "default_bool::<true>")]
pub enabled: bool,
#[serde(default = "default_level")]
pub level: String,
#[serde(default = "default_bool::<false>")]
pub use_json: bool,
#[serde(default = "default_bool::<true>")]
pub color: bool,
}

impl Default for StdoutLogSettings {
fn default() -> Self {
Self { enabled: true, level: "info".into(), use_json: false, color: true }
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct FileLogSettings {
#[serde(default = "default_bool::<false>")]
pub enabled: bool,
#[serde(default = "default_level")]
pub level: String,
#[serde(default = "default_bool::<true>")]
pub use_json: bool,
#[serde(default = "default_log_dir_path")]
pub dir_path: PathBuf,
#[serde(default)]
pub max_files: Option<usize>,
}

impl Default for FileLogSettings {
fn default() -> Self {
Self {
enabled: false,
level: "info".into(),
use_json: true,
dir_path: default_log_dir_path(),
max_files: None,
}
}
}
6 changes: 4 additions & 2 deletions crates/common/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ pub struct CommitBoostConfig {
pub modules: Option<Vec<StaticModuleConfig>>,
pub signer: Option<SignerConfig>,
pub metrics: Option<MetricsConfig>,
pub logs: Option<LogsSettings>,
#[serde(default)]
pub logs: LogsSettings,
}

impl CommitBoostConfig {
Expand Down Expand Up @@ -117,5 +118,6 @@ struct HelperConfig {
modules: Option<Vec<StaticModuleConfig>>,
signer: Option<SignerConfig>,
metrics: Option<MetricsConfig>,
logs: Option<LogsSettings>,
#[serde(default)]
logs: LogsSettings,
}
14 changes: 14 additions & 0 deletions crates/common/src/pbs/types/beacon_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ impl SignedBlindedBeaconBlock {
}
}

pub fn block_number(&self) -> u64 {
match &self.message {
BlindedBeaconBlock::Electra(b) => b.body.execution_payload_header.block_number,
BlindedBeaconBlock::Deneb(b) => b.body.execution_payload_header.block_number,
}
}

pub fn parent_hash(&self) -> B256 {
match &self.message {
BlindedBeaconBlock::Electra(b) => b.body.execution_payload_header.parent_hash,
BlindedBeaconBlock::Deneb(b) => b.body.execution_payload_header.parent_hash,
}
}

pub fn slot(&self) -> u64 {
match &self.message {
BlindedBeaconBlock::Electra(b) => b.slot,
Expand Down
Loading
Loading