Skip to content

Commit 4c10911

Browse files
Add a flag to always use payloads from builders (#4052)
## Issue Addressed #4040 ## Proposed Changes - Add the `always_prefer_builder_payload` field to `Config` in `beacon_node/client/src/config.rs`. - Add that same field to `Inner` in `beacon_node/execution_layer/src/lib.rs` - Modify the logic for picking the payload in `beacon_node/execution_layer/src/lib.rs` - Add the `always-prefer-builder-payload` flag to the beacon node CLI - Test the new flags in `lighthouse/tests/beacon_node.rs` Co-authored-by: Paul Hauner <[email protected]>
1 parent 5bb635d commit 4c10911

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
lines changed

beacon_node/client/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub struct Config {
7979
pub monitoring_api: Option<monitoring_api::Config>,
8080
pub slasher: Option<slasher::Config>,
8181
pub logger_config: LoggerConfig,
82+
pub always_prefer_builder_payload: bool,
8283
}
8384

8485
impl Default for Config {
@@ -105,6 +106,7 @@ impl Default for Config {
105106
validator_monitor_pubkeys: vec![],
106107
validator_monitor_individual_tracking_threshold: DEFAULT_INDIVIDUAL_TRACKING_THRESHOLD,
107108
logger_config: LoggerConfig::default(),
109+
always_prefer_builder_payload: false,
108110
}
109111
}
110112
}

beacon_node/execution_layer/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ struct Inner<E: EthSpec> {
219219
payload_cache: PayloadCache<E>,
220220
builder_profit_threshold: Uint256,
221221
log: Logger,
222+
always_prefer_builder_payload: bool,
222223
}
223224

224225
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
@@ -241,6 +242,7 @@ pub struct Config {
241242
/// The minimum value of an external payload for it to be considered in a proposal.
242243
pub builder_profit_threshold: u128,
243244
pub execution_timeout_multiplier: Option<u32>,
245+
pub always_prefer_builder_payload: bool,
244246
}
245247

246248
/// Provides access to one execution engine and provides a neat interface for consumption by the
@@ -263,6 +265,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
263265
default_datadir,
264266
builder_profit_threshold,
265267
execution_timeout_multiplier,
268+
always_prefer_builder_payload,
266269
} = config;
267270

268271
if urls.len() > 1 {
@@ -335,6 +338,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
335338
payload_cache: PayloadCache::default(),
336339
builder_profit_threshold: Uint256::from(builder_profit_threshold),
337340
log,
341+
always_prefer_builder_payload,
338342
};
339343

340344
Ok(Self {
@@ -796,7 +800,9 @@ impl<T: EthSpec> ExecutionLayer<T> {
796800

797801
let relay_value = relay.data.message.value;
798802
let local_value = *local.block_value();
799-
if local_value >= relay_value {
803+
if !self.inner.always_prefer_builder_payload
804+
&& local_value >= relay_value
805+
{
800806
info!(
801807
self.log(),
802808
"Local block is more profitable than relay block";

beacon_node/src/cli.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,4 +957,13 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
957957
This is equivalent to --http and --validator-monitor-auto.")
958958
.takes_value(false)
959959
)
960+
.arg(
961+
Arg::with_name("always-prefer-builder-payload")
962+
.long("always-prefer-builder-payload")
963+
.help("If set, the beacon node always uses the payload from the builder instead of the local payload.")
964+
// The builder profit threshold flag is used to provide preference
965+
// to local payloads, therefore it fundamentally conflicts with
966+
// always using the builder.
967+
.conflicts_with("builder-profit-threshold")
968+
)
960969
}

beacon_node/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,11 @@ pub fn get_config<E: EthSpec>(
753753
client_config.chain.optimistic_finalized_sync =
754754
!cli_args.is_present("disable-optimistic-finalized-sync");
755755

756+
// Payload selection configs
757+
if cli_args.is_present("always-prefer-builder-payload") {
758+
client_config.always_prefer_builder_payload = true;
759+
}
760+
756761
Ok(client_config)
757762
}
758763

beacon_node/tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![cfg(test)]
2-
#![recursion_limit = "256"]
2+
#![recursion_limit = "512"]
33

44
use beacon_chain::StateSkipConfig;
55
use node_test_rig::{

lighthouse/tests/beacon_node.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,21 @@ fn trusted_peers_flag() {
340340
});
341341
}
342342

343+
#[test]
344+
fn always_prefer_builder_payload_flag() {
345+
CommandLineTest::new()
346+
.flag("always-prefer-builder-payload", None)
347+
.run_with_zero_port()
348+
.with_config(|config| assert!(config.always_prefer_builder_payload));
349+
}
350+
351+
#[test]
352+
fn no_flag_sets_always_prefer_builder_payload_to_false() {
353+
CommandLineTest::new()
354+
.run_with_zero_port()
355+
.with_config(|config| assert!(!config.always_prefer_builder_payload));
356+
}
357+
343358
// Tests for Eth1 flags.
344359
#[test]
345360
fn dummy_eth1_flag() {

0 commit comments

Comments
 (0)