Skip to content

Commit

Permalink
Merge of #5857
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored May 31, 2024
2 parents bbe9242 + af4db60 commit 7d8e443
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 8 deletions.
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ where
.set_builder_url(
SensitiveUrl::parse(format!("http://127.0.0.1:{port}").as_str()).unwrap(),
None,
None,
)
.unwrap();

Expand Down
17 changes: 12 additions & 5 deletions beacon_node/builder_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ pub struct Timeouts {
get_builder_status: Duration,
}

impl Default for Timeouts {
fn default() -> Self {
impl Timeouts {
fn new(get_header_timeout: Option<Duration>) -> Self {
let get_header =
get_header_timeout.unwrap_or(Duration::from_millis(DEFAULT_GET_HEADER_TIMEOUT_MILLIS));

Self {
get_header: Duration::from_millis(DEFAULT_GET_HEADER_TIMEOUT_MILLIS),
get_header,
post_validators: Duration::from_millis(DEFAULT_TIMEOUT_MILLIS),
post_blinded_blocks: Duration::from_millis(DEFAULT_TIMEOUT_MILLIS),
get_builder_status: Duration::from_millis(DEFAULT_TIMEOUT_MILLIS),
Expand All @@ -49,13 +52,17 @@ pub struct BuilderHttpClient {
}

impl BuilderHttpClient {
pub fn new(server: SensitiveUrl, user_agent: Option<String>) -> Result<Self, Error> {
pub fn new(
server: SensitiveUrl,
user_agent: Option<String>,
builder_header_timeout: Option<Duration>,
) -> Result<Self, Error> {
let user_agent = user_agent.unwrap_or(DEFAULT_USER_AGENT.to_string());
let client = reqwest::Client::builder().user_agent(&user_agent).build()?;
Ok(Self {
client,
server,
timeouts: Timeouts::default(),
timeouts: Timeouts::new(builder_header_timeout),
user_agent,
})
}
Expand Down
15 changes: 12 additions & 3 deletions beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ pub struct Config {
pub execution_endpoint: Option<SensitiveUrl>,
/// 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.
pub builder_header_timeout: Option<Duration>,
/// User agent to send with requests to the builder API.
pub builder_user_agent: Option<String>,
/// JWT secret for the above endpoint running the engine api.
Expand Down Expand Up @@ -400,6 +403,7 @@ impl<E: EthSpec> ExecutionLayer<E> {
execution_endpoint: url,
builder_url,
builder_user_agent,
builder_header_timeout,
secret_file,
suggested_fee_recipient,
jwt_id,
Expand Down Expand Up @@ -469,7 +473,7 @@ impl<E: EthSpec> ExecutionLayer<E> {
};

if let Some(builder_url) = builder_url {
el.set_builder_url(builder_url, builder_user_agent)?;
el.set_builder_url(builder_url, builder_user_agent, builder_header_timeout)?;
}

Ok(el)
Expand All @@ -491,9 +495,14 @@ impl<E: EthSpec> ExecutionLayer<E> {
&self,
builder_url: SensitiveUrl,
builder_user_agent: Option<String>,
builder_header_timeout: Option<Duration>,
) -> Result<(), Error> {
let builder_client = BuilderHttpClient::new(builder_url.clone(), builder_user_agent)
.map_err(Error::Builder)?;
let builder_client = BuilderHttpClient::new(
builder_url.clone(),
builder_user_agent,
builder_header_timeout,
)
.map_err(Error::Builder)?;
info!(
self.log(),
"Using external block builder";
Expand Down
28 changes: 28 additions & 0 deletions 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 @@ -855,6 +857,32 @@ pub fn cli_app() -> Command {
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::new("builder-header-timeout")
.long("builder-header-timeout")
.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)
)
/* Deneb settings */
.arg(
Arg::new("trusted-setup-file-override")
Expand Down
4 changes: 4 additions & 0 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ pub fn get_config<E: EthSpec>(

el_config.builder_user_agent =
clap_utils::parse_optional(cli_args, "builder-user-agent")?;

el_config.builder_header_timeout =
clap_utils::parse_optional(cli_args, "builder-header-timeout")?
.map(Duration::from_millis);
}

if parse_flag(cli_args, "builder-profit-threshold") {
Expand Down
3 changes: 3 additions & 0 deletions book/src/help_bn.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Options:
slots on the canonical chain in the past `SLOTS_PER_EPOCH`, it will
NOT query any connected builders, and will use the local execution
engine for payload construction. [default: 8]
--builder-header-timeout <MILLISECONDS>
Defines a timeout value (in milliseconds) to use when fetching a block
header from the builder API. [default: 1000]
--builder-profit-threshold <WEI_VALUE>
This flag is deprecated and has no effect.
--builder-user-agent <STRING>
Expand Down
20 changes: 20 additions & 0 deletions lighthouse/tests/beacon_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,26 @@ fn builder_fallback_flags() {
);
}

#[test]
fn builder_get_header_timeout() {
run_payload_builder_flag_test_with_config(
"builder",
"http://meow.cats",
Some("builder-header-timeout"),
Some("1500"),
|config| {
assert_eq!(
config
.execution_layer
.as_ref()
.unwrap()
.builder_header_timeout,
Some(Duration::from_millis(1500))
);
},
);
}

#[test]
fn builder_user_agent() {
run_payload_builder_flag_test_with_config(
Expand Down

0 comments on commit 7d8e443

Please sign in to comment.