Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::{backfill::BackfillAction, engine::DownloadRequest};
use reth_beacon_consensus::{ForkchoiceStateTracker, InvalidHeaderCache, OnForkChoiceUpdated};
use reth_blockchain_tree::{BlockBuffer, BlockStatus};
use reth_blockchain_tree::{
error::InsertBlockErrorKind, BlockAttachment, BlockBuffer, BlockStatus,
};
use reth_blockchain_tree_api::{error::InsertBlockError, InsertPayloadOk};
use reth_consensus::{Consensus, PostExecutionInput};
use reth_engine_primitives::EngineTypes;
Expand All @@ -12,7 +14,9 @@ use reth_primitives::{
Address, Block, BlockNumber, Receipts, Requests, SealedBlock, SealedBlockWithSenders, B256,
U256,
};
use reth_provider::{BlockReader, ExecutionOutcome, StateProvider, StateProviderFactory};
use reth_provider::{
BlockReader, ExecutionOutcome, StateProvider, StateProviderFactory, StateRootProvider,
};
use reth_revm::database::StateProviderDatabase;
use reth_rpc_types::{
engine::{
Expand Down Expand Up @@ -387,28 +391,33 @@ where
&mut self,
block: SealedBlockWithSenders,
) -> Result<InsertPayloadOk, InsertBlockError> {
// TODO: check if block is known
self.insert_block_inner(block.clone())
.map_err(|kind| InsertBlockError::new(block.block, kind))
}

// validate block consensus rules
if let Err(err) = self.validate_block(&block) {
return Err(InsertBlockError::consensus_error(err, block.block))
fn insert_block_inner(
&mut self,
block: SealedBlockWithSenders,
) -> Result<InsertPayloadOk, InsertBlockErrorKind> {
if self.block_by_hash(block.hash())?.is_some() {
let attachment = BlockAttachment::Canonical; // TODO: remove or revise attachment
return Ok(InsertPayloadOk::AlreadySeen(BlockStatus::Valid(attachment)))
}

// validate block consensus rules
self.validate_block(&block)?;

let state_provider = self.state_provider(block.parent_hash).unwrap();
let executor = self.executor_provider.executor(StateProviderDatabase::new(&state_provider));

let block_number = block.number;
let block_hash = block.hash();
let block = block.unseal();
let output = executor.execute((&block, U256::MAX).into()).unwrap();
self.consensus
.validate_block_post_execution(
&block,
PostExecutionInput::new(&output.receipts, &output.requests),
)
.map_err(|error| {
InsertBlockError::new(block.block.clone().seal(block_hash), error.into())
})?;
self.consensus.validate_block_post_execution(
&block,
PostExecutionInput::new(&output.receipts, &output.requests),
)?;

let hashed_state = HashedPostState::from_bundle_state(&output.state.state);

Expand All @@ -429,7 +438,8 @@ where
};
self.state.tree_state.insert_executed(executed);

todo!()
let attachment = BlockAttachment::Canonical; // TODO: remove or revise attachment
Ok(InsertPayloadOk::Inserted(BlockStatus::Valid(attachment)))
}
}

Expand Down