Skip to content

Commit 4399ee4

Browse files
authored
perf: avoid double signing (#804)
## 📝 Summary Avoid double signing the request when builder is submitting only to regular or only to optimistic relays. ## ✅ I have completed the following steps: * [x] Run `make lint` * [x] Run `make test` * [ ] Added tests (if applicable)
1 parent 49957ea commit 4399ee4

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

crates/rbuilder/src/live_builder/block_output/relay_submit.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ async fn run_submit_to_relays_job(
141141
) -> Option<BuiltBlockInfo> {
142142
let mut res = None;
143143

144-
let (regular_relays, optimistic_relays) =
145-
relays.into_iter().partition(|relay| !relay.optimistic());
144+
let (regular_relays, optimistic_relays) = relays
145+
.into_iter()
146+
.partition::<Vec<_>, _>(|relay| !relay.optimistic());
146147

147148
let mut last_bid_hash = None;
148149
'submit: loop {
@@ -253,20 +254,25 @@ async fn run_submit_to_relays_job(
253254
&block.sealed_block,
254255
);
255256
let (regular_request, optimistic_request) = {
256-
let regular = create_submit_block_request(
257-
&config.signer,
258-
&config.chain_spec,
259-
&slot_data,
260-
&block,
261-
&execution_payload,
262-
)
263-
.inspect_err(|error| {
264-
error!(parent: &submission_span, ?error, "Error creating regular submit block request");
265-
})
266-
.ok();
257+
let mut regular = None;
258+
if optimistic_config.is_none() || !regular_relays.is_empty() {
259+
regular = create_submit_block_request(
260+
&config.signer,
261+
&config.chain_spec,
262+
&slot_data,
263+
&block,
264+
&execution_payload,
265+
)
266+
.inspect_err(|error| {
267+
error!(parent: &submission_span, ?error, "Error creating regular submit block request");
268+
})
269+
.ok();
270+
}
267271

268272
let mut optimistic = None;
269-
if let Some(optimistic_config) = optimistic_config {
273+
if let Some(optimistic_config) =
274+
optimistic_config.filter(|_| !optimistic_relays.is_empty())
275+
{
270276
optimistic = create_submit_block_request(
271277
&optimistic_config.signer,
272278
&config.chain_spec,
@@ -283,7 +289,9 @@ async fn run_submit_to_relays_job(
283289
};
284290

285291
if regular_request.is_none() && optimistic_request.is_none() {
286-
error!(parent: &submission_span, "Unable to construct request from the built block");
292+
let regular_relays_len = regular_relays.len();
293+
let optimistic_relays_len = optimistic_relays.len();
294+
error!(parent: &submission_span, regular_relays_len, optimistic_relays_len, "Unable to construct request from the built block");
287295
continue 'submit;
288296
}
289297

0 commit comments

Comments
 (0)