Skip to content

Commit 901cd5e

Browse files
authored
CBST-10: validate PBS config (#173)
* validate pbs config * add min bid check
1 parent 91712c9 commit 901cd5e

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

crates/common/src/config/pbs.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use std::{collections::HashMap, sync::Arc};
44

5-
use alloy::primitives::U256;
6-
use eyre::Result;
5+
use alloy::primitives::{utils::format_ether, U256};
6+
use eyre::{ensure, Result};
77
use serde::{de::DeserializeOwned, Deserialize, Serialize};
88
use url::Url;
99

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

1919
#[derive(Debug, Clone, Deserialize, Serialize)]
@@ -70,6 +70,25 @@ pub struct PbsConfig {
7070
impl PbsConfig {
7171
/// Validate PBS config parameters
7272
pub fn validate(&self) -> Result<()> {
73+
// timeouts must be positive
74+
ensure!(self.timeout_get_header_ms > 0, "timeout_get_header_ms must be greater than 0");
75+
ensure!(self.timeout_get_payload_ms > 0, "timeout_get_payload_ms must be greater than 0");
76+
ensure!(
77+
self.timeout_register_validator_ms > 0,
78+
"timeout_register_validator_ms must be greater than 0"
79+
);
80+
ensure!(self.late_in_slot_time_ms > 0, "late_in_slot_time_ms must be greater than 0");
81+
82+
ensure!(
83+
self.timeout_get_header_ms < self.late_in_slot_time_ms,
84+
"timeout_get_header_ms must be less than late_in_slot_time_ms"
85+
);
86+
87+
ensure!(
88+
self.min_bid_wei < U256::from(WEI_PER_ETH),
89+
format!("min bid is too high: {} ETH", format_ether(self.min_bid_wei))
90+
);
91+
7392
Ok(())
7493
}
7594
}

crates/common/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn utcnow_ns() -> u64 {
5050
}
5151

5252
// Formatting
53-
const WEI_PER_ETH: u64 = 1_000_000_000_000_000_000;
53+
pub const WEI_PER_ETH: u64 = 1_000_000_000_000_000_000;
5454
pub fn wei_to_eth(wei: &U256) -> f64 {
5555
wei.to_string().parse::<f64>().unwrap_or_default() / WEI_PER_ETH as f64
5656
}

0 commit comments

Comments
 (0)