Skip to content
Open
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
105 changes: 105 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ lazy_static = "1.5.0"
lh_eth2 = { package = "eth2", git = "https://github.com/sigp/lighthouse", tag = "v8.0.0-rc.0" }
lh_eth2_keystore = { package = "eth2_keystore", git = "https://github.com/sigp/lighthouse", tag = "v8.0.0-rc.0" }
lh_types = { package = "types", git = "https://github.com/sigp/lighthouse", tag = "v8.0.0-rc.0" }
notify = "8.2.0"
parking_lot = "0.12.3"
pbkdf2 = "0.12.2"
prometheus = "0.14.0"
Expand Down
4 changes: 2 additions & 2 deletions bin/pbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ async fn main() -> Result<()> {

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

let pbs_config = load_pbs_config().await?;
let (pbs_config, config_path) = load_pbs_config(None).await?;

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

tokio::select! {
Expand Down
1 change: 1 addition & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lazy_static.workspace = true
lh_eth2.workspace = true
lh_eth2_keystore.workspace = true
lh_types.workspace = true
notify.workspace = true
pbkdf2.workspace = true
rand.workspace = true
rayon.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/config/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct LogsSettings {

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

// Override log dir path if env var is set
if let Some(log_dir) = load_optional_env_var(LOGS_DIR_ENV) {
Expand Down
10 changes: 5 additions & 5 deletions crates/common/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ impl CommitBoostConfig {
}

pub fn from_file(path: &PathBuf) -> Result<Self> {
let config: Self = load_from_file(path)?;
let (config, _): (Self, _) = load_from_file(path)?;
Ok(config)
}

// When loading the config from the environment, it's important that every path
// is replaced with the correct value if the config is loaded inside a container
pub fn from_env_path() -> Result<Self> {
let helper_config: HelperConfig = load_file_from_env(CONFIG_ENV)?;
pub fn from_env_path() -> Result<(Self, PathBuf)> {
let (helper_config, config_path): (HelperConfig, PathBuf) = load_file_from_env(CONFIG_ENV)?;

let chain = match helper_config.chain {
ChainLoader::Path { path, genesis_time_secs } => {
Expand Down Expand Up @@ -109,13 +109,13 @@ impl CommitBoostConfig {
logs: helper_config.logs,
};

Ok(config)
Ok((config, config_path))
}

/// Returns the path to the chain spec file if any
pub fn chain_spec_file(path: &PathBuf) -> Option<PathBuf> {
match load_from_file::<_, ChainConfig>(path) {
Ok(config) => {
Ok((config, _)) => {
if let ChainLoader::Path { path, genesis_time_secs: _ } = config.chain {
Some(path)
} else {
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/config/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn load_commit_module_config<T: DeserializeOwned>() -> Result<StartCommitMod
}

// load module config including the extra data (if any)
let cb_config: StubConfig<T> = load_file_from_env(CONFIG_ENV)?;
let (cb_config, _): (StubConfig<T>, _) = load_file_from_env(CONFIG_ENV)?;

// find all matching modules config
let matches: Vec<ThisModuleConfig<T>> = cb_config
Expand Down Expand Up @@ -148,7 +148,7 @@ pub fn load_builder_module_config<T: DeserializeOwned>() -> eyre::Result<StartBu
}

// load module config including the extra data (if any)
let cb_config: StubConfig<T> = load_file_from_env(CONFIG_ENV)?;
let (cb_config, _): (StubConfig<T>, _) = load_file_from_env(CONFIG_ENV)?;

// find all matching modules config
let matches: Vec<ThisModuleConfig<T>> = cb_config
Expand Down
33 changes: 20 additions & 13 deletions crates/common/src/config/pbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::{
collections::HashMap,
net::{Ipv4Addr, SocketAddr},
path::PathBuf,
sync::Arc,
};

Expand Down Expand Up @@ -242,8 +243,11 @@ fn default_pbs() -> String {
}

/// Loads the default pbs config, i.e. with no signer client or custom data
pub async fn load_pbs_config() -> Result<PbsModuleConfig> {
let config = CommitBoostConfig::from_env_path()?;
pub async fn load_pbs_config(config_path: Option<PathBuf>) -> Result<(PbsModuleConfig, PathBuf)> {
let (config, config_path) = match config_path {
Some(path) => (CommitBoostConfig::from_file(&path)?, path),
None => CommitBoostConfig::from_env_path()?,
};
config.validate().await?;

// Make sure relays isn't empty - since the config is still technically valid if
Expand Down Expand Up @@ -295,16 +299,19 @@ pub async fn load_pbs_config() -> Result<PbsModuleConfig> {

let all_relays = all_relays.into_values().collect();

Ok(PbsModuleConfig {
chain: config.chain,
endpoint,
pbs_config: Arc::new(config.pbs.pbs_config),
relays: relay_clients,
all_relays,
signer_client: None,
registry_muxes,
mux_lookup,
})
Ok((
PbsModuleConfig {
chain: config.chain,
endpoint,
pbs_config: Arc::new(config.pbs.pbs_config),
relays: relay_clients,
all_relays,
signer_client: None,
registry_muxes,
mux_lookup,
},
config_path,
))
}

/// Loads a custom pbs config, i.e. with signer client and/or custom data
Expand All @@ -326,7 +333,7 @@ pub async fn load_pbs_custom_config<T: DeserializeOwned>() -> Result<(PbsModuleC
}

// load module config including the extra data (if any)
let cb_config: StubConfig<T> = load_file_from_env(CONFIG_ENV)?;
let (cb_config, _): (StubConfig<T>, _) = load_file_from_env(CONFIG_ENV)?;
cb_config.pbs.static_config.pbs_config.validate(cb_config.chain).await?;

// use endpoint from env if set, otherwise use default host and port
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/config/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub struct StartSignerConfig {

impl StartSignerConfig {
pub fn load_from_env() -> Result<Self> {
let config = CommitBoostConfig::from_env_path()?;
let (config, _) = CommitBoostConfig::from_env_path()?;

let jwts = load_jwt_secrets()?;

Expand Down
16 changes: 12 additions & 4 deletions crates/common/src/config/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{collections::HashMap, path::Path};
use std::{
collections::HashMap,
path::{Path, PathBuf},
};

use eyre::{Context, Result, bail};
use serde::de::DeserializeOwned;
Expand All @@ -17,13 +20,18 @@ pub fn load_optional_env_var(env: &str) -> Option<String> {
std::env::var(env).ok()
}

pub fn load_from_file<P: AsRef<Path> + std::fmt::Debug, T: DeserializeOwned>(path: P) -> Result<T> {
pub fn load_from_file<P: AsRef<Path> + std::fmt::Debug, T: DeserializeOwned>(
path: P,
) -> Result<(T, PathBuf)> {
let config_file = std::fs::read_to_string(path.as_ref())
.wrap_err(format!("Unable to find config file: {path:?}"))?;
toml::from_str(&config_file).wrap_err("could not deserialize toml from string")
match toml::from_str(&config_file).wrap_err("could not deserialize toml from string") {
Ok(config) => Ok((config, path.as_ref().to_path_buf())),
Err(e) => Err(e),
}
}

pub fn load_file_from_env<T: DeserializeOwned>(env: &str) -> Result<T> {
pub fn load_file_from_env<T: DeserializeOwned>(env: &str) -> Result<(T, PathBuf)> {
let path = std::env::var(env).wrap_err(format!("{env} is not set"))?;
load_from_file(&path)
}
Expand Down
1 change: 1 addition & 0 deletions crates/pbs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cb-metrics.workspace = true
eyre.workspace = true
futures.workspace = true
lazy_static.workspace = true
notify.workspace = true
parking_lot.workspace = true
prometheus.workspace = true
reqwest.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/pbs/src/mev_boost/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{BuilderApiState, PbsState};
/// Reload the PBS state with the latest configuration in the config file
/// Returns 200 if successful or 500 if failed
pub async fn reload<S: BuilderApiState>(state: PbsState<S>) -> eyre::Result<PbsState<S>> {
let pbs_config = load_pbs_config().await?;
let new_state = PbsState::new(pbs_config).with_data(state.data);
let (pbs_config, config_path) = load_pbs_config(None).await?;
let new_state = PbsState::new(pbs_config, config_path).with_data(state.data);

if state.config.pbs_config.host != new_state.config.pbs_config.host {
warn!(
Expand Down
Loading
Loading