Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBST-10: validate PBS config #173

Merged
merged 2 commits into from
Nov 20, 2024
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
25 changes: 22 additions & 3 deletions crates/common/src/config/pbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use std::{collections::HashMap, sync::Arc};

use alloy::primitives::U256;
use eyre::Result;
use alloy::primitives::{utils::format_ether, U256};
use eyre::{ensure, Result};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use url::Url;

Expand All @@ -13,7 +13,7 @@ use crate::{
config::{load_env_var, load_file_from_env, CONFIG_ENV, MODULE_JWT_ENV, SIGNER_URL_ENV},
pbs::{BuilderEventPublisher, DefaultTimeout, RelayClient, RelayEntry, LATE_IN_SLOT_TIME_MS},
types::Chain,
utils::{as_eth_str, default_bool, default_u256, default_u64},
utils::{as_eth_str, default_bool, default_u256, default_u64, WEI_PER_ETH},
};

#[derive(Debug, Clone, Deserialize, Serialize)]
Expand Down Expand Up @@ -70,6 +70,25 @@ pub struct PbsConfig {
impl PbsConfig {
/// Validate PBS config parameters
pub fn validate(&self) -> Result<()> {
// timeouts must be positive
ensure!(self.timeout_get_header_ms > 0, "timeout_get_header_ms must be greater than 0");
ensure!(self.timeout_get_payload_ms > 0, "timeout_get_payload_ms must be greater than 0");
ensure!(
self.timeout_register_validator_ms > 0,
"timeout_register_validator_ms must be greater than 0"
);
ensure!(self.late_in_slot_time_ms > 0, "late_in_slot_time_ms must be greater than 0");

ensure!(
self.timeout_get_header_ms < self.late_in_slot_time_ms,
"timeout_get_header_ms must be less than late_in_slot_time_ms"
);

ensure!(
self.min_bid_wei < U256::from(WEI_PER_ETH),
format!("min bid is too high: {} ETH", format_ether(self.min_bid_wei))
);

Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn utcnow_ns() -> u64 {
}

// Formatting
const WEI_PER_ETH: u64 = 1_000_000_000_000_000_000;
pub const WEI_PER_ETH: u64 = 1_000_000_000_000_000_000;
pub fn wei_to_eth(wei: &U256) -> f64 {
wei.to_string().parse::<f64>().unwrap_or_default() / WEI_PER_ETH as f64
}
Expand Down