diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index 95c2f14be6..ba90a1fbd8 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -2103,16 +2103,16 @@ where /// Prepares the invalid payload response for the given hash, checking the /// database for the parent hash and populating the payload status with the latest valid hash /// according to the engine api spec. - fn prepare_invalid_response(&mut self, mut parent_hash: B256) -> ProviderResult { - // Edge case: the `latestValid` field is the zero hash if the parent block is the terminal - // PoW block, which we need to identify by looking at the parent's block difficulty - if let Some(parent) = self.sealed_header_by_hash(parent_hash)? && - !parent.difficulty().is_zero() - { - parent_hash = B256::ZERO; - } + fn prepare_invalid_response(&mut self, parent_hash: B256) -> ProviderResult { + let valid_parent_hash = match self.sealed_header_by_hash(parent_hash)? { + // Edge case: the `latestValid` field is the zero hash if the parent block is the + // terminal PoW block, which we need to identify by looking at the parent's block + // difficulty + Some(parent) if !parent.difficulty().is_zero() => Some(B256::ZERO), + Some(_) => Some(parent_hash), + None => self.latest_valid_hash_for_invalid_payload(parent_hash)?, + }; - let valid_parent_hash = self.latest_valid_hash_for_invalid_payload(parent_hash)?; Ok(PayloadStatus::from_status(PayloadStatusEnum::Invalid { validation_error: PayloadValidationError::LinksToRejectedPayload.to_string(), })