mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 09:08:05 -05:00
fix: return zero latestValidHash pre-merge (#1677)
This commit is contained in:
@@ -4,7 +4,7 @@ use reth_interfaces::consensus::ForkchoiceState;
|
||||
use reth_primitives::{
|
||||
proofs::{self, EMPTY_LIST_HASH},
|
||||
BlockHash, BlockId, BlockNumber, ChainSpec, Hardfork, Header, SealedBlock, TransactionSigned,
|
||||
H64, U256,
|
||||
H256, H64, U256,
|
||||
};
|
||||
use reth_provider::{
|
||||
BlockExecutor, BlockProvider, EvmEnvProvider, ExecutorFactory, HeaderProvider,
|
||||
@@ -257,6 +257,9 @@ impl<Client: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvi
|
||||
/// state in the block header, then passes validation data back to Consensus layer, that
|
||||
/// adds the block to the head of its own blockchain and attests to it. The block is then
|
||||
/// broadcasted over the consensus p2p network in the form of a "Beacon block".
|
||||
///
|
||||
/// These responses should adhere to the [Engine API Spec for
|
||||
/// `engine_newPayload`](https://github.com/ethereum/execution-apis/blob/main/src/engine/paris.md#specification).
|
||||
pub fn new_payload(&mut self, payload: ExecutionPayload) -> EngineApiResult<PayloadStatus> {
|
||||
let block = match self.try_construct_block(payload) {
|
||||
Ok(b) => b,
|
||||
@@ -289,9 +292,22 @@ impl<Client: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvi
|
||||
|
||||
// Short circuit the check by passing parent total difficulty.
|
||||
if !self.chain_spec.fork(Hardfork::Paris).active_at_ttd(parent_td, U256::ZERO) {
|
||||
// This case returns a `latestValidHash` of zero because it is required by the engine
|
||||
// api spec:
|
||||
//
|
||||
// Client software MUST respond to this method call in the following way:
|
||||
// {
|
||||
// status: INVALID,
|
||||
// latestValidHash:
|
||||
// 0x0000000000000000000000000000000000000000000000000000000000000000,
|
||||
// validationError: errorMessage | null
|
||||
// }
|
||||
//
|
||||
// if terminal block conditions are not satisfied
|
||||
return Ok(PayloadStatus::from_status(PayloadStatusEnum::Invalid {
|
||||
validation_error: EngineApiError::PayloadPreMerge.to_string(),
|
||||
}))
|
||||
})
|
||||
.with_latest_valid_hash(H256::zero()))
|
||||
}
|
||||
|
||||
if block.timestamp <= parent.timestamp {
|
||||
@@ -646,7 +662,8 @@ mod tests {
|
||||
|
||||
let expected_result = PayloadStatus::from_status(PayloadStatusEnum::Invalid {
|
||||
validation_error: EngineApiError::PayloadPreMerge.to_string(),
|
||||
});
|
||||
})
|
||||
.with_latest_valid_hash(H256::zero());
|
||||
assert_matches!(result_rx.await, Ok(Ok(result)) => assert_eq!(result, expected_result));
|
||||
}
|
||||
|
||||
|
||||
@@ -145,6 +145,11 @@ impl PayloadStatus {
|
||||
pub fn from_status(status: PayloadStatusEnum) -> Self {
|
||||
Self { status, latest_valid_hash: None }
|
||||
}
|
||||
|
||||
pub fn with_latest_valid_hash(mut self, latest_valid_hash: H256) -> Self {
|
||||
self.latest_valid_hash = Some(latest_valid_hash);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user