Skip to content

Commit

Permalink
Using associated trait bound for db error
Browse files Browse the repository at this point in the history
  • Loading branch information
i-m-aditya committed Jun 19, 2024
1 parent da1536f commit ce4bdd8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
8 changes: 4 additions & 4 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ impl<EvmConfig> BlockExecutorProvider for EthExecutorProvider<EvmConfig>
where
EvmConfig: ConfigureEvm,
{
type Executor<DB: Database<Error = ProviderError>> = EthBlockExecutor<EvmConfig, DB>;
type Executor<DB: Database<Error: Into<ProviderError>>> = EthBlockExecutor<EvmConfig, DB>;

type BatchExecutor<DB: Database<Error = ProviderError>> = EthBatchExecutor<EvmConfig, DB>;
type BatchExecutor<DB: Database<Error: Into<ProviderError>>> = EthBatchExecutor<EvmConfig, DB>;

fn executor<DB>(&self, db: DB) -> Self::Executor<DB>
where
DB: Database<Error = ProviderError>,
DB: Database<Error: Into<ProviderError>>,
{
self.eth_executor(db)
}

fn batch_executor<DB>(&self, db: DB, prune_modes: PruneModes) -> Self::BatchExecutor<DB>
where
DB: Database<Error = ProviderError>,
DB: Database<Error: Into<ProviderError>>,
{
let executor = self.eth_executor(db);
EthBatchExecutor {
Expand Down
14 changes: 8 additions & 6 deletions crates/evm/src/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,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>>> =
Either<A::Executor<DB>, B::Executor<DB>>;

type BatchExecutor<DB: Database<Error: Into<ProviderError>>> =
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>>,
{
match self {
Self::Left(a) => Either::Left(a.executor(db)),
Expand All @@ -34,7 +36,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>>,
{
match self {
Self::Left(a) => Either::Left(a.batch_executor(db, prune_modes)),
Expand All @@ -57,7 +59,7 @@ where
Output = BlockExecutionOutput<Receipt>,
Error = BlockExecutionError,
>,
DB: Database<Error = ProviderError>,
DB: Database<Error: Into<ProviderError>>,
{
type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>;
type Output = BlockExecutionOutput<Receipt>;
Expand Down Expand Up @@ -85,7 +87,7 @@ where
Output = BatchBlockExecutionOutput,
Error = BlockExecutionError,
>,
DB: Database<Error = ProviderError>,
DB: Database<Error: Into<ProviderError>>,
{
type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>;
type Output = BatchBlockExecutionOutput;
Expand Down
16 changes: 8 additions & 8 deletions crates/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ 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>>>: for<'a> Executor<
DB,
Input<'a> = BlockExecutionInput<'a, BlockWithSenders>,
Output = BlockExecutionOutput<Receipt>,
Error = BlockExecutionError,
>;

/// 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>>>: for<'a> BatchExecutor<
DB,
Input<'a> = BlockExecutionInput<'a, BlockWithSenders>,
// TODO: change to bundle state with receipts
Expand All @@ -193,7 +193,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>>;

/// Creates a new batch executor with the given database and pruning modes.
///
Expand All @@ -204,7 +204,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>>;
}

#[cfg(test)]
Expand All @@ -218,19 +218,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>>> = TestExecutor<DB>;
type BatchExecutor<DB: Database<Error: Into<ProviderError>>> = TestExecutor<DB>;

fn executor<DB>(&self, _db: DB) -> Self::Executor<DB>
where
DB: Database<Error = ProviderError>,
DB: Database<Error: Into<ProviderError>>,
{
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>>,
{
TestExecutor(PhantomData)
}
Expand Down
8 changes: 4 additions & 4 deletions crates/evm/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,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>>> = Self;

type BatchExecutor<DB: Database<Error = ProviderError>> = Self;
type BatchExecutor<DB: Database<Error: Into<ProviderError>>> = Self;

fn executor<DB>(&self, _: DB) -> Self::Executor<DB>
where
DB: Database<Error = ProviderError>,
DB: Database<Error: Into<ProviderError>>,
{
Self
}

fn batch_executor<DB>(&self, _: DB, _: PruneModes) -> Self::BatchExecutor<DB>
where
DB: Database<Error = ProviderError>,
DB: Database<Error: Into<ProviderError>>,
{
Self
}
Expand Down
8 changes: 4 additions & 4 deletions crates/evm/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ impl MockExecutorProvider {
}

impl BlockExecutorProvider for MockExecutorProvider {
type Executor<DB: Database<Error = ProviderError>> = Self;
type Executor<DB: Database<Error: Into<ProviderError>>> = Self;

type BatchExecutor<DB: Database<Error = ProviderError>> = Self;
type BatchExecutor<DB: Database<Error: Into<ProviderError>>> = Self;

fn executor<DB>(&self, _: DB) -> Self::Executor<DB>
where
DB: Database<Error = ProviderError>,
DB: Database<Error: Into<ProviderError>>,
{
self.clone()
}

fn batch_executor<DB>(&self, _: DB, _: PruneModes) -> Self::BatchExecutor<DB>
where
DB: Database<Error = ProviderError>,
DB: Database<Error: Into<ProviderError>>,
{
self.clone()
}
Expand Down

0 comments on commit ce4bdd8

Please sign in to comment.