Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/blockchain-tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ workspace = true
# reth
reth-primitives.workspace = true
reth-interfaces.workspace = true
reth-storage-errors.workspace = true
reth-execution-errors.workspace = true
reth-db.workspace = true
reth-evm.workspace = true
reth-revm.workspace = true
Expand Down
27 changes: 12 additions & 15 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ use crate::{
use reth_consensus::{Consensus, ConsensusError};
use reth_db::database::Database;
use reth_evm::execute::BlockExecutorProvider;
use reth_interfaces::{
blockchain_tree::{
error::{BlockchainTreeError, CanonicalError, InsertBlockError, InsertBlockErrorKind},
BlockAttachment, BlockStatus, BlockValidationKind, CanonicalOutcome, InsertPayloadOk,
},
executor::{BlockExecutionError, BlockValidationError},
provider::RootMismatch,
RethResult,
use reth_execution_errors::{BlockExecutionError, BlockValidationError};
use reth_interfaces::blockchain_tree::{
error::{BlockchainTreeError, CanonicalError, InsertBlockError, InsertBlockErrorKind},
BlockAttachment, BlockStatus, BlockValidationKind, CanonicalOutcome, InsertPayloadOk,
};
use reth_primitives::{
BlockHash, BlockNumHash, BlockNumber, ForkBlock, GotExpected, Hardfork, PruneModes, Receipt,
Expand All @@ -29,6 +25,7 @@ use reth_provider::{
StaticFileProviderFactory,
};
use reth_stages_api::{MetricEvent, MetricEventsSender};
use reth_storage_errors::provider::{ProviderResult, RootMismatch};
use std::{
collections::{btree_map::Entry, BTreeMap, HashSet},
sync::Arc,
Expand Down Expand Up @@ -120,7 +117,7 @@ where
externals: TreeExternals<DB, E>,
config: BlockchainTreeConfig,
prune_modes: Option<PruneModes>,
) -> RethResult<Self> {
) -> ProviderResult<Self> {
let max_reorg_depth = config.max_reorg_depth() as usize;
// The size of the broadcast is twice the maximum reorg depth, because at maximum reorg
// depth at least N blocks must be sent at once.
Expand Down Expand Up @@ -843,7 +840,7 @@ where
pub fn connect_buffered_blocks_to_canonical_hashes_and_finalize(
&mut self,
last_finalized_block: BlockNumber,
) -> RethResult<()> {
) -> ProviderResult<()> {
self.finalize_block(last_finalized_block);

let last_canonical_hashes = self.update_block_hashes()?;
Expand All @@ -855,7 +852,7 @@ where

/// Update all block hashes. iterate over present and new list of canonical hashes and compare
/// them. Remove all mismatches, disconnect them and removes all chains.
pub fn update_block_hashes(&mut self) -> RethResult<BTreeMap<BlockNumber, B256>> {
pub fn update_block_hashes(&mut self) -> ProviderResult<BTreeMap<BlockNumber, B256>> {
let last_canonical_hashes = self
.externals
.fetch_latest_canonical_hashes(self.config.num_of_canonical_hashes() as usize)?;
Expand All @@ -878,7 +875,7 @@ where
/// blocks before the tip.
pub fn update_block_hashes_and_clear_buffered(
&mut self,
) -> RethResult<BTreeMap<BlockNumber, BlockHash>> {
) -> ProviderResult<BTreeMap<BlockNumber, BlockHash>> {
let chain = self.update_block_hashes()?;

if let Some((block, _)) = chain.last_key_value() {
Expand All @@ -893,7 +890,7 @@ where
///
/// `N` is the maximum of `max_reorg_depth` and the number of block hashes needed to satisfy the
/// `BLOCKHASH` opcode in the EVM.
pub fn connect_buffered_blocks_to_canonical_hashes(&mut self) -> RethResult<()> {
pub fn connect_buffered_blocks_to_canonical_hashes(&mut self) -> ProviderResult<()> {
let last_canonical_hashes = self
.externals
.fetch_latest_canonical_hashes(self.config.num_of_canonical_hashes() as usize)?;
Expand All @@ -905,7 +902,7 @@ where
fn connect_buffered_blocks_to_hashes(
&mut self,
hashes: impl IntoIterator<Item = impl Into<BlockNumHash>>,
) -> RethResult<()> {
) -> ProviderResult<()> {
// check unconnected block buffer for children of the canonical hashes
for added_block in hashes.into_iter() {
self.try_connect_buffered_blocks(added_block.into())
Expand Down Expand Up @@ -1264,7 +1261,7 @@ where
}

/// Unwind tables and put it inside state
pub fn unwind(&mut self, unwind_to: BlockNumber) -> RethResult<()> {
pub fn unwind(&mut self, unwind_to: BlockNumber) -> Result<(), CanonicalError> {
// nothing to be done if unwind_to is higher then the tip
if self.block_indices().canonical_tip().number <= unwind_to {
return Ok(())
Expand Down
12 changes: 5 additions & 7 deletions crates/blockchain-tree/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ use crate::BundleStateDataRef;
use reth_consensus::{Consensus, ConsensusError};
use reth_db::database::Database;
use reth_evm::execute::{BlockExecutionOutput, BlockExecutorProvider, Executor};
use reth_interfaces::{
blockchain_tree::{
error::{BlockchainTreeError, InsertBlockErrorKind},
BlockAttachment, BlockValidationKind,
},
RethResult,
use reth_execution_errors::BlockExecutionError;
use reth_interfaces::blockchain_tree::{
error::{BlockchainTreeError, InsertBlockErrorKind},
BlockAttachment, BlockValidationKind,
};
use reth_primitives::{
BlockHash, BlockNumber, ForkBlock, GotExpected, Receipts, SealedBlockWithSenders, SealedHeader,
Expand Down Expand Up @@ -176,7 +174,7 @@ impl AppendableChain {
externals: &TreeExternals<DB, E>,
block_attachment: BlockAttachment,
block_validation_kind: BlockValidationKind,
) -> RethResult<(BundleStateWithReceipts, Option<TrieUpdates>)>
) -> Result<(BundleStateWithReceipts, Option<TrieUpdates>), BlockExecutionError>
where
BSDP: FullBundleStateDataProvider,
DB: Database + Clone,
Expand Down
4 changes: 2 additions & 2 deletions crates/blockchain-tree/src/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use reth_consensus::Consensus;
use reth_db::{
cursor::DbCursorRO, database::Database, static_file::HeaderMask, tables, transaction::DbTx,
};
use reth_interfaces::RethResult;
use reth_primitives::{BlockHash, BlockNumber, StaticFileSegment};
use reth_provider::{ProviderFactory, StaticFileProviderFactory, StatsReader};
use reth_storage_errors::provider::ProviderResult;
use std::{collections::BTreeMap, sync::Arc};

/// A container for external components.
Expand Down Expand Up @@ -46,7 +46,7 @@ impl<DB: Database, E> TreeExternals<DB, E> {
pub(crate) fn fetch_latest_canonical_hashes(
&self,
num_hashes: usize,
) -> RethResult<BTreeMap<BlockNumber, BlockHash>> {
) -> ProviderResult<BTreeMap<BlockNumber, BlockHash>> {
// Fetch the latest canonical hashes from the database
let mut hashes = self
.provider_factory
Expand Down
6 changes: 3 additions & 3 deletions crates/blockchain-tree/src/shareable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ where
let res =
tree.connect_buffered_blocks_to_canonical_hashes_and_finalize(last_finalized_block);
tree.update_chains_metrics();
res
Ok(res?)
}

fn update_block_hashes_and_clear_buffered(
Expand All @@ -89,15 +89,15 @@ where
let mut tree = self.tree.write();
let res = tree.update_block_hashes_and_clear_buffered();
tree.update_chains_metrics();
res
Ok(res?)
}

fn connect_buffered_blocks_to_canonical_hashes(&self) -> RethResult<()> {
trace!(target: "blockchain_tree", "Connecting buffered blocks to canonical hashes");
let mut tree = self.tree.write();
let res = tree.connect_buffered_blocks_to_canonical_hashes();
tree.update_chains_metrics();
res
Ok(res?)
}

fn make_canonical(&self, block_hash: BlockHash) -> Result<CanonicalOutcome, CanonicalError> {
Expand Down