Return RecoveredBlock in ensure_well_formed_payload (#14625)

This commit is contained in:
Joseph Zhao
2025-02-21 18:42:54 +08:00
committed by GitHub
parent faa55d96bf
commit 86e8a2a245
6 changed files with 39 additions and 68 deletions

View File

@ -21,7 +21,7 @@ use reth_payload_primitives::{
EngineObjectValidationError, InvalidPayloadAttributesError, NewPayloadError, PayloadAttributes,
PayloadOrAttributes, PayloadTypes,
};
use reth_primitives::{NodePrimitives, SealedBlock};
use reth_primitives::{NodePrimitives, RecoveredBlock, SealedBlock};
use reth_primitives_traits::Block;
use serde::{de::DeserializeOwned, Serialize};
@ -145,7 +145,7 @@ pub trait PayloadValidator: fmt::Debug + Send + Sync + Unpin + 'static {
fn ensure_well_formed_payload(
&self,
payload: Self::ExecutionData,
) -> Result<SealedBlock<Self::Block>, NewPayloadError>;
) -> Result<RecoveredBlock<Self::Block>, NewPayloadError>;
}
/// Type that validates the payloads processed by the engine.

View File

@ -919,7 +919,7 @@ where
let status = if self.backfill_sync_state.is_idle() {
let mut latest_valid_hash = None;
let num_hash = block.num_hash();
match self.insert_block_without_senders(block) {
match self.insert_block(block) {
Ok(status) => {
let status = match status {
InsertPayloadOk::Inserted(BlockStatus::Valid) => {
@ -942,7 +942,7 @@ where
}
Err(error) => self.on_insert_block_error(error)?,
}
} else if let Err(error) = self.buffer_block_without_senders(block) {
} else if let Err(error) = self.buffer_block(block) {
self.on_insert_block_error(error)?
} else {
PayloadStatus::from_status(PayloadStatusEnum::Syncing)
@ -1991,19 +1991,6 @@ where
Ok(())
}
/// Attempts to recover the block's senders and then buffers it.
///
/// Returns an error if sender recovery failed or inserting into the buffer failed.
fn buffer_block_without_senders(
&mut self,
block: SealedBlock<N::Block>,
) -> Result<(), InsertBlockError<N::Block>> {
match block.try_recover() {
Ok(block) => self.buffer_block(block),
Err(err) => Err(InsertBlockError::sender_recovery_error(err.into_inner())),
}
}
/// Pre-validates the block and inserts it into the buffer.
fn buffer_block(
&mut self,
@ -2350,16 +2337,6 @@ where
self.most_recent_cache.take_if(|cache| cache.executed_block_hash() == parent_hash)
}
fn insert_block_without_senders(
&mut self,
block: SealedBlock<N::Block>,
) -> Result<InsertPayloadOk, InsertBlockError<N::Block>> {
match block.try_recover() {
Ok(block) => self.insert_block(block),
Err(err) => Err(InsertBlockError::sender_recovery_error(err.into_inner())),
}
}
fn insert_block(
&mut self,
block: RecoveredBlock<N::Block>,
@ -3833,11 +3810,11 @@ mod tests {
let s = include_str!("../../test-data/holesky/2.rlp");
let data = Bytes::from_str(s).unwrap();
let block = Block::decode(&mut data.as_ref()).unwrap();
let sealed = block.seal_slow();
let sealed = block.seal_slow().try_recover().unwrap();
let mut test_harness = TestHarness::new(HOLESKY.clone());
let outcome = test_harness.tree.insert_block_without_senders(sealed.clone()).unwrap();
let outcome = test_harness.tree.insert_block(sealed.clone()).unwrap();
assert_eq!(
outcome,
InsertPayloadOk::Inserted(BlockStatus::Disconnected {