Skip to content

Commit fe99a06

Browse files
authored
Fast relay concept is split between fast and independent (#605)
## 📝 Summary - new flag "is_independent" for relays. - "fast_bid_threshold_eth" renamed to "independent_bid_threshold_eth" - Critical blocks (containing bundles with replacement ids) go only to fast relays. None -> true - Big blocks (bid > independent_bid_threshold_eth) go only to independent relays. None -> true ## ✅ I have completed the following steps: * [X] Run `make lint` * [X] Run `make test` * [ ] Added tests (if applicable)
1 parent 545a69d commit fe99a06

File tree

5 files changed

+74
-22
lines changed

5 files changed

+74
-22
lines changed

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

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub struct SubmissionConfig {
105105
pub optimistic_config: Option<OptimisticConfig>,
106106
pub bid_observer: Box<dyn BidObserver + Send + Sync>,
107107
/// Bids above this value will only go to fast relays.
108-
pub fast_bid_threshold: U256,
108+
pub independent_bid_threshold: U256,
109109
}
110110

111111
/// Configuration for optimistic block submission to relays.
@@ -244,8 +244,11 @@ async fn run_submit_to_relays_job(
244244
parent: &submission_span,
245245
"Submitting bid",
246246
);
247-
let send_to_slow_relays = can_send_to_slow_relay(&block, config.fast_bid_threshold);
248-
inc_initiated_submissions(optimistic_config.is_some(), send_to_slow_relays);
247+
let relay_filter = get_relay_filter_and_update_metrics(
248+
&block,
249+
optimistic_config.is_some(),
250+
config.independent_bid_threshold,
251+
);
249252

250253
let (normal_signed_submission, optimistic_signed_submission) = {
251254
let normal_signed_submission = match sign_block_for_relay(
@@ -302,7 +305,7 @@ async fn run_submit_to_relays_job(
302305
submit_block_to_relays(
303306
&normal_relays,
304307
&normal_signed_submission,
305-
send_to_slow_relays,
308+
&relay_filter,
306309
false,
307310
&submission_span,
308311
&cancel,
@@ -312,7 +315,7 @@ async fn run_submit_to_relays_job(
312315
submit_block_to_relays(
313316
&optimistic_relays,
314317
optimistic_signed_submission,
315-
send_to_slow_relays,
318+
&relay_filter,
316319
true,
317320
&submission_span,
318321
&cancel,
@@ -322,7 +325,7 @@ async fn run_submit_to_relays_job(
322325
submit_block_to_relays(
323326
&optimistic_relays,
324327
&normal_signed_submission,
325-
send_to_slow_relays,
328+
&relay_filter,
326329
false,
327330
&submission_span,
328331
&cancel,
@@ -346,13 +349,13 @@ async fn run_submit_to_relays_job(
346349
fn submit_block_to_relays(
347350
relays: &Vec<MevBoostRelayBidSubmitter>,
348351
submission: &SubmitBlockRequestWithMetadata,
349-
send_to_slow_relays: bool,
352+
relay_filter: &impl Fn(&MevBoostRelayBidSubmitter) -> bool,
350353
optimistic: bool,
351354
submission_span: &Span,
352355
cancel: &CancellationToken,
353356
) {
354357
for relay in relays {
355-
if relay.is_fast() || send_to_slow_relays {
358+
if relay_filter(relay) {
356359
let span = info_span!(parent: submission_span, "relay_submit", relay = &relay.id(), optimistic);
357360
let relay = relay.clone();
358361
let cancel = cancel.clone();
@@ -367,9 +370,19 @@ fn submit_block_to_relays(
367370
}
368371
}
369372

370-
/// can send only cheap blocks with no bundle replacement data.
371-
fn can_send_to_slow_relay(block: &Block, fast_bid_threshold: U256) -> bool {
372-
let has_replacement_uuid = block
373+
/// Creates a Fn to decide if the block should go to a relay.
374+
/// The cfg defines 2 flags on relays: fast and independent.
375+
/// If a block has replacement ids it should NOT go to a relay that is not fast since it needs fast cancellations.
376+
/// If a block is expensive it should NOT go to a non independent relay.
377+
fn get_relay_filter_and_update_metrics(
378+
block: &Block,
379+
optimistic: bool,
380+
independent_bid_threshold: U256,
381+
) -> impl Fn(&MevBoostRelayBidSubmitter) -> bool {
382+
// only_independent = expensive blocks.
383+
let only_independent = block.trace.bid_value > independent_bid_threshold;
384+
// only_fast = blocks with replaceable orders.
385+
let only_fast = block
373386
.trace
374387
.included_orders
375388
.iter()
@@ -379,8 +392,16 @@ fn can_send_to_slow_relay(block: &Block, fast_bid_threshold: U256) -> bool {
379392
Order::Tx(_) => false,
380393
Order::ShareBundle(_) => false,
381394
});
382-
let is_expensive_block = block.trace.bid_value > fast_bid_threshold;
383-
!has_replacement_uuid && !is_expensive_block
395+
inc_initiated_submissions(optimistic, !only_fast, !only_independent);
396+
move |relay: &MevBoostRelayBidSubmitter| {
397+
if only_independent && !relay.is_independent() {
398+
return false; // Sorry relay but this block is expensive and you are not independent :(
399+
}
400+
if only_fast && !relay.is_fast() {
401+
return false; // Sorry relay but this block contains replacements and you are slow :(
402+
}
403+
true
404+
}
384405
}
385406

386407
pub async fn run_submit_to_relays_job_and_metrics(

crates/rbuilder/src/live_builder/config.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ pub struct Config {
114114
}
115115

116116
const DEFAULT_SLOT_DELTA_TO_START_BIDDING_MS: i64 = -8000;
117+
const DEFAULT_INDEPENDENT_BID_THRESHOLD_ETH: &str = "0";
117118

118119
#[serde_as]
119120
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
@@ -140,8 +141,8 @@ pub struct L1Config {
140141
/// Genesis fork version for the chain. If not provided it will be fetched from the beacon client.
141142
pub genesis_fork_version: Option<String>,
142143

143-
/// Bids above this value will only go to fast relays.
144-
pub fast_bid_threshold_eth: String,
144+
/// Bids above this value will only go to independent relays.
145+
pub independent_bid_threshold_eth: String,
145146
}
146147

147148
impl Default for L1Config {
@@ -155,7 +156,7 @@ impl Default for L1Config {
155156
optimistic_max_bid_value_eth: "0.0".to_string(),
156157
cl_node_url: vec![EnvOrValue::from("http://127.0.0.1:3500")],
157158
genesis_fork_version: None,
158-
fast_bid_threshold_eth: "0".to_owned(),
159+
independent_bid_threshold_eth: DEFAULT_INDEPENDENT_BID_THRESHOLD_ETH.to_owned(),
159160
}
160161
}
161162
}
@@ -197,6 +198,7 @@ impl L1Config {
197198
submit_config,
198199
relay_config.mode == RelayMode::Test,
199200
relay_config.is_fast(),
201+
relay_config.is_independent(),
200202
));
201203
} else {
202204
eyre::bail!(
@@ -314,7 +316,7 @@ impl L1Config {
314316
signer,
315317
optimistic_config,
316318
bid_observer,
317-
fast_bid_threshold: parse_ether(&self.fast_bid_threshold_eth)?,
319+
independent_bid_threshold: parse_ether(&self.independent_bid_threshold_eth)?,
318320
})
319321
}
320322

@@ -719,6 +721,7 @@ lazy_static! {
719721
builder_id_header: None,
720722
api_token_header: None,
721723
is_fast: None,
724+
is_independent: None,
722725
},
723726
);
724727
map.insert(
@@ -738,6 +741,7 @@ lazy_static! {
738741
builder_id_header: None,
739742
api_token_header: None,
740743
is_fast: None,
744+
is_independent: None,
741745
},
742746
);
743747
map.insert(
@@ -757,6 +761,7 @@ lazy_static! {
757761
builder_id_header: None,
758762
api_token_header: None,
759763
is_fast: None,
764+
is_independent: None,
760765
},
761766
);
762767
map.insert(
@@ -775,6 +780,7 @@ lazy_static! {
775780
builder_id_header: None,
776781
api_token_header: None,
777782
is_fast: None,
783+
is_independent: None,
778784
},
779785
);
780786
map.insert(
@@ -794,6 +800,7 @@ lazy_static! {
794800
builder_id_header: None,
795801
api_token_header: None,
796802
is_fast: None,
803+
is_independent: None,
797804
},
798805
);
799806
map

crates/rbuilder/src/primitives/mev_boost.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ pub struct RelayConfig {
6161
pub submit_config: Option<RelaySubmitConfig>,
6262
/// Deprecated field that is not used
6363
pub priority: Option<usize>,
64-
/// critical blocks go only to fast relays. None -> true
64+
/// Critical blocks (containing bundles with replacement ids) go only to fast relays. None -> true
6565
pub is_fast: Option<bool>,
66+
/// Big blocks (bid > [L1Config::independent_bid_threshold_eth]) go only to independent relays. None -> true
67+
pub is_independent: Option<bool>,
6668
}
6769

6870
const IS_FAST_DEFAULT: bool = true;
71+
const IS_INDEPENDENT_DEFAULT: bool = true;
6972
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Default)]
7073
#[serde(deny_unknown_fields)]
7174
pub struct RelaySubmitConfig {
@@ -98,6 +101,10 @@ impl RelayConfig {
98101
pub fn is_fast(&self) -> bool {
99102
self.is_fast.unwrap_or(IS_FAST_DEFAULT)
100103
}
104+
105+
pub fn is_independent(&self) -> bool {
106+
self.is_independent.unwrap_or(IS_INDEPENDENT_DEFAULT)
107+
}
101108
}
102109

103110
/// Wrapper in RelayClient to submit blocks.
@@ -120,6 +127,7 @@ pub struct MevBoostRelayBidSubmitter {
120127
/// Parameter for the relay
121128
cancellations: bool,
122129
is_fast: bool,
130+
is_independent: bool,
123131
}
124132

125133
impl MevBoostRelayBidSubmitter {
@@ -129,6 +137,7 @@ impl MevBoostRelayBidSubmitter {
129137
config: &RelaySubmitConfig,
130138
test_relay: bool,
131139
is_fast: bool,
140+
is_independent: bool,
132141
) -> Self {
133142
let submission_rate_limiter = config.interval_between_submissions_ms.map(|d| {
134143
Arc::new(RateLimiter::direct(
@@ -145,13 +154,18 @@ impl MevBoostRelayBidSubmitter {
145154
test_relay,
146155
cancellations: true,
147156
is_fast,
157+
is_independent,
148158
}
149159
}
150160

151161
pub fn is_fast(&self) -> bool {
152162
self.is_fast
153163
}
154164

165+
pub fn is_independent(&self) -> bool {
166+
self.is_independent
167+
}
168+
155169
pub fn test_relay(&self) -> bool {
156170
self.test_relay
157171
}

crates/rbuilder/src/telemetry/metrics/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ register_metrics! {
134134
"initiated_submissions",
135135
"Number of initiated submissions to the relays"
136136
),
137-
&["optimistic","sent_to_slow"],
137+
&["optimistic","sent_to_slow","send_to_non_independent"],
138138
)
139139
.unwrap();
140140

@@ -469,9 +469,17 @@ pub fn inc_active_slots() {
469469
ACTIVE_SLOTS.inc();
470470
}
471471

472-
pub fn inc_initiated_submissions(optimistic: bool, sent_to_slow_relays: bool) {
472+
pub fn inc_initiated_submissions(
473+
optimistic: bool,
474+
sent_to_slow_relays: bool,
475+
send_to_non_independent: bool,
476+
) {
473477
INITIATED_SUBMISSIONS
474-
.with_label_values(&[&optimistic.to_string(), &sent_to_slow_relays.to_string()])
478+
.with_label_values(&[
479+
&optimistic.to_string(),
480+
&sent_to_slow_relays.to_string(),
481+
&send_to_non_independent.to_string(),
482+
])
475483
.inc();
476484
}
477485

docs/CONFIG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@ Every field has a default if omitted.
6363
|RelayConfig.use_gzip_for_submit|optional bool||false|
6464
|RelayConfig.optimistic|optional bool||false|
6565
|RelayConfig.interval_between_submissions_ms|optional int| Caps the submission rate to the relay|None|
66+
|RelayConfig.is_fast|optional bool| Critical blocks (the ones containing orders with replacement id) will go only to fast relays.|true|
67+
|RelayConfig.is_independent|optional bool| Big blocks (bid value > independent_bid_threshold_eth) will go only to independent relays.|true|
6668
|enabled_relays| vec["string"]| Extra hardcoded relays to add (see DEFAULT_RELAYS in [config.rs](../crates/rbuilder/src/live_builder/config.rs))|[]|
6769
|relay_secret_key|optional env/string|Secret key that will be used to sign normal submissions to the relay.|None|
6870
|optimistic_relay_secret_key|optional env/string|Secret key that will be used to sign optimistic submissions to the relay.|None|
6971
|optimistic_enabled|bool|When enabled builder will make optimistic submissions to optimistic relays|false|
7072
|optimistic_max_bid_value_eth|string| Bids above this value will always be submitted in non-optimistic mode.|"0.0"|
7173
|cl_node_url|vec[env/stirng]| Array if urls to CL clients to get the new payload events|["http://127.0.0.1:3500"]
7274
|genesis_fork_version|optional string|Genesis fork version for the chain. If not provided it will be fetched from the beacon client.|None|
73-
75+
|independent_bid_threshold_eth|optional string|Bids above this value will only go to independent relays.| "0"|
7476
## Building algorithms
7577
rbuilder can multiple building algorithms and each algorithm can be instantiated multiple times with it's own set of parameters each time.
7678
Each instantiated algorithm starts with:

0 commit comments

Comments
 (0)