mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor(interfaces): Result -> RethResult, Error -> RethError (#4695)
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
use crate::engine::hooks::EngineHookError;
|
||||
use reth_interfaces::RethError;
|
||||
use reth_rpc_types::engine::ForkchoiceUpdateError;
|
||||
use reth_stages::PipelineError;
|
||||
|
||||
@ -23,9 +24,9 @@ pub enum BeaconConsensusEngineError {
|
||||
/// Hook error.
|
||||
#[error(transparent)]
|
||||
Hook(#[from] EngineHookError),
|
||||
/// Common error. Wrapper around [reth_interfaces::Error].
|
||||
/// Common error. Wrapper around [RethError].
|
||||
#[error(transparent)]
|
||||
Common(#[from] reth_interfaces::Error),
|
||||
Common(#[from] RethError),
|
||||
}
|
||||
|
||||
// box the pipeline error as it is a large enum.
|
||||
@ -53,14 +54,14 @@ pub enum BeaconForkChoiceUpdateError {
|
||||
ForkchoiceUpdateError(#[from] ForkchoiceUpdateError),
|
||||
/// Internal errors, for example, error while reading from the database.
|
||||
#[error(transparent)]
|
||||
Internal(Box<reth_interfaces::Error>),
|
||||
Internal(Box<RethError>),
|
||||
/// Thrown when the engine task is unavailable/stopped.
|
||||
#[error("beacon consensus engine task stopped")]
|
||||
EngineUnavailable,
|
||||
}
|
||||
|
||||
impl From<reth_interfaces::Error> for BeaconForkChoiceUpdateError {
|
||||
fn from(e: reth_interfaces::Error) -> Self {
|
||||
impl From<RethError> for BeaconForkChoiceUpdateError {
|
||||
fn from(e: RethError) -> Self {
|
||||
Self::Internal(Box::new(e))
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ use crate::{
|
||||
BeaconForkChoiceUpdateError, BeaconOnNewPayloadError,
|
||||
};
|
||||
use futures::TryFutureExt;
|
||||
use reth_interfaces::RethResult;
|
||||
use reth_rpc_types::engine::{
|
||||
CancunPayloadFields, ExecutionPayload, ForkchoiceState, ForkchoiceUpdated, PayloadAttributes,
|
||||
PayloadStatus,
|
||||
@ -63,7 +64,7 @@ impl BeaconConsensusEngineHandle {
|
||||
&self,
|
||||
state: ForkchoiceState,
|
||||
payload_attrs: Option<PayloadAttributes>,
|
||||
) -> oneshot::Receiver<Result<OnForkChoiceUpdated, reth_interfaces::Error>> {
|
||||
) -> oneshot::Receiver<RethResult<OnForkChoiceUpdated>> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let _ = self.to_engine.send(BeaconEngineMessage::ForkchoiceUpdated {
|
||||
state,
|
||||
|
||||
@ -10,6 +10,7 @@ pub(crate) use controller::{EngineHooksController, PolledHook};
|
||||
|
||||
mod prune;
|
||||
pub use prune::PruneHook;
|
||||
use reth_interfaces::RethError;
|
||||
|
||||
/// Collection of [engine hooks][`EngineHook`].
|
||||
#[derive(Default)]
|
||||
@ -96,9 +97,9 @@ pub enum EngineHookError {
|
||||
/// Hook channel closed.
|
||||
#[error("Hook channel closed")]
|
||||
ChannelClosed,
|
||||
/// Common error. Wrapper around [reth_interfaces::Error].
|
||||
/// Common error. Wrapper around [RethError].
|
||||
#[error(transparent)]
|
||||
Common(#[from] reth_interfaces::Error),
|
||||
Common(#[from] RethError),
|
||||
/// An internal error occurred.
|
||||
#[error("Internal hook error occurred.")]
|
||||
Internal(#[from] Box<dyn std::error::Error + Send + Sync>),
|
||||
|
||||
@ -9,7 +9,7 @@ use crate::{
|
||||
use futures::FutureExt;
|
||||
use metrics::Counter;
|
||||
use reth_db::database::Database;
|
||||
use reth_interfaces::sync::SyncState;
|
||||
use reth_interfaces::{sync::SyncState, RethError};
|
||||
use reth_primitives::BlockNumber;
|
||||
use reth_prune::{Pruner, PrunerError, PrunerWithResult};
|
||||
use reth_tasks::TaskSpawner;
|
||||
@ -62,8 +62,8 @@ impl<DB: Database + 'static> PruneHook<DB> {
|
||||
EngineHookError::Internal(Box::new(err))
|
||||
}
|
||||
PrunerError::Interface(err) => err.into(),
|
||||
PrunerError::Database(err) => reth_interfaces::Error::Database(err).into(),
|
||||
PrunerError::Provider(err) => reth_interfaces::Error::Provider(err).into(),
|
||||
PrunerError::Database(err) => RethError::Database(err).into(),
|
||||
PrunerError::Provider(err) => RethError::Provider(err).into(),
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ use crate::{
|
||||
BeaconConsensusEngineEvent,
|
||||
};
|
||||
use futures::{future::Either, FutureExt};
|
||||
use reth_interfaces::consensus::ForkchoiceState;
|
||||
use reth_interfaces::{consensus::ForkchoiceState, RethResult};
|
||||
use reth_payload_builder::error::PayloadBuilderError;
|
||||
use reth_rpc_types::engine::{
|
||||
CancunPayloadFields, ExecutionPayload, ForkChoiceUpdateResult, ForkchoiceUpdateError,
|
||||
@ -158,7 +158,7 @@ pub enum BeaconEngineMessage {
|
||||
/// The payload attributes for block building.
|
||||
payload_attrs: Option<PayloadAttributes>,
|
||||
/// The sender for returning forkchoice updated result.
|
||||
tx: oneshot::Sender<Result<OnForkChoiceUpdated, reth_interfaces::Error>>,
|
||||
tx: oneshot::Sender<RethResult<OnForkChoiceUpdated>>,
|
||||
},
|
||||
/// Message with exchanged transition configuration.
|
||||
TransitionConfigurationExchanged,
|
||||
|
||||
@ -18,7 +18,7 @@ use reth_interfaces::{
|
||||
executor::{BlockExecutionError, BlockValidationError},
|
||||
p2p::{bodies::client::BodiesClient, headers::client::HeadersClient},
|
||||
sync::{NetworkSyncUpdater, SyncState},
|
||||
Error,
|
||||
RethError, RethResult,
|
||||
};
|
||||
use reth_payload_builder::{PayloadBuilderAttributes, PayloadBuilderHandle};
|
||||
use reth_primitives::{
|
||||
@ -232,7 +232,7 @@ where
|
||||
target: Option<H256>,
|
||||
pipeline_run_threshold: u64,
|
||||
hooks: EngineHooks,
|
||||
) -> Result<(Self, BeaconConsensusEngineHandle), Error> {
|
||||
) -> RethResult<(Self, BeaconConsensusEngineHandle)> {
|
||||
let (to_engine, rx) = mpsc::unbounded_channel();
|
||||
Self::with_channel(
|
||||
client,
|
||||
@ -278,7 +278,7 @@ where
|
||||
to_engine: UnboundedSender<BeaconEngineMessage>,
|
||||
rx: UnboundedReceiver<BeaconEngineMessage>,
|
||||
hooks: EngineHooks,
|
||||
) -> Result<(Self, BeaconConsensusEngineHandle), Error> {
|
||||
) -> RethResult<(Self, BeaconConsensusEngineHandle)> {
|
||||
let handle = BeaconConsensusEngineHandle { to_engine };
|
||||
let sync = EngineSyncController::new(
|
||||
pipeline,
|
||||
@ -327,7 +327,7 @@ where
|
||||
/// # Returns
|
||||
///
|
||||
/// A target block hash if the pipeline is inconsistent, otherwise `None`.
|
||||
fn check_pipeline_consistency(&self) -> Result<Option<H256>, Error> {
|
||||
fn check_pipeline_consistency(&self) -> RethResult<Option<H256>> {
|
||||
// If no target was provided, check if the stages are congruent - check if the
|
||||
// checkpoint of the last stage matches the checkpoint of the first.
|
||||
let first_stage_checkpoint = self
|
||||
@ -555,7 +555,7 @@ where
|
||||
&mut self,
|
||||
state: ForkchoiceState,
|
||||
attrs: Option<PayloadAttributes>,
|
||||
tx: oneshot::Sender<Result<OnForkChoiceUpdated, Error>>,
|
||||
tx: oneshot::Sender<Result<OnForkChoiceUpdated, RethError>>,
|
||||
) -> OnForkchoiceUpdateOutcome {
|
||||
self.metrics.forkchoice_updated_messages.increment(1);
|
||||
self.blockchain.on_forkchoice_update_received(&state);
|
||||
@ -563,7 +563,7 @@ where
|
||||
let on_updated = match self.forkchoice_updated(state, attrs) {
|
||||
Ok(response) => response,
|
||||
Err(error) => {
|
||||
if let Error::Execution(ref err) = error {
|
||||
if let RethError::Execution(ref err) = error {
|
||||
if err.is_fatal() {
|
||||
// FCU resulted in a fatal error from which we can't recover
|
||||
let err = err.clone();
|
||||
@ -623,7 +623,7 @@ where
|
||||
&mut self,
|
||||
state: ForkchoiceState,
|
||||
attrs: Option<PayloadAttributes>,
|
||||
) -> Result<OnForkChoiceUpdated, Error> {
|
||||
) -> RethResult<OnForkChoiceUpdated> {
|
||||
trace!(target: "consensus::engine", ?state, "Received new forkchoice state update");
|
||||
if state.head_block_hash.is_zero() {
|
||||
return Ok(OnForkChoiceUpdated::invalid_state())
|
||||
@ -690,7 +690,7 @@ where
|
||||
PayloadStatus::new(PayloadStatusEnum::Valid, Some(state.head_block_hash))
|
||||
}
|
||||
Err(error) => {
|
||||
if let Error::Canonical(ref err) = error {
|
||||
if let RethError::Canonical(ref err) = error {
|
||||
if err.is_fatal() {
|
||||
tracing::error!(target: "consensus::engine", ?err, "Encountered fatal error");
|
||||
return Err(error)
|
||||
@ -719,7 +719,7 @@ where
|
||||
fn record_make_canonical_latency(
|
||||
&self,
|
||||
start: Instant,
|
||||
outcome: &Result<CanonicalOutcome, Error>,
|
||||
outcome: &Result<CanonicalOutcome, RethError>,
|
||||
) {
|
||||
let elapsed = start.elapsed();
|
||||
self.metrics.make_canonical_latency.record(elapsed);
|
||||
@ -747,7 +747,7 @@ where
|
||||
&mut self,
|
||||
state: ForkchoiceState,
|
||||
status: &PayloadStatus,
|
||||
) -> Result<Option<OnForkChoiceUpdated>, reth_interfaces::Error> {
|
||||
) -> RethResult<Option<OnForkChoiceUpdated>> {
|
||||
// We only perform consistency checks if the status is VALID because if the status is
|
||||
// INVALID, we want to return the correct _type_ of error to the CL so we can properly
|
||||
// describe the reason it is invalid. For example, it's possible that the status is invalid
|
||||
@ -776,7 +776,7 @@ where
|
||||
fn ensure_consistent_state(
|
||||
&mut self,
|
||||
state: ForkchoiceState,
|
||||
) -> Result<Option<OnForkChoiceUpdated>, reth_interfaces::Error> {
|
||||
) -> RethResult<Option<OnForkChoiceUpdated>> {
|
||||
// Ensure that the finalized block, if not zero, is known and in the canonical chain
|
||||
// after the head block is canonicalized.
|
||||
//
|
||||
@ -816,11 +816,7 @@ where
|
||||
///
|
||||
/// This also updates the tracked safe and finalized blocks, and should be called before
|
||||
/// returning a VALID forkchoice update response
|
||||
fn update_canon_chain(
|
||||
&self,
|
||||
head: SealedHeader,
|
||||
update: &ForkchoiceState,
|
||||
) -> Result<(), Error> {
|
||||
fn update_canon_chain(&self, head: SealedHeader, update: &ForkchoiceState) -> RethResult<()> {
|
||||
self.update_head(head)?;
|
||||
self.update_finalized_block(update.finalized_block_hash)?;
|
||||
self.update_safe_block(update.safe_block_hash)?;
|
||||
@ -835,7 +831,7 @@ where
|
||||
///
|
||||
/// This should be called before returning a VALID forkchoice update response
|
||||
#[inline]
|
||||
fn update_head(&self, head: SealedHeader) -> Result<(), reth_interfaces::Error> {
|
||||
fn update_head(&self, head: SealedHeader) -> RethResult<()> {
|
||||
let mut head_block = Head {
|
||||
number: head.number,
|
||||
hash: head.hash,
|
||||
@ -850,7 +846,7 @@ where
|
||||
|
||||
head_block.total_difficulty =
|
||||
self.blockchain.header_td_by_number(head_block.number)?.ok_or_else(|| {
|
||||
Error::Provider(ProviderError::TotalDifficultyNotFound {
|
||||
RethError::Provider(ProviderError::TotalDifficultyNotFound {
|
||||
number: head_block.number,
|
||||
})
|
||||
})?;
|
||||
@ -863,17 +859,17 @@ where
|
||||
///
|
||||
/// Returns an error if the block is not found.
|
||||
#[inline]
|
||||
fn update_safe_block(&self, safe_block_hash: H256) -> Result<(), reth_interfaces::Error> {
|
||||
fn update_safe_block(&self, safe_block_hash: H256) -> RethResult<()> {
|
||||
if !safe_block_hash.is_zero() {
|
||||
if self.blockchain.safe_block_hash()? == Some(safe_block_hash) {
|
||||
// nothing to update
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
let safe = self
|
||||
.blockchain
|
||||
.find_block_by_hash(safe_block_hash, BlockSource::Any)?
|
||||
.ok_or_else(|| Error::Provider(ProviderError::UnknownBlockHash(safe_block_hash)))?;
|
||||
let safe =
|
||||
self.blockchain.find_block_by_hash(safe_block_hash, BlockSource::Any)?.ok_or_else(
|
||||
|| RethError::Provider(ProviderError::UnknownBlockHash(safe_block_hash)),
|
||||
)?;
|
||||
self.blockchain.set_safe(safe.header.seal(safe_block_hash));
|
||||
}
|
||||
Ok(())
|
||||
@ -883,10 +879,7 @@ where
|
||||
///
|
||||
/// Returns an error if the block is not found.
|
||||
#[inline]
|
||||
fn update_finalized_block(
|
||||
&self,
|
||||
finalized_block_hash: H256,
|
||||
) -> Result<(), reth_interfaces::Error> {
|
||||
fn update_finalized_block(&self, finalized_block_hash: H256) -> RethResult<()> {
|
||||
if !finalized_block_hash.is_zero() {
|
||||
if self.blockchain.finalized_block_hash()? == Some(finalized_block_hash) {
|
||||
// nothing to update
|
||||
@ -897,7 +890,7 @@ where
|
||||
.blockchain
|
||||
.find_block_by_hash(finalized_block_hash, BlockSource::Any)?
|
||||
.ok_or_else(|| {
|
||||
Error::Provider(ProviderError::UnknownBlockHash(finalized_block_hash))
|
||||
RethError::Provider(ProviderError::UnknownBlockHash(finalized_block_hash))
|
||||
})?;
|
||||
self.blockchain.finalize_block(finalized.number);
|
||||
self.blockchain.set_finalized(finalized.header.seal(finalized_block_hash));
|
||||
@ -915,7 +908,7 @@ where
|
||||
fn on_failed_canonical_forkchoice_update(
|
||||
&mut self,
|
||||
state: &ForkchoiceState,
|
||||
error: Error,
|
||||
error: RethError,
|
||||
) -> PayloadStatus {
|
||||
debug_assert!(self.sync.is_pipeline_idle(), "pipeline must be idle");
|
||||
|
||||
@ -929,7 +922,7 @@ where
|
||||
|
||||
#[allow(clippy::single_match)]
|
||||
match &error {
|
||||
Error::Canonical(
|
||||
RethError::Canonical(
|
||||
error @ CanonicalError::Validation(BlockValidationError::BlockPreMerge { .. }),
|
||||
) => {
|
||||
warn!(target: "consensus::engine", ?error, ?state, "Failed to canonicalize the head hash");
|
||||
@ -938,7 +931,7 @@ where
|
||||
})
|
||||
.with_latest_valid_hash(H256::zero())
|
||||
}
|
||||
Error::Execution(BlockExecutionError::BlockHashNotFoundInChain { .. }) => {
|
||||
RethError::Execution(BlockExecutionError::BlockHashNotFoundInChain { .. }) => {
|
||||
// This just means we couldn't find the block when attempting to make it canonical,
|
||||
// so we should not warn the user, since this will result in us attempting to sync
|
||||
// to a new target and is considered normal operation during sync
|
||||
@ -1330,7 +1323,7 @@ where
|
||||
///
|
||||
/// If the given block is missing from the database, this will return `false`. Otherwise, `true`
|
||||
/// is returned: the database contains the hash and the tree was updated.
|
||||
fn update_tree_on_finished_pipeline(&mut self, block_hash: H256) -> Result<bool, Error> {
|
||||
fn update_tree_on_finished_pipeline(&mut self, block_hash: H256) -> RethResult<bool> {
|
||||
let synced_to_finalized = match self.blockchain.block_number(block_hash)? {
|
||||
Some(number) => {
|
||||
// Attempt to restore the tree.
|
||||
@ -1495,7 +1488,7 @@ where
|
||||
// it's part of the canonical chain: if it's the safe or the finalized block
|
||||
if matches!(
|
||||
err,
|
||||
Error::Canonical(CanonicalError::BlockchainTree(
|
||||
RethError::Canonical(CanonicalError::BlockchainTree(
|
||||
BlockchainTreeError::BlockHashNotFoundInChain { .. }
|
||||
))
|
||||
) {
|
||||
@ -1580,9 +1573,9 @@ where
|
||||
Ok(header) => match header {
|
||||
Some(header) => header,
|
||||
None => {
|
||||
return Some(Err(Error::Provider(ProviderError::HeaderNotFound(
|
||||
max_block.into(),
|
||||
))
|
||||
return Some(Err(RethError::Provider(
|
||||
ProviderError::HeaderNotFound(max_block.into()),
|
||||
)
|
||||
.into()))
|
||||
}
|
||||
},
|
||||
@ -1755,7 +1748,7 @@ where
|
||||
}
|
||||
OnForkchoiceUpdateOutcome::Fatal(err) => {
|
||||
// fatal error, we can terminate the future
|
||||
return Poll::Ready(Err(Error::Execution(err).into()))
|
||||
return Poll::Ready(Err(RethError::Execution(err).into()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//! Collection of methods for block validation.
|
||||
use reth_interfaces::{consensus::ConsensusError, Result as RethResult};
|
||||
use reth_interfaces::{consensus::ConsensusError, RethResult};
|
||||
use reth_primitives::{
|
||||
constants::{
|
||||
self,
|
||||
@ -504,7 +504,7 @@ mod tests {
|
||||
use super::*;
|
||||
use assert_matches::assert_matches;
|
||||
use mockall::mock;
|
||||
use reth_interfaces::{Error::Consensus, Result};
|
||||
use reth_interfaces::{RethError::Consensus, RethResult};
|
||||
use reth_primitives::{
|
||||
constants::eip4844::DATA_GAS_PER_BLOB, hex_literal::hex, proofs, Account, Address,
|
||||
BlockBody, BlockHash, BlockHashOrNumber, Bytes, ChainSpecBuilder, Header, Signature,
|
||||
@ -516,7 +516,7 @@ mod tests {
|
||||
WithdrawalsProvider {}
|
||||
|
||||
impl WithdrawalsProvider for WithdrawalsProvider {
|
||||
fn latest_withdrawal(&self) -> Result<Option<Withdrawal>> ;
|
||||
fn latest_withdrawal(&self) -> RethResult<Option<Withdrawal>> ;
|
||||
|
||||
fn withdrawals_by_block(
|
||||
&self,
|
||||
@ -555,44 +555,44 @@ mod tests {
|
||||
}
|
||||
|
||||
impl AccountReader for Provider {
|
||||
fn basic_account(&self, _address: Address) -> Result<Option<Account>> {
|
||||
fn basic_account(&self, _address: Address) -> RethResult<Option<Account>> {
|
||||
Ok(self.account)
|
||||
}
|
||||
}
|
||||
|
||||
impl HeaderProvider for Provider {
|
||||
fn is_known(&self, _block_hash: &BlockHash) -> Result<bool> {
|
||||
fn is_known(&self, _block_hash: &BlockHash) -> RethResult<bool> {
|
||||
Ok(self.is_known)
|
||||
}
|
||||
|
||||
fn header(&self, _block_number: &BlockHash) -> Result<Option<Header>> {
|
||||
fn header(&self, _block_number: &BlockHash) -> RethResult<Option<Header>> {
|
||||
Ok(self.parent.clone())
|
||||
}
|
||||
|
||||
fn header_by_number(&self, _num: u64) -> Result<Option<Header>> {
|
||||
fn header_by_number(&self, _num: u64) -> RethResult<Option<Header>> {
|
||||
Ok(self.parent.clone())
|
||||
}
|
||||
|
||||
fn header_td(&self, _hash: &BlockHash) -> Result<Option<U256>> {
|
||||
fn header_td(&self, _hash: &BlockHash) -> RethResult<Option<U256>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn header_td_by_number(&self, _number: BlockNumber) -> Result<Option<U256>> {
|
||||
fn header_td_by_number(&self, _number: BlockNumber) -> RethResult<Option<U256>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn headers_range(&self, _range: impl RangeBounds<BlockNumber>) -> Result<Vec<Header>> {
|
||||
fn headers_range(&self, _range: impl RangeBounds<BlockNumber>) -> RethResult<Vec<Header>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
|
||||
fn sealed_headers_range(
|
||||
&self,
|
||||
_range: impl RangeBounds<BlockNumber>,
|
||||
) -> Result<Vec<SealedHeader>> {
|
||||
) -> RethResult<Vec<SealedHeader>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
|
||||
fn sealed_header(&self, _block_number: BlockNumber) -> Result<Option<SealedHeader>> {
|
||||
fn sealed_header(&self, _block_number: BlockNumber) -> RethResult<Option<SealedHeader>> {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
@ -606,7 +606,7 @@ mod tests {
|
||||
self.withdrawals_provider.withdrawals_by_block(_id, _timestamp)
|
||||
}
|
||||
|
||||
fn latest_withdrawal(&self) -> Result<Option<Withdrawal>> {
|
||||
fn latest_withdrawal(&self) -> RethResult<Option<Withdrawal>> {
|
||||
self.withdrawals_provider.latest_withdrawal()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user