Skip to content

Commit d131e1d

Browse files
committed
Add a disable-ssz flag on the builder
1 parent b3fe483 commit d131e1d

File tree

5 files changed

+46
-10
lines changed

5 files changed

+46
-10
lines changed

beacon_node/beacon_chain/src/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ where
779779
SensitiveUrl::parse(format!("http://127.0.0.1:{port}").as_str()).unwrap(),
780780
None,
781781
None,
782+
false,
782783
)
783784
.unwrap();
784785

beacon_node/builder_client/src/lib.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use eth2::types::{
77
use eth2::types::{FullPayloadContents, SignedBlindedBeaconBlock};
88
pub use eth2::Error;
99
use eth2::{
10-
ok_or_error, StatusCode, CONSENSUS_VERSION_HEADER, CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER,
10+
ok_or_error, StatusCode, CONSENSUS_VERSION_HEADER, CONTENT_TYPE_HEADER,
11+
JSON_CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER,
1112
};
1213
use reqwest::header::{HeaderMap, HeaderValue, ACCEPT};
1314
use reqwest::{IntoUrl, Response};
@@ -59,14 +60,20 @@ pub struct BuilderHttpClient {
5960
server: SensitiveUrl,
6061
timeouts: Timeouts,
6162
user_agent: String,
62-
ssz_enabled: Arc<AtomicBool>,
63+
/// Only use json for all requests/responses types.
64+
disable_ssz: bool,
65+
/// Indicates that the `get_header`` response had content-type ssz
66+
/// so we can set content-type header to ssz to make the `submit_blinded_blocks`
67+
/// request.
68+
ssz_used: Arc<AtomicBool>,
6369
}
6470

6571
impl BuilderHttpClient {
6672
pub fn new(
6773
server: SensitiveUrl,
6874
user_agent: Option<String>,
6975
builder_header_timeout: Option<Duration>,
76+
disable_ssz: bool,
7077
) -> Result<Self, Error> {
7178
let user_agent = user_agent.unwrap_or(DEFAULT_USER_AGENT.to_string());
7279
let client = reqwest::Client::builder().user_agent(&user_agent).build()?;
@@ -75,7 +82,8 @@ impl BuilderHttpClient {
7582
server,
7683
timeouts: Timeouts::new(builder_header_timeout),
7784
user_agent,
78-
ssz_enabled: Arc::new(false.into()),
85+
disable_ssz,
86+
ssz_used: Arc::new(false.into()),
7987
})
8088
}
8189

@@ -126,15 +134,15 @@ impl BuilderHttpClient {
126134

127135
let Ok(Some(fork_name)) = self.fork_name_from_header(&headers) else {
128136
// if no fork version specified, attempt to fallback to JSON
129-
self.ssz_enabled.store(false, Ordering::SeqCst);
137+
self.ssz_used.store(false, Ordering::SeqCst);
130138
return serde_json::from_slice(&response_bytes).map_err(Error::InvalidJson);
131139
};
132140

133141
let content_type = self.content_type_from_header(&headers);
134142

135143
match content_type {
136144
ContentType::Ssz => {
137-
self.ssz_enabled.store(true, Ordering::SeqCst);
145+
self.ssz_used.store(true, Ordering::SeqCst);
138146
T::from_ssz_bytes_by_fork(&response_bytes, fork_name)
139147
.map(|data| ForkVersionedResponse {
140148
version: Some(fork_name),
@@ -144,15 +152,17 @@ impl BuilderHttpClient {
144152
.map_err(Error::InvalidSsz)
145153
}
146154
ContentType::Json => {
147-
self.ssz_enabled.store(false, Ordering::SeqCst);
155+
self.ssz_used.store(false, Ordering::SeqCst);
148156
serde_json::from_slice(&response_bytes).map_err(Error::InvalidJson)
149157
}
150158
}
151159
}
152160

153161
/// Return `true` if the most recently received response from the builder had SSZ Content-Type.
162+
///
163+
/// Also returns `false` if we have explicitly disabled ssz.
154164
pub fn is_ssz_enabled(&self) -> bool {
155-
self.ssz_enabled.load(Ordering::SeqCst)
165+
self.disable_ssz && self.ssz_used.load(Ordering::SeqCst)
156166
}
157167

158168
async fn get_with_timeout<T: DeserializeOwned, U: IntoUrl>(
@@ -366,8 +376,12 @@ impl BuilderHttpClient {
366376
.push(pubkey.as_hex_string().as_str());
367377

368378
let mut headers = HeaderMap::new();
369-
// We accept ssz responses by default so indicate that in the accept header
370-
headers.insert(ACCEPT, HeaderValue::from_static(PREFERENCE_ACCEPT_VALUE));
379+
if self.disable_ssz {
380+
headers.insert(ACCEPT, HeaderValue::from_static(JSON_CONTENT_TYPE_HEADER));
381+
} else {
382+
// We accept ssz responses by default so indicate that in the accept header
383+
headers.insert(ACCEPT, HeaderValue::from_static(PREFERENCE_ACCEPT_VALUE));
384+
}
371385

372386
let resp = self
373387
.get_with_header(path, self.timeouts.get_header, headers)

beacon_node/execution_layer/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ pub struct Config {
441441
pub builder_header_timeout: Option<Duration>,
442442
/// User agent to send with requests to the builder API.
443443
pub builder_user_agent: Option<String>,
444+
/// Disable ssz requests on builder. Only use json.
445+
pub disable_builder_ssz_requests: bool,
444446
/// JWT secret for the above endpoint running the engine api.
445447
pub secret_file: Option<PathBuf>,
446448
/// The default fee recipient to use on the beacon node if none if provided from
@@ -470,6 +472,7 @@ impl<E: EthSpec> ExecutionLayer<E> {
470472
builder_url,
471473
builder_user_agent,
472474
builder_header_timeout,
475+
disable_builder_ssz_requests,
473476
secret_file,
474477
suggested_fee_recipient,
475478
jwt_id,
@@ -539,7 +542,12 @@ impl<E: EthSpec> ExecutionLayer<E> {
539542
};
540543

541544
if let Some(builder_url) = builder_url {
542-
el.set_builder_url(builder_url, builder_user_agent, builder_header_timeout)?;
545+
el.set_builder_url(
546+
builder_url,
547+
builder_user_agent,
548+
builder_header_timeout,
549+
disable_builder_ssz_requests,
550+
)?;
543551
}
544552

545553
Ok(el)
@@ -562,11 +570,13 @@ impl<E: EthSpec> ExecutionLayer<E> {
562570
builder_url: SensitiveUrl,
563571
builder_user_agent: Option<String>,
564572
builder_header_timeout: Option<Duration>,
573+
disable_ssz: bool,
565574
) -> Result<(), Error> {
566575
let builder_client = BuilderHttpClient::new(
567576
builder_url.clone(),
568577
builder_user_agent,
569578
builder_header_timeout,
579+
disable_ssz,
570580
)
571581
.map_err(Error::Builder)?;
572582
info!(

beacon_node/src/cli.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,15 @@ pub fn cli_app() -> Command {
14601460
.action(ArgAction::Set)
14611461
.display_order(0)
14621462
)
1463+
.arg(
1464+
Arg::new("builder-disable-ssz")
1465+
.long("builder-disable-ssz")
1466+
.value_name("BOOLEAN")
1467+
.help("Disables sending requests using ssz over the builder api")
1468+
.requires("builder")
1469+
.action(ArgAction::SetTrue)
1470+
.display_order(0)
1471+
)
14631472
.arg(
14641473
Arg::new("reset-payload-statuses")
14651474
.long("reset-payload-statuses")

beacon_node/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ pub fn get_config<E: EthSpec>(
346346
el_config.builder_header_timeout =
347347
clap_utils::parse_optional(cli_args, "builder-header-timeout")?
348348
.map(Duration::from_millis);
349+
350+
el_config.disable_builder_ssz_requests = cli_args.get_flag("builder-disable-ssz");
349351
}
350352

351353
// Set config values from parse values.

0 commit comments

Comments
 (0)