Skip to content

Commit 77e1c67

Browse files
committed
Added Flag to Bypass New Payload Cache
1 parent ef1aa6b commit 77e1c67

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

beacon_node/beacon_chain/src/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ where
469469
execution_endpoint: url,
470470
secret_file: None,
471471
suggested_fee_recipient: Some(Address::repeat_byte(42)),
472+
bypass_new_payload_cache: true,
472473
..Default::default()
473474
};
474475
let execution_layer =

beacon_node/beacon_chain/tests/payload_invalidation.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,6 @@ impl InvalidPayloadRig {
279279
} else {
280280
mock_execution_layer.server.full_payload_verification();
281281
}
282-
// wait for the new payload cache to timeout
283-
tokio::time::sleep(std::time::Duration::from_secs(12)).await;
284282
let root = self
285283
.harness
286284
.process_block(slot, block.canonical_root(), (block.clone(), blobs.clone()))

beacon_node/execution_layer/src/lib.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ struct Inner<E: EthSpec> {
551551
/// Cache for deduplicating `notify_new_payload` requests.
552552
///
553553
/// Handles both in-flight requests and recently completed requests.
554-
new_payload_cache: NewPayloadCache,
554+
new_payload_cache: Option<NewPayloadCache>,
555555
}
556556

557557
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
@@ -579,6 +579,8 @@ pub struct Config {
579579
/// Default directory for the jwt secret if not provided through cli.
580580
pub default_datadir: PathBuf,
581581
pub execution_timeout_multiplier: Option<u32>,
582+
/// Whether to bypass the new payload cache (useful for testing).
583+
pub bypass_new_payload_cache: bool,
582584
}
583585

584586
/// Provides access to one execution engine and provides a neat interface for consumption by the
@@ -603,6 +605,7 @@ impl<E: EthSpec> ExecutionLayer<E> {
603605
jwt_version,
604606
default_datadir,
605607
execution_timeout_multiplier,
608+
bypass_new_payload_cache,
606609
} = config;
607610

608611
let execution_url = url.ok_or(Error::NoEngine)?;
@@ -647,6 +650,12 @@ impl<E: EthSpec> ExecutionLayer<E> {
647650
Engine::new(api, executor.clone())
648651
};
649652

653+
let new_payload_cache = if !bypass_new_payload_cache {
654+
Some(NewPayloadCache::new())
655+
} else {
656+
None
657+
};
658+
650659
let inner = Inner {
651660
engine: Arc::new(engine),
652661
builder: ArcSwapOption::empty(),
@@ -658,7 +667,7 @@ impl<E: EthSpec> ExecutionLayer<E> {
658667
executor,
659668
payload_cache: PayloadCache::default(),
660669
last_new_payload_errored: RwLock::new(false),
661-
new_payload_cache: NewPayloadCache::new(),
670+
new_payload_cache,
662671
};
663672

664673
let el = Self {
@@ -1485,12 +1494,15 @@ impl<E: EthSpec> ExecutionLayer<E> {
14851494
) -> Result<PayloadStatus, Error> {
14861495
let block_hash = new_payload_request.block_hash();
14871496

1488-
self.inner
1489-
.new_payload_cache
1490-
.get_or_execute(block_hash, || {
1491-
self.notify_new_payload_impl(new_payload_request)
1492-
})
1493-
.await
1497+
if let Some(new_payload_cache) = &self.inner.new_payload_cache {
1498+
new_payload_cache
1499+
.get_or_execute(block_hash, || {
1500+
self.notify_new_payload_impl(new_payload_request)
1501+
})
1502+
.await
1503+
} else {
1504+
self.notify_new_payload_impl(new_payload_request).await
1505+
}
14941506
}
14951507

14961508
/// Internal implementation of notify_new_payload without deduplication logic.

beacon_node/execution_layer/src/test_utils/mock_execution_layer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ impl<E: EthSpec> MockExecutionLayer<E> {
7676
execution_endpoint: Some(url),
7777
secret_file: Some(path),
7878
suggested_fee_recipient: Some(Address::repeat_byte(42)),
79+
bypass_new_payload_cache: true,
7980
..Default::default()
8081
};
8182
let el = ExecutionLayer::from_config(config, executor.clone()).unwrap();

beacon_node/http_api/tests/status_tests.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ async fn el_error_on_new_payload() {
134134
assert!(!api_response.is_optimistic);
135135
assert!(!api_response.is_syncing);
136136

137-
// sleep for just past the cache TTL
138-
tokio::time::sleep(std::time::Duration::from_secs(12)).await;
139-
140137
// Processing a block successfully should remove the status.
141138
mock_el.server.set_new_payload_status(
142139
block_hash,

testing/execution_engine_integration/src/test_rig.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ impl<Engine: GenericExecutionEngine> TestRig<Engine> {
136136
secret_file: None,
137137
suggested_fee_recipient: Some(Address::repeat_byte(42)),
138138
default_datadir: execution_engine.datadir(),
139+
bypass_new_payload_cache: true,
139140
..Default::default()
140141
};
141142
let execution_layer = ExecutionLayer::from_config(config, executor.clone()).unwrap();
@@ -154,6 +155,7 @@ impl<Engine: GenericExecutionEngine> TestRig<Engine> {
154155
secret_file: None,
155156
suggested_fee_recipient: fee_recipient,
156157
default_datadir: execution_engine.datadir(),
158+
bypass_new_payload_cache: true,
157159
..Default::default()
158160
};
159161
let execution_layer = ExecutionLayer::from_config(config, executor).unwrap();
@@ -463,14 +465,6 @@ impl<Engine: GenericExecutionEngine> TestRig<Engine> {
463465

464466
// TODO: again think about forks here
465467
let mut invalid_payload = valid_payload.clone();
466-
// reverse the block hash to bypass the new payload cache
467-
let reversed: [u8; 32] = {
468-
let mut arr = [0; 32];
469-
arr.copy_from_slice(invalid_payload.block_hash().0.as_slice());
470-
arr.reverse();
471-
arr
472-
};
473-
*invalid_payload.block_hash_mut().0 = reversed;
474468
*invalid_payload.prev_randao_mut() = Hash256::from_low_u64_be(42);
475469
let status = self
476470
.ee_a

0 commit comments

Comments
 (0)