mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: couple ExecutionPayload and ExecutionPayloadSidecar (#14172)
This commit is contained in:
@ -15,8 +15,7 @@ use alloy_primitives::{
|
||||
BlockNumber, B256, U256,
|
||||
};
|
||||
use alloy_rpc_types_engine::{
|
||||
ExecutionPayload, ExecutionPayloadSidecar, ForkchoiceState, PayloadStatus, PayloadStatusEnum,
|
||||
PayloadValidationError,
|
||||
ForkchoiceState, PayloadStatus, PayloadStatusEnum, PayloadValidationError,
|
||||
};
|
||||
use block_buffer::BlockBuffer;
|
||||
use error::{InsertBlockError, InsertBlockErrorKind, InsertBlockFatalError};
|
||||
@ -29,7 +28,7 @@ use reth_consensus::{Consensus, FullConsensus, PostExecutionInput};
|
||||
pub use reth_engine_primitives::InvalidBlockHook;
|
||||
use reth_engine_primitives::{
|
||||
BeaconConsensusEngineEvent, BeaconEngineMessage, BeaconOnNewPayloadError, EngineTypes,
|
||||
EngineValidator, ForkchoiceStateTracker, OnForkChoiceUpdated,
|
||||
EngineValidator, ExecutionData, ForkchoiceStateTracker, OnForkChoiceUpdated,
|
||||
};
|
||||
use reth_errors::{ConsensusError, ProviderResult};
|
||||
use reth_ethereum_primitives::EthPrimitives;
|
||||
@ -791,7 +790,7 @@ where
|
||||
|
||||
/// When the Consensus layer receives a new block via the consensus gossip protocol,
|
||||
/// the transactions in the block are sent to the execution layer in the form of a
|
||||
/// [`ExecutionPayload`]. The Execution layer executes the transactions and validates the
|
||||
/// [`ExecutionData`]. The Execution layer executes the transactions and validates the
|
||||
/// 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
|
||||
/// broadcast over the consensus p2p network in the form of a "Beacon block".
|
||||
@ -804,8 +803,7 @@ where
|
||||
#[instrument(level = "trace", skip_all, fields(block_hash = %payload.block_hash(), block_num = %payload.block_number(),), target = "engine::tree")]
|
||||
fn on_new_payload(
|
||||
&mut self,
|
||||
payload: ExecutionPayload,
|
||||
sidecar: ExecutionPayloadSidecar,
|
||||
payload: ExecutionData,
|
||||
) -> Result<TreeOutcome<PayloadStatus>, InsertBlockFatalError> {
|
||||
trace!(target: "engine::tree", "invoked new payload");
|
||||
self.metrics.engine.new_payload_messages.increment(1);
|
||||
@ -836,7 +834,7 @@ where
|
||||
//
|
||||
// This validation **MUST** be instantly run in all cases even during active sync process.
|
||||
let parent_hash = payload.parent_hash();
|
||||
let block = match self.payload_validator.ensure_well_formed_payload(payload, sidecar) {
|
||||
let block = match self.payload_validator.ensure_well_formed_payload(payload) {
|
||||
Ok(block) => block,
|
||||
Err(error) => {
|
||||
error!(target: "engine::tree", %error, "Invalid payload");
|
||||
@ -1392,8 +1390,8 @@ where
|
||||
error!(target: "engine::tree", "Failed to send event: {err:?}");
|
||||
}
|
||||
}
|
||||
BeaconEngineMessage::NewPayload { payload, sidecar, tx } => {
|
||||
let output = self.on_new_payload(payload, sidecar);
|
||||
BeaconEngineMessage::NewPayload { payload, tx } => {
|
||||
let output = self.on_new_payload(payload);
|
||||
if let Err(err) =
|
||||
tx.send(output.map(|o| o.outcome).map_err(|e| {
|
||||
BeaconOnNewPayloadError::Internal(Box::new(e))
|
||||
@ -3207,13 +3205,13 @@ mod tests {
|
||||
&block.clone_sealed_block().into_block(),
|
||||
);
|
||||
self.tree
|
||||
.on_new_payload(
|
||||
payload.into(),
|
||||
ExecutionPayloadSidecar::v3(CancunPayloadFields {
|
||||
.on_new_payload(ExecutionData {
|
||||
payload: payload.into(),
|
||||
sidecar: ExecutionPayloadSidecar::v3(CancunPayloadFields {
|
||||
parent_beacon_block_root: block.parent_beacon_block_root.unwrap(),
|
||||
versioned_hashes: vec![],
|
||||
}),
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@ -3478,7 +3476,10 @@ mod tests {
|
||||
|
||||
let outcome = test_harness
|
||||
.tree
|
||||
.on_new_payload(payload.into(), ExecutionPayloadSidecar::none())
|
||||
.on_new_payload(ExecutionData {
|
||||
payload: payload.into(),
|
||||
sidecar: ExecutionPayloadSidecar::none(),
|
||||
})
|
||||
.unwrap();
|
||||
assert!(outcome.outcome.is_syncing());
|
||||
|
||||
@ -3523,8 +3524,10 @@ mod tests {
|
||||
.tree
|
||||
.on_engine_message(FromEngine::Request(
|
||||
BeaconEngineMessage::NewPayload {
|
||||
payload: payload.clone().into(),
|
||||
sidecar: ExecutionPayloadSidecar::none(),
|
||||
payload: ExecutionData {
|
||||
payload: payload.clone().into(),
|
||||
sidecar: ExecutionPayloadSidecar::none(),
|
||||
},
|
||||
tx,
|
||||
}
|
||||
.into(),
|
||||
|
||||
Reference in New Issue
Block a user