chore: simplify tree result types (#8390)

This commit is contained in:
Matthias Seitz
2024-05-24 16:41:01 +02:00
committed by GitHub
parent 4ee75d57ad
commit 789260416d
6 changed files with 26 additions and 27 deletions

2
Cargo.lock generated
View File

@ -6534,6 +6534,7 @@ dependencies = [
"reth-db",
"reth-evm",
"reth-evm-ethereum",
"reth-execution-errors",
"reth-interfaces",
"reth-metrics",
"reth-network",
@ -6541,6 +6542,7 @@ dependencies = [
"reth-provider",
"reth-revm",
"reth-stages-api",
"reth-storage-errors",
"reth-trie",
"reth-trie-parallel",
"tokio",

View File

@ -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

View File

@ -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,
@ -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,
@ -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.
@ -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()?;
@ -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)?;
@ -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() {
@ -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)?;
@ -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())
@ -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(())

View File

@ -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,
@ -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,

View File

@ -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.
@ -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

View File

@ -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(
@ -89,7 +89,7 @@ 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<()> {
@ -97,7 +97,7 @@ where
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> {