Skip to content

Commit

Permalink
add upper limit check, changes based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
eserilev committed May 29, 2024
1 parent 8d1f865 commit 773c4d4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
7 changes: 2 additions & 5 deletions beacon_node/builder_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ pub struct Timeouts {

impl Timeouts {
fn new(get_header_timeout: Option<Duration>) -> Self {
let get_header = if let Some(get_header_timeout) = get_header_timeout {
get_header_timeout
} else {
Duration::from_millis(DEFAULT_GET_HEADER_TIMEOUT_MILLIS)
};
let get_header =
get_header_timeout.unwrap_or(Duration::from_millis(DEFAULT_GET_HEADER_TIMEOUT_MILLIS));

Self {
get_header,
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ pub struct Config {
/// Endpoint urls for services providing the builder api.
pub builder_url: Option<SensitiveUrl>,
/// The timeout value used when making a request to fetch a block header
/// from the builder api
/// from the builder api.
pub builder_header_timeout: Option<Duration>,
/// User agent to send with requests to the builder API.
pub builder_user_agent: Option<String>,
Expand Down
19 changes: 18 additions & 1 deletion beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Duration;

use clap::{builder::ArgPredicate, crate_version, Arg, ArgAction, ArgGroup, Command};
use clap_utils::{get_color_style, FLAG_HEADER};
use strum::VariantNames;
Expand Down Expand Up @@ -858,10 +860,25 @@ pub fn cli_app() -> Command {
.arg(
Arg::new("builder-header-timeout")
.long("builder-header-timeout")
.value_name("UINT64")
.value_name("MILLISECONDS")
.help("Defines a timeout value (in milliseconds) to use when \
fetching a block header from the builder api.")
.default_value("1000")
.value_parser(|timeout: &str| {
match timeout
.parse::<u64>()
.ok()
.map(Duration::from_millis)
{
Some(val) => {
if val > Duration::from_secs(3) {
return Err("builder-header-timeout cannot exceed 3000ms")
}
Ok(timeout.to_string())
},
None => Err("builder-header-timeout must be a number"),
}
})
.requires("builder")
.action(ArgAction::Set)
.display_order(0)
Expand Down
9 changes: 0 additions & 9 deletions consensus/types/src/test_utils/test_random/bitfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ impl<N: Unsigned + Clone> TestRandom for BitVector<N> {
fn random_for_test(rng: &mut impl RngCore) -> Self {
let mut raw_bytes = smallvec![0; std::cmp::max(1, (N::to_usize() + 7) / 8)];
rng.fill_bytes(&mut raw_bytes);
// If N isn't divisible by 8
// zero out bits greater than N
if let Some(last_byte) = raw_bytes.last_mut() {
let mut mask = 0;
for i in 0..N::to_usize() % 8 {
mask |= 1 << i;
}
*last_byte &= mask;
}
Self::from_bytes(raw_bytes).expect("we generate a valid BitVector")
}
}

0 comments on commit 773c4d4

Please sign in to comment.