Skip to content

Commit e331bcf

Browse files
efbigZanCorDX
andauthored
chore: remove separate optimistic signer (#810)
## πŸ“ Summary Remove separate optimistic signer and configuration to allow builder to use only a single signing key for submissions and remove double signing from the hot path. ## βœ… I have completed the following steps: * [x] Run `make lint` * [x] Run `make test` * [ ] Added tests (if applicable) --------- Co-authored-by: Daniel Xifra <[email protected]>
1 parent 6960175 commit e331bcf

File tree

5 files changed

+40
-177
lines changed

5 files changed

+40
-177
lines changed

β€Žcrates/rbuilder/src/live_builder/block_output/relay_submit.rsβ€Ž

Lines changed: 34 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,10 @@ pub trait BlockBuildingSink: std::fmt::Debug + Send + Sync {
107107
pub struct SubmissionConfig {
108108
pub chain_spec: Arc<ChainSpec>,
109109
pub signer: BLSBlockSigner,
110-
111-
pub optimistic_config: Option<OptimisticConfig>,
112110
pub optimistic_v3_config: Option<OptimisticV3Config>,
113111
pub bid_observer: Box<dyn BidObserver + Send + Sync>,
114112
}
115113

116-
/// Configuration for optimistic block submission to relays.
117-
#[derive(Debug, Clone)]
118-
pub struct OptimisticConfig {
119-
pub signer: BLSBlockSigner,
120-
pub max_bid_value: U256,
121-
}
122-
123114
/// Configuration for optimistic V3.
124115
#[derive(Debug, Clone)]
125116
pub struct OptimisticV3Config {
@@ -160,19 +151,6 @@ async fn run_submit_to_relays_job(
160151
.collect::<Vec<_>>(),
161152
);
162153

163-
let (regular_relays, optimistic_relays) = relays
164-
.into_iter()
165-
.partition::<Vec<_>, _>(|relay| !relay.optimistic());
166-
167-
let regular_relays_ids = regular_relays
168-
.iter()
169-
.map(|relay| relay.id())
170-
.collect::<Vec<_>>();
171-
let optimistic_relays_ids = optimistic_relays
172-
.iter()
173-
.map(|relay| relay.id())
174-
.collect::<Vec<_>>();
175-
176154
let mut last_bid_hash = None;
177155
'submit: loop {
178156
tokio::select! {
@@ -210,18 +188,6 @@ async fn run_submit_to_relays_job(
210188
.filter(|o| !o.order.is_tx())
211189
.count();
212190

213-
// Only enable the optimistic config for this block if the bid value is below the max bid value
214-
let optimistic_config = config
215-
.optimistic_config
216-
.as_ref()
217-
.and_then(|optimistic_config| {
218-
if block.trace.bid_value < optimistic_config.max_bid_value {
219-
Some(optimistic_config)
220-
} else {
221-
None
222-
}
223-
});
224-
225191
// SAFETY: UNIX timestamp in nanos won't exceed u64::MAX until year 2554
226192
let sequence = OffsetDateTime::now_utc().unix_timestamp_nanos() as u64;
227193
let executed_orders = block
@@ -254,8 +220,7 @@ async fn run_submit_to_relays_job(
254220
gas = block.sealed_block.gas_used,
255221
block_id = block.trace.build_block_id.0,
256222
builder_name = block.builder_name,
257-
regular_relays_ids = ?regular_relays_ids,
258-
optimistic_relays_ids = ?optimistic_relays_ids,
223+
?relay_set
259224
);
260225
info!(
261226
parent: &submission_span,
@@ -280,99 +245,49 @@ async fn run_submit_to_relays_job(
280245
latency_ms = latency.whole_milliseconds(),
281246
"Submitting bid",
282247
);
283-
inc_initiated_submissions(optimistic_config.is_some());
248+
inc_initiated_submissions();
284249

285250
let execution_payload = block_to_execution_payload(
286251
&config.chain_spec,
287252
&slot_data.payload_attributes_event.data,
288253
&block.sealed_block,
289254
);
290-
let (regular_request, optimistic_request) = {
291-
let mut regular = None;
292-
if optimistic_config.is_none() || !regular_relays.is_empty() {
293-
regular = create_submit_block_request(
294-
&config.signer,
295-
&config.chain_spec,
296-
&slot_data,
297-
&block,
298-
&execution_payload,
299-
)
300-
.inspect_err(|error| {
301-
error!(parent: &submission_span, ?error, "Error creating regular submit block request");
302-
})
303-
.ok();
304-
}
305-
306-
let mut optimistic = None;
307-
if let Some(optimistic_config) =
308-
optimistic_config.filter(|_| !optimistic_relays.is_empty())
309-
{
310-
optimistic = create_submit_block_request(
311-
&optimistic_config.signer,
312-
&config.chain_spec,
313-
&slot_data,
314-
&block,
315-
&execution_payload,
316-
).inspect_err(|error| {
317-
error!(parent: &submission_span, ?error, "Error creating optimistic submit block request");
318-
})
319-
.ok();
255+
let request = match create_submit_block_request(
256+
&config.signer,
257+
&config.chain_spec,
258+
&slot_data,
259+
&block,
260+
&execution_payload,
261+
) {
262+
Ok(request) => request,
263+
Err(error) => {
264+
error!(parent: &submission_span, ?error, "Error creating submit block request");
265+
continue 'submit;
320266
}
321-
322-
(regular, optimistic)
323267
};
324268

325-
if regular_request.is_none() && optimistic_request.is_none() {
326-
let regular_relays_len = regular_relays.len();
327-
let optimistic_relays_len = optimistic_relays.len();
328-
error!(parent: &submission_span, regular_relays_len, optimistic_relays_len, "Unable to construct request from the built block");
329-
continue 'submit;
330-
}
331-
332269
mark_submission_start_time(block.trace.orders_sealed_at);
333-
if let Some(request) = &regular_request {
334-
submit_block_to_relays(
335-
request.clone(),
336-
&bid_metadata,
337-
&block.bid_adjustments,
338-
&regular_relays,
339-
&slot_data.relay_registrations,
340-
false,
341-
&config.optimistic_v3_config,
342-
&submission_span,
343-
&cancel,
344-
)
345-
}
270+
submit_block_to_relays(
271+
request.clone(),
272+
&bid_metadata,
273+
&block.bid_adjustments,
274+
&relays,
275+
&slot_data.relay_registrations,
276+
&config.optimistic_v3_config,
277+
&submission_span,
278+
&cancel,
279+
);
346280

347-
let optimistic_request = optimistic_request
348-
.map(|req| (req, true))
349-
// non-optimistic submission to optimistic relays
350-
.or(regular_request.map(|req| (req, false)));
351-
if let Some((request, optimistic)) = optimistic_request {
352-
submit_block_to_relays(
353-
request.clone(),
354-
&bid_metadata,
355-
&block.bid_adjustments,
356-
&optimistic_relays,
357-
&slot_data.relay_registrations,
358-
optimistic,
359-
&config.optimistic_v3_config,
360-
&submission_span,
361-
&cancel,
281+
submission_span.in_scope(|| {
282+
config.bid_observer.block_submitted(
283+
&slot_data,
284+
request,
285+
Arc::new(block.trace),
286+
builder_name,
287+
bid_metadata.value.top_competitor_bid.unwrap_or_default(),
288+
&relay_set,
362289
);
363-
364-
submission_span.in_scope(|| {
365-
// NOTE: we only notify normal submission here because they have the same contents but different pubkeys
366-
config.bid_observer.block_submitted(
367-
&slot_data,
368-
request,
369-
Arc::new(block.trace),
370-
builder_name,
371-
bid_metadata.value.top_competitor_bid.unwrap_or_default(),
372-
&relay_set,
373-
);
374-
})
375-
}
290+
});
376291
}
377292
}
378293

@@ -473,7 +388,6 @@ fn submit_block_to_relays(
473388
bid_adjustments: &std::collections::HashMap<Address, BidAdjustmentData>,
474389
relays: &Vec<MevBoostRelayBidSubmitter>,
475390
registrations: &HashMap<MevBoostRelayID, RelaySlotData>,
476-
optimistic: bool,
477391
optimistic_v3_config: &Option<OptimisticV3Config>,
478392
submission_span: &Span,
479393
cancel: &CancellationToken,
@@ -530,8 +444,7 @@ fn submit_block_to_relays(
530444
metadata: bid_metadata.clone(),
531445
};
532446

533-
let span =
534-
info_span!(parent: submission_span, "relay_submit", relay = &relay.id(), optimistic);
447+
let span = info_span!(parent: submission_span, "relay_submit", relay = &relay.id());
535448
let relay = relay.clone();
536449
let cancel = cancel.clone();
537450
tokio::spawn(
@@ -541,7 +454,6 @@ fn submit_block_to_relays(
541454
submission,
542455
optimistic_v3,
543456
registration.registration,
544-
optimistic,
545457
cancel,
546458
)
547459
.await;
@@ -556,7 +468,6 @@ async fn submit_bid_to_the_relay(
556468
submit_block_request: SubmitBlockRequestWithMetadata,
557469
optimistic_v3_request: Option<(OptimisticV3Config, SubmitHeaderRequestWithMetadata)>,
558470
registration: ValidatorSlotData,
559-
optimistic: bool,
560471
cancel: CancellationToken,
561472
) {
562473
let submit_start = Instant::now();
@@ -591,7 +502,7 @@ async fn submit_bid_to_the_relay(
591502
Ok(()) => {
592503
trace!("Block submitted to the relay successfully");
593504
add_relay_submit_time(relay.id(), submit_time);
594-
inc_relay_accepted_submissions(relay.id(), optimistic);
505+
inc_relay_accepted_submissions(relay.id(), relay.optimistic());
595506
}
596507
Err(SubmitBlockErr::PayloadDelivered | SubmitBlockErr::PastSlot) => {
597508
trace!("Block already delivered by the relay, cancelling");

β€Žcrates/rbuilder/src/live_builder/config.rsβ€Ž

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::{
77
bidding_service_interface::{
88
BidObserver, BiddingService, LandedBlockInfo, NullBidObserver,
99
},
10-
relay_submit::{OptimisticConfig, RelaySubmitSinkFactory, SubmissionConfig},
10+
relay_submit::{RelaySubmitSinkFactory, SubmissionConfig},
1111
true_value_bidding_service::NewTrueBlockValueBiddingService,
1212
unfinished_block_processing::UnfinishedBuiltBlocksInputFactory,
1313
},
@@ -50,10 +50,7 @@ use crate::{
5050
utils::{build_info::rbuilder_version, ProviderFactoryReopener, Signer},
5151
};
5252
use alloy_chains::ChainKind;
53-
use alloy_primitives::{
54-
utils::{format_ether, parse_ether},
55-
Address, FixedBytes, B256, U256,
56-
};
53+
use alloy_primitives::{utils::parse_ether, Address, FixedBytes, B256, U256};
5754
use alloy_rpc_types_beacon::BlsPublicKey;
5855
use bid_scraper::config::NamedPublisherConfig;
5956
use ethereum_consensus::{
@@ -158,13 +155,6 @@ pub struct L1Config {
158155
pub registration_update_interval_ms: Option<u64>,
159156
/// Secret key that will be used to sign normal submissions to the relay.
160157
relay_secret_key: Option<EnvOrValue<String>>,
161-
/// Secret key that will be used to sign optimistic submissions to the relay.
162-
optimistic_relay_secret_key: EnvOrValue<String>,
163-
/// When enabled builer will make optimistic submissions to optimistic relays
164-
/// influenced by `optimistic_max_bid_value_eth`
165-
pub optimistic_enabled: bool,
166-
/// Bids above this value will always be submitted in non-optimistic mode.
167-
pub optimistic_max_bid_value_eth: String,
168158

169159
/// Name kept singular for backwards compatibility
170160
#[serde_as(deserialize_as = "OneOrMany<EnvOrValue<String>>")]
@@ -192,9 +182,6 @@ impl Default for L1Config {
192182
relays: vec![],
193183
enabled_relays: vec![],
194184
relay_secret_key: None,
195-
optimistic_relay_secret_key: "".into(),
196-
optimistic_enabled: false,
197-
optimistic_max_bid_value_eth: "0.0".to_string(),
198185
cl_node_url: vec![EnvOrValue::from("http://127.0.0.1:3500")],
199186
genesis_fork_version: None,
200187
relay_bid_scrapers: Default::default(),
@@ -358,28 +345,9 @@ impl L1Config {
358345
let signer = BLSBlockSigner::new(relay_secret_key, signing_domain)
359346
.map_err(|e| eyre::eyre!("Failed to create normal signer: {:?}", e))?;
360347

361-
let optimistic_signer = if self.optimistic_enabled {
362-
BLSBlockSigner::from_string(self.optimistic_relay_secret_key.value()?, signing_domain)
363-
.map_err(|e| eyre::eyre!("Failed to create optimistic signer: {:?}", e))?
364-
} else {
365-
// Placeholder value since it is required for SubmissionConfig. But after https://github.com/flashbots/rbuilder/pull/323
366-
// we can return None
367-
signer.clone()
368-
};
369-
370-
let optimistic_config = if self.optimistic_enabled {
371-
Some(OptimisticConfig {
372-
signer: optimistic_signer,
373-
max_bid_value: parse_ether(&self.optimistic_max_bid_value_eth)?,
374-
})
375-
} else {
376-
None
377-
};
378-
379348
Ok(SubmissionConfig {
380349
chain_spec,
381350
signer,
382-
optimistic_config,
383351
optimistic_v3_config,
384352
bid_observer,
385353
})
@@ -442,18 +410,10 @@ impl L1Config {
442410
optimistic_v3_config,
443411
)?;
444412
info!(
445-
"Builder mev boost normal relay pubkey: {:?}",
413+
"Builder mev boost relay pubkey: {:?}",
446414
submission_config.signer.pub_key()
447415
);
448416

449-
if let Some(optimitic_config) = submission_config.optimistic_config.as_ref() {
450-
info!(
451-
"Optimistic mode enabled, relay pubkey {:?}, max_value: {}",
452-
optimitic_config.signer.pub_key(),
453-
format_ether(optimitic_config.max_bid_value),
454-
);
455-
};
456-
457417
let (submitters, slot_info_providers) = self.create_relays()?;
458418
if slot_info_providers.is_empty() {
459419
eyre::bail!("No slot info providers provided");

β€Žcrates/rbuilder/src/live_builder/testdata/config_with_relay_override.tomlβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ reth_datadir = "/mnt/data/reth"
1010

1111
coinbase_secret_key = "env:COINBASE_SECRET_KEY"
1212
relay_secret_key = "env:RELAY_SECRET_KEY"
13-
optimistic_relay_secret_key = "env:OPTIMISTIC_RELAY_SECRET_KEY"
1413

1514
# cl_node_url can be a single value, array of values, or passed by an environment variables with values separated with a comma
1615
# cl_node_url = "http://localhost:3500"

β€Žcrates/rbuilder/src/telemetry/metrics/mod.rsβ€Ž

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,11 @@ register_metrics! {
209209
IntCounter::new("simulation_gas_used", "Simulation gas used").unwrap();
210210
pub static ACTIVE_SLOTS: IntCounter =
211211
IntCounter::new("active_slots", "Slots when builder was active").unwrap();
212-
pub static INITIATED_SUBMISSIONS: IntCounterVec = IntCounterVec::new(
213-
Opts::new(
212+
pub static INITIATED_SUBMISSIONS: IntCounter = IntCounter::new(
214213
"initiated_submissions",
215214
"Number of initiated submissions to the relays"
216-
),
217-
&["optimistic"],
218215
)
219216
.unwrap();
220-
221217
pub static RELAY_SUBMIT_TIME: HistogramVec = HistogramVec::new(
222218
HistogramOpts::new("relay_submit_time", "Time to send bid to the relay (ms)")
223219
.buckets(exponential_buckets_range(0.5, 3000.0, 50)),
@@ -567,10 +563,8 @@ pub fn inc_active_slots() {
567563
ACTIVE_SLOTS.inc();
568564
}
569565

570-
pub fn inc_initiated_submissions(optimistic: bool) {
571-
INITIATED_SUBMISSIONS
572-
.with_label_values(&[&optimistic.to_string()])
573-
.inc();
566+
pub fn inc_initiated_submissions() {
567+
INITIATED_SUBMISSIONS.inc();
574568
}
575569

576570
pub fn add_relay_submit_time(relay: &MevBoostRelayID, duration: Duration) {

β€Žexamples/config/rbuilder/config-live-example.tomlβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ reth_datadir = "/mnt/data/reth"
1111

1212
coinbase_secret_key = "env:COINBASE_SECRET_KEY"
1313
relay_secret_key = "env:RELAY_SECRET_KEY"
14-
optimistic_relay_secret_key = "env:OPTIMISTIC_RELAY_SECRET_KEY"
1514

1615
# cl_node_url can be a single value, array of values, or passed by an environment variables with values separated with a comma
1716
# cl_node_url = "http://localhost:3500"

0 commit comments

Comments
Β (0)