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

Add builder header timeout flag #5857

Merged
merged 7 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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
20 changes: 15 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,16 @@ 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 = if let Some(get_header_timeout) = get_header_timeout {
get_header_timeout
} else {
Duration::from_millis(DEFAULT_GET_HEADER_TIMEOUT_MILLIS)
};
michaelsproul marked this conversation as resolved.
Show resolved Hide resolved

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 +55,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
michaelsproul marked this conversation as resolved.
Show resolved Hide resolved
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
11 changes: 11 additions & 0 deletions beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,17 @@ pub fn cli_app() -> Command {
.action(ArgAction::Set)
.display_order(0)
)
.arg(
Arg::new("builder-header-timeout")
.long("builder-header-timeout")
.value_name("UINT64")
.help("Defines a timeout value (in milliseconds) to use when \
fetching a block header from the builder api.")
eserilev marked this conversation as resolved.
Show resolved Hide resolved
.default_value("1000")
.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 <UINT64>
Defines a timeout value (in milliseconds) to use when fetching a block
header from the builder api. [default: 1000]
eserilev marked this conversation as resolved.
Show resolved Hide resolved
--builder-profit-threshold <WEI_VALUE>
This flag is deprecated and has no effect.
--builder-user-agent <STRING>
Expand Down
9 changes: 9 additions & 0 deletions consensus/types/src/test_utils/test_random/bitfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ 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;
}
michaelsproul marked this conversation as resolved.
Show resolved Hide resolved
Self::from_bytes(raw_bytes).expect("we generate a valid BitVector")
}
}
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
Loading