diff --git a/beacon_node/beacon_chain/src/test_utils.rs b/beacon_node/beacon_chain/src/test_utils.rs index 720e261e25..8e2ec11833 100644 --- a/beacon_node/beacon_chain/src/test_utils.rs +++ b/beacon_node/beacon_chain/src/test_utils.rs @@ -469,6 +469,7 @@ where execution_endpoint: url, secret_file: None, suggested_fee_recipient: Some(Address::repeat_byte(42)), + bypass_new_payload_cache: true, ..Default::default() }; let execution_layer = diff --git a/beacon_node/beacon_chain/tests/payload_invalidation.rs b/beacon_node/beacon_chain/tests/payload_invalidation.rs index da5a3fbca1..5bd43835e3 100644 --- a/beacon_node/beacon_chain/tests/payload_invalidation.rs +++ b/beacon_node/beacon_chain/tests/payload_invalidation.rs @@ -279,8 +279,6 @@ impl InvalidPayloadRig { } else { mock_execution_layer.server.full_payload_verification(); } - // wait for the new payload cache to timeout - tokio::time::sleep(std::time::Duration::from_secs(12)).await; let root = self .harness .process_block(slot, block.canonical_root(), (block.clone(), blobs.clone())) diff --git a/beacon_node/execution_layer/src/lib.rs b/beacon_node/execution_layer/src/lib.rs index 5b0a86d34b..870897b04d 100644 --- a/beacon_node/execution_layer/src/lib.rs +++ b/beacon_node/execution_layer/src/lib.rs @@ -551,7 +551,7 @@ struct Inner { /// Cache for deduplicating `notify_new_payload` requests. /// /// Handles both in-flight requests and recently completed requests. - new_payload_cache: NewPayloadCache, + new_payload_cache: Option, } #[derive(Debug, Default, Clone, Serialize, Deserialize)] @@ -579,6 +579,8 @@ pub struct Config { /// Default directory for the jwt secret if not provided through cli. pub default_datadir: PathBuf, pub execution_timeout_multiplier: Option, + /// Whether to bypass the new payload cache (useful for testing). + pub bypass_new_payload_cache: bool, } /// Provides access to one execution engine and provides a neat interface for consumption by the @@ -603,6 +605,7 @@ impl ExecutionLayer { jwt_version, default_datadir, execution_timeout_multiplier, + bypass_new_payload_cache, } = config; let execution_url = url.ok_or(Error::NoEngine)?; @@ -647,6 +650,12 @@ impl ExecutionLayer { Engine::new(api, executor.clone()) }; + let new_payload_cache = if !bypass_new_payload_cache { + Some(NewPayloadCache::new()) + } else { + None + }; + let inner = Inner { engine: Arc::new(engine), builder: ArcSwapOption::empty(), @@ -658,7 +667,7 @@ impl ExecutionLayer { executor, payload_cache: PayloadCache::default(), last_new_payload_errored: RwLock::new(false), - new_payload_cache: NewPayloadCache::new(), + new_payload_cache, }; let el = Self { @@ -1485,12 +1494,15 @@ impl ExecutionLayer { ) -> Result { let block_hash = new_payload_request.block_hash(); - self.inner - .new_payload_cache - .get_or_execute(block_hash, || { - self.notify_new_payload_impl(new_payload_request) - }) - .await + if let Some(new_payload_cache) = &self.inner.new_payload_cache { + new_payload_cache + .get_or_execute(block_hash, || { + self.notify_new_payload_impl(new_payload_request) + }) + .await + } else { + self.notify_new_payload_impl(new_payload_request).await + } } /// Internal implementation of notify_new_payload without deduplication logic. diff --git a/beacon_node/execution_layer/src/test_utils/mock_execution_layer.rs b/beacon_node/execution_layer/src/test_utils/mock_execution_layer.rs index 73c998956c..a4bc605b72 100644 --- a/beacon_node/execution_layer/src/test_utils/mock_execution_layer.rs +++ b/beacon_node/execution_layer/src/test_utils/mock_execution_layer.rs @@ -76,6 +76,7 @@ impl MockExecutionLayer { execution_endpoint: Some(url), secret_file: Some(path), suggested_fee_recipient: Some(Address::repeat_byte(42)), + bypass_new_payload_cache: true, ..Default::default() }; let el = ExecutionLayer::from_config(config, executor.clone()).unwrap(); diff --git a/beacon_node/http_api/tests/status_tests.rs b/beacon_node/http_api/tests/status_tests.rs index eece628b32..556b75cb85 100644 --- a/beacon_node/http_api/tests/status_tests.rs +++ b/beacon_node/http_api/tests/status_tests.rs @@ -134,9 +134,6 @@ async fn el_error_on_new_payload() { assert!(!api_response.is_optimistic); assert!(!api_response.is_syncing); - // sleep for just past the cache TTL - tokio::time::sleep(std::time::Duration::from_secs(12)).await; - // Processing a block successfully should remove the status. mock_el.server.set_new_payload_status( block_hash, diff --git a/testing/execution_engine_integration/src/test_rig.rs b/testing/execution_engine_integration/src/test_rig.rs index 72a38230ad..43b2718d00 100644 --- a/testing/execution_engine_integration/src/test_rig.rs +++ b/testing/execution_engine_integration/src/test_rig.rs @@ -136,6 +136,7 @@ impl TestRig { secret_file: None, suggested_fee_recipient: Some(Address::repeat_byte(42)), default_datadir: execution_engine.datadir(), + bypass_new_payload_cache: true, ..Default::default() }; let execution_layer = ExecutionLayer::from_config(config, executor.clone()).unwrap(); @@ -154,6 +155,7 @@ impl TestRig { secret_file: None, suggested_fee_recipient: fee_recipient, default_datadir: execution_engine.datadir(), + bypass_new_payload_cache: true, ..Default::default() }; let execution_layer = ExecutionLayer::from_config(config, executor).unwrap(); @@ -463,14 +465,6 @@ impl TestRig { // TODO: again think about forks here let mut invalid_payload = valid_payload.clone(); - // reverse the block hash to bypass the new payload cache - let reversed: [u8; 32] = { - let mut arr = [0; 32]; - arr.copy_from_slice(invalid_payload.block_hash().0.as_slice()); - arr.reverse(); - arr - }; - *invalid_payload.block_hash_mut().0 = reversed; *invalid_payload.prev_randao_mut() = Hash256::from_low_u64_be(42); let status = self .ee_a