mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Using associated trait bound for db error (#8951)
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
//! Helper type that represents one of two possible executor types
|
||||
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::execute::{
|
||||
BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor,
|
||||
};
|
||||
@ -18,13 +20,15 @@ where
|
||||
A: BlockExecutorProvider,
|
||||
B: BlockExecutorProvider,
|
||||
{
|
||||
type Executor<DB: Database<Error = ProviderError>> = Either<A::Executor<DB>, B::Executor<DB>>;
|
||||
type BatchExecutor<DB: Database<Error = ProviderError>> =
|
||||
type Executor<DB: Database<Error: Into<ProviderError> + Display>> =
|
||||
Either<A::Executor<DB>, B::Executor<DB>>;
|
||||
|
||||
type BatchExecutor<DB: Database<Error: Into<ProviderError> + Display>> =
|
||||
Either<A::BatchExecutor<DB>, B::BatchExecutor<DB>>;
|
||||
|
||||
fn executor<DB>(&self, db: DB) -> Self::Executor<DB>
|
||||
where
|
||||
DB: Database<Error = ProviderError>,
|
||||
DB: Database<Error: Into<ProviderError> + Display>,
|
||||
{
|
||||
match self {
|
||||
Self::Left(a) => Either::Left(a.executor(db)),
|
||||
@ -34,7 +38,7 @@ where
|
||||
|
||||
fn batch_executor<DB>(&self, db: DB, prune_modes: PruneModes) -> Self::BatchExecutor<DB>
|
||||
where
|
||||
DB: Database<Error = ProviderError>,
|
||||
DB: Database<Error: Into<ProviderError> + Display>,
|
||||
{
|
||||
match self {
|
||||
Self::Left(a) => Either::Left(a.batch_executor(db, prune_modes)),
|
||||
@ -57,7 +61,7 @@ where
|
||||
Output = BlockExecutionOutput<Receipt>,
|
||||
Error = BlockExecutionError,
|
||||
>,
|
||||
DB: Database<Error = ProviderError>,
|
||||
DB: Database<Error: Into<ProviderError> + Display>,
|
||||
{
|
||||
type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>;
|
||||
type Output = BlockExecutionOutput<Receipt>;
|
||||
@ -85,7 +89,7 @@ where
|
||||
Output = ExecutionOutcome,
|
||||
Error = BlockExecutionError,
|
||||
>,
|
||||
DB: Database<Error = ProviderError>,
|
||||
DB: Database<Error: Into<ProviderError> + Display>,
|
||||
{
|
||||
type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>;
|
||||
type Output = ExecutionOutcome;
|
||||
|
||||
@ -5,6 +5,7 @@ use reth_primitives::{BlockNumber, BlockWithSenders, Receipt, Request, U256};
|
||||
use reth_prune_types::PruneModes;
|
||||
use revm::db::BundleState;
|
||||
use revm_primitives::db::Database;
|
||||
use std::fmt::Display;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
@ -142,7 +143,7 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static {
|
||||
///
|
||||
/// It is not expected to validate the state trie root, this must be done by the caller using
|
||||
/// the returned state.
|
||||
type Executor<DB: Database<Error = ProviderError>>: for<'a> Executor<
|
||||
type Executor<DB: Database<Error: Into<ProviderError> + Display>>: for<'a> Executor<
|
||||
DB,
|
||||
Input<'a> = BlockExecutionInput<'a, BlockWithSenders>,
|
||||
Output = BlockExecutionOutput<Receipt>,
|
||||
@ -150,7 +151,7 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static {
|
||||
>;
|
||||
|
||||
/// An executor that can execute a batch of blocks given a database.
|
||||
type BatchExecutor<DB: Database<Error = ProviderError>>: for<'a> BatchExecutor<
|
||||
type BatchExecutor<DB: Database<Error: Into<ProviderError> + Display>>: for<'a> BatchExecutor<
|
||||
DB,
|
||||
Input<'a> = BlockExecutionInput<'a, BlockWithSenders>,
|
||||
Output = ExecutionOutcome,
|
||||
@ -162,7 +163,7 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static {
|
||||
/// This is used to execute a single block and get the changed state.
|
||||
fn executor<DB>(&self, db: DB) -> Self::Executor<DB>
|
||||
where
|
||||
DB: Database<Error = ProviderError>;
|
||||
DB: Database<Error: Into<ProviderError> + Display>;
|
||||
|
||||
/// Creates a new batch executor with the given database and pruning modes.
|
||||
///
|
||||
@ -173,7 +174,7 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static {
|
||||
/// execution.
|
||||
fn batch_executor<DB>(&self, db: DB, prune_modes: PruneModes) -> Self::BatchExecutor<DB>
|
||||
where
|
||||
DB: Database<Error = ProviderError>;
|
||||
DB: Database<Error: Into<ProviderError> + Display>;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -187,19 +188,19 @@ mod tests {
|
||||
struct TestExecutorProvider;
|
||||
|
||||
impl BlockExecutorProvider for TestExecutorProvider {
|
||||
type Executor<DB: Database<Error = ProviderError>> = TestExecutor<DB>;
|
||||
type BatchExecutor<DB: Database<Error = ProviderError>> = TestExecutor<DB>;
|
||||
type Executor<DB: Database<Error: Into<ProviderError> + Display>> = TestExecutor<DB>;
|
||||
type BatchExecutor<DB: Database<Error: Into<ProviderError> + Display>> = TestExecutor<DB>;
|
||||
|
||||
fn executor<DB>(&self, _db: DB) -> Self::Executor<DB>
|
||||
where
|
||||
DB: Database<Error = ProviderError>,
|
||||
DB: Database<Error: Into<ProviderError> + Display>,
|
||||
{
|
||||
TestExecutor(PhantomData)
|
||||
}
|
||||
|
||||
fn batch_executor<DB>(&self, _db: DB, _prune_modes: PruneModes) -> Self::BatchExecutor<DB>
|
||||
where
|
||||
DB: Database<Error = ProviderError>,
|
||||
DB: Database<Error: Into<ProviderError> + Display>,
|
||||
{
|
||||
TestExecutor(PhantomData)
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
//! A no operation block executor implementation.
|
||||
|
||||
use std::fmt::Display;
|
||||
|
||||
use reth_execution_errors::BlockExecutionError;
|
||||
use reth_execution_types::ExecutionOutcome;
|
||||
use reth_primitives::{BlockNumber, BlockWithSenders, Receipt};
|
||||
@ -19,20 +21,20 @@ const UNAVAILABLE_FOR_NOOP: &str = "execution unavailable for noop";
|
||||
pub struct NoopBlockExecutorProvider;
|
||||
|
||||
impl BlockExecutorProvider for NoopBlockExecutorProvider {
|
||||
type Executor<DB: Database<Error = ProviderError>> = Self;
|
||||
type Executor<DB: Database<Error: Into<ProviderError> + Display>> = Self;
|
||||
|
||||
type BatchExecutor<DB: Database<Error = ProviderError>> = Self;
|
||||
type BatchExecutor<DB: Database<Error: Into<ProviderError> + Display>> = Self;
|
||||
|
||||
fn executor<DB>(&self, _: DB) -> Self::Executor<DB>
|
||||
where
|
||||
DB: Database<Error = ProviderError>,
|
||||
DB: Database<Error: Into<ProviderError> + Display>,
|
||||
{
|
||||
Self
|
||||
}
|
||||
|
||||
fn batch_executor<DB>(&self, _: DB, _: PruneModes) -> Self::BatchExecutor<DB>
|
||||
where
|
||||
DB: Database<Error = ProviderError>,
|
||||
DB: Database<Error: Into<ProviderError> + Display>,
|
||||
{
|
||||
Self
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ use reth_primitives::{BlockNumber, BlockWithSenders, Receipt};
|
||||
use reth_prune_types::PruneModes;
|
||||
use reth_storage_errors::provider::ProviderError;
|
||||
use revm_primitives::db::Database;
|
||||
use std::sync::Arc;
|
||||
use std::{fmt::Display, sync::Arc};
|
||||
|
||||
/// A [`BlockExecutorProvider`] that returns mocked execution results.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
@ -26,20 +26,20 @@ impl MockExecutorProvider {
|
||||
}
|
||||
|
||||
impl BlockExecutorProvider for MockExecutorProvider {
|
||||
type Executor<DB: Database<Error = ProviderError>> = Self;
|
||||
type Executor<DB: Database<Error: Into<ProviderError> + Display>> = Self;
|
||||
|
||||
type BatchExecutor<DB: Database<Error = ProviderError>> = Self;
|
||||
type BatchExecutor<DB: Database<Error: Into<ProviderError> + Display>> = Self;
|
||||
|
||||
fn executor<DB>(&self, _: DB) -> Self::Executor<DB>
|
||||
where
|
||||
DB: Database<Error = ProviderError>,
|
||||
DB: Database<Error: Into<ProviderError> + Display>,
|
||||
{
|
||||
self.clone()
|
||||
}
|
||||
|
||||
fn batch_executor<DB>(&self, _: DB, _: PruneModes) -> Self::BatchExecutor<DB>
|
||||
where
|
||||
DB: Database<Error = ProviderError>,
|
||||
DB: Database<Error: Into<ProviderError> + Display>,
|
||||
{
|
||||
self.clone()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user