mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
fix: dont include latest valid hash on block hash error (#2523)
This commit is contained in:
@ -485,9 +485,17 @@ where
|
||||
Ok(block) => block,
|
||||
Err(error) => {
|
||||
error!(target: "consensus::engine", ?block_hash, block_number, ?error, "Invalid payload");
|
||||
let latest_valid_hash =
|
||||
self.latest_valid_hash_for_invalid_payload(parent_hash, None);
|
||||
return PayloadStatus::from(error).maybe_latest_valid_hash(latest_valid_hash)
|
||||
|
||||
let mut latest_valid_hash = None;
|
||||
if !error.is_block_hash_mismatch() {
|
||||
// Engine-API rule:
|
||||
// > `latestValidHash: null` if the blockHash validation has failed
|
||||
latest_valid_hash =
|
||||
self.latest_valid_hash_for_invalid_payload(parent_hash, None);
|
||||
}
|
||||
let status = PayloadStatusEnum::from(error);
|
||||
|
||||
return PayloadStatus::new(status, latest_valid_hash)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -208,6 +208,13 @@ pub enum PayloadError {
|
||||
Decode(#[from] reth_rlp::DecodeError),
|
||||
}
|
||||
|
||||
impl PayloadError {
|
||||
/// Returns `true` if the error is caused by invalid extra data.
|
||||
pub fn is_block_hash_mismatch(&self) -> bool {
|
||||
matches!(self, PayloadError::BlockHash { .. })
|
||||
}
|
||||
}
|
||||
|
||||
/// This structure contains a body of an execution payload.
|
||||
///
|
||||
/// See also: <https://github.com/ethereum/execution-apis/blob/6452a6b194d7db269bf1dbd087a267251d3cc7f8/src/engine/shanghai.md#executionpayloadbodyv1>
|
||||
@ -303,17 +310,13 @@ impl Serialize for PayloadStatus {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PayloadError> for PayloadStatus {
|
||||
impl From<PayloadError> for PayloadStatusEnum {
|
||||
fn from(error: PayloadError) -> Self {
|
||||
match error {
|
||||
error @ PayloadError::BlockHash { .. } => {
|
||||
PayloadStatus::from_status(PayloadStatusEnum::InvalidBlockHash {
|
||||
validation_error: error.to_string(),
|
||||
})
|
||||
PayloadStatusEnum::InvalidBlockHash { validation_error: error.to_string() }
|
||||
}
|
||||
_ => PayloadStatus::from_status(PayloadStatusEnum::Invalid {
|
||||
validation_error: error.to_string(),
|
||||
}),
|
||||
_ => PayloadStatusEnum::Invalid { validation_error: error.to_string() },
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -383,6 +386,11 @@ impl PayloadStatusEnum {
|
||||
pub fn is_invalid(&self) -> bool {
|
||||
matches!(self, PayloadStatusEnum::Invalid { .. })
|
||||
}
|
||||
|
||||
/// Returns true if the payload status is invalid block hash.
|
||||
pub fn is_invalid_block_hash(&self) -> bool {
|
||||
matches!(self, PayloadStatusEnum::InvalidBlockHash { .. })
|
||||
}
|
||||
}
|
||||
|
||||
/// Various validation errors
|
||||
|
||||
Reference in New Issue
Block a user