mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Replace async trait with ->impl Future (#6791)
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -6248,7 +6248,6 @@ dependencies = [
|
||||
"alloy-node-bindings",
|
||||
"alloy-rlp",
|
||||
"aquamarine",
|
||||
"async-trait",
|
||||
"auto_impl",
|
||||
"criterion",
|
||||
"derive_more",
|
||||
@ -6949,7 +6948,6 @@ dependencies = [
|
||||
"alloy-rlp",
|
||||
"aquamarine",
|
||||
"assert_matches",
|
||||
"async-trait",
|
||||
"auto_impl",
|
||||
"bitflags 2.4.2",
|
||||
"criterion",
|
||||
|
||||
@ -60,7 +60,6 @@ tracing.workspace = true
|
||||
fnv = "1.0"
|
||||
thiserror.workspace = true
|
||||
parking_lot.workspace = true
|
||||
async-trait.workspace = true
|
||||
linked_hash_set = "0.1"
|
||||
linked-hash-map = "0.5.6"
|
||||
rand.workspace = true
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#![allow(unreachable_pub)]
|
||||
//! Helper extension traits for working with clique providers.
|
||||
|
||||
use async_trait::async_trait;
|
||||
use enr::k256::ecdsa::SigningKey;
|
||||
use ethers_core::{
|
||||
types::{transaction::eip2718::TypedTransaction, Address, Block, BlockNumber, H256},
|
||||
@ -51,7 +50,6 @@ pub type CliqueMiddlewareError<M> = CliqueError<<M as Middleware>::Error>;
|
||||
|
||||
/// Extension trait for [`Middleware`](ethers_providers::Middleware) to provide clique specific
|
||||
/// functionality.
|
||||
#[async_trait(?Send)]
|
||||
pub trait CliqueMiddleware: Send + Sync + Middleware {
|
||||
/// Enable mining on the clique geth instance by importing and unlocking the signer account
|
||||
/// derived from given private key and password.
|
||||
|
||||
@ -5,7 +5,6 @@ use reth_rpc_types::{NodeInfo, PeerInfo};
|
||||
/// Admin namespace rpc interface that gives access to several non-standard RPC methods.
|
||||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "admin"))]
|
||||
#[cfg_attr(feature = "client", rpc(server, client, namespace = "admin"))]
|
||||
#[async_trait::async_trait]
|
||||
pub trait AdminApi {
|
||||
/// Adds the given node record to the peerset.
|
||||
#[method(name = "addPeer")]
|
||||
|
||||
@ -12,7 +12,6 @@ use reth_rpc_types::{
|
||||
/// A subset of the [EthBundleApi] API interface that only supports `eth_callBundle`.
|
||||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "eth"))]
|
||||
#[cfg_attr(feature = "client", rpc(server, client, namespace = "eth"))]
|
||||
#[async_trait::async_trait]
|
||||
pub trait EthCallBundleApi {
|
||||
/// `eth_callBundle` can be used to simulate a bundle against a specific block number,
|
||||
/// including simulating a bundle at the top of the next block.
|
||||
@ -28,7 +27,6 @@ pub trait EthCallBundleApi {
|
||||
/// See also <https://docs.flashbots.net/flashbots-auction/searchers/advanced/rpc-endpoint>
|
||||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "eth"))]
|
||||
#[cfg_attr(feature = "client", rpc(server, client, namespace = "eth"))]
|
||||
#[async_trait::async_trait]
|
||||
pub trait EthBundleApi {
|
||||
/// `eth_sendBundle` can be used to send your bundles to the builder.
|
||||
#[method(name = "sendBundle")]
|
||||
|
||||
@ -165,7 +165,6 @@ pub trait EngineApi<Engine: EngineTypes> {
|
||||
/// Specifically for the engine auth server: <https://github.com/ethereum/execution-apis/blob/main/src/engine/common.md#underlying-protocol>
|
||||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "eth"))]
|
||||
#[cfg_attr(feature = "client", rpc(server, client, namespace = "eth"))]
|
||||
#[async_trait]
|
||||
pub trait EngineEthApi {
|
||||
/// Returns an object with data about the sync status or false.
|
||||
#[method(name = "syncing")]
|
||||
|
||||
@ -12,7 +12,6 @@ use reth_rpc_types::{
|
||||
/// Eth rpc interface: <https://ethereum.github.io/execution-apis/api-documentation/>
|
||||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "eth"))]
|
||||
#[cfg_attr(feature = "client", rpc(server, client, namespace = "eth"))]
|
||||
#[async_trait]
|
||||
pub trait EthApi {
|
||||
/// Returns the protocol version encoded as a string.
|
||||
#[method(name = "protocolVersion")]
|
||||
|
||||
@ -6,7 +6,6 @@ use reth_rpc_types::{
|
||||
/// Mev rpc interface.
|
||||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "mev"))]
|
||||
#[cfg_attr(feature = "client", rpc(server, client, namespace = "mev"))]
|
||||
#[async_trait::async_trait]
|
||||
pub trait MevApi {
|
||||
/// Submitting bundles to the relay. It takes in a bundle and provides a bundle hash as a
|
||||
/// return value.
|
||||
|
||||
@ -5,7 +5,6 @@ use reth_rpc_types::txpool::{TxpoolContent, TxpoolContentFrom, TxpoolInspect, Tx
|
||||
/// Txpool rpc interface.
|
||||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "txpool"))]
|
||||
#[cfg_attr(feature = "client", rpc(server, client, namespace = "txpool"))]
|
||||
#[async_trait::async_trait]
|
||||
pub trait TxPoolApi {
|
||||
/// Returns the number of transactions currently pending for inclusion in the next block(s), as
|
||||
/// well as the ones that are being scheduled for future execution only.
|
||||
|
||||
@ -6,7 +6,6 @@ use reth_rpc_types::relay::{BuilderBlockValidationRequest, BuilderBlockValidatio
|
||||
/// Block validation rpc interface.
|
||||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "flashbots"))]
|
||||
#[cfg_attr(feature = "client", rpc(server, client, namespace = "flashbots"))]
|
||||
#[async_trait::async_trait]
|
||||
pub trait BlockSubmissionValidationApi {
|
||||
/// A Request to validate a block submission.
|
||||
#[method(name = "validateBuilderSubmissionV1")]
|
||||
|
||||
@ -4,7 +4,6 @@ use reth_primitives::{Bytes, B256};
|
||||
/// Web3 rpc interface.
|
||||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "web3"))]
|
||||
#[cfg_attr(feature = "client", rpc(server, client, namespace = "web3"))]
|
||||
#[async_trait::async_trait]
|
||||
pub trait Web3Api {
|
||||
/// Returns current client version.
|
||||
#[method(name = "clientVersion")]
|
||||
|
||||
@ -29,7 +29,6 @@ alloy-rlp.workspace = true
|
||||
reth-revm = { workspace = true, optional = true }
|
||||
|
||||
# async/futures
|
||||
async-trait.workspace = true
|
||||
futures-util.workspace = true
|
||||
parking_lot.workspace = true
|
||||
tokio = { workspace = true, default-features = false, features = ["sync"] }
|
||||
|
||||
@ -318,7 +318,6 @@ where
|
||||
}
|
||||
|
||||
/// implements the `TransactionPool` interface for various transaction pool API consumers.
|
||||
#[async_trait::async_trait]
|
||||
impl<V, T, S> TransactionPool for Pool<V, T, S>
|
||||
where
|
||||
V: TransactionValidator,
|
||||
|
||||
@ -29,7 +29,6 @@ use tokio::sync::{mpsc, mpsc::Receiver};
|
||||
#[non_exhaustive]
|
||||
pub struct NoopTransactionPool;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl TransactionPool for NoopTransactionPool {
|
||||
type Transaction = EthPooledTransaction;
|
||||
|
||||
@ -254,7 +253,6 @@ pub struct MockTransactionValidator<T> {
|
||||
_marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<T: PoolTransaction> TransactionValidator for MockTransactionValidator<T> {
|
||||
type Transaction = T;
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
fmt,
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
task::{Context, Poll},
|
||||
@ -35,7 +36,6 @@ use tokio::sync::mpsc::Receiver;
|
||||
///
|
||||
/// Note: This requires `Clone` for convenience, since it is assumed that this will be implemented
|
||||
/// for a wrapped `Arc` type, see also [`Pool`](crate::Pool).
|
||||
#[async_trait::async_trait]
|
||||
#[auto_impl::auto_impl(Arc)]
|
||||
pub trait TransactionPool: Send + Sync + Clone {
|
||||
/// The transaction type of the pool
|
||||
@ -55,19 +55,22 @@ pub trait TransactionPool: Send + Sync + Clone {
|
||||
/// p2p network.
|
||||
///
|
||||
/// Consumer: P2P
|
||||
async fn add_external_transaction(&self, transaction: Self::Transaction) -> PoolResult<TxHash> {
|
||||
self.add_transaction(TransactionOrigin::External, transaction).await
|
||||
fn add_external_transaction(
|
||||
&self,
|
||||
transaction: Self::Transaction,
|
||||
) -> impl Future<Output = PoolResult<TxHash>> + Send {
|
||||
self.add_transaction(TransactionOrigin::External, transaction)
|
||||
}
|
||||
|
||||
/// Imports all _external_ transactions
|
||||
///
|
||||
///
|
||||
/// Consumer: Utility
|
||||
async fn add_external_transactions(
|
||||
fn add_external_transactions(
|
||||
&self,
|
||||
transactions: Vec<Self::Transaction>,
|
||||
) -> Vec<PoolResult<TxHash>> {
|
||||
self.add_transactions(TransactionOrigin::External, transactions).await
|
||||
) -> impl Future<Output = Vec<PoolResult<TxHash>>> + Send {
|
||||
self.add_transactions(TransactionOrigin::External, transactions)
|
||||
}
|
||||
|
||||
/// Adds an _unvalidated_ transaction into the pool and subscribe to state changes.
|
||||
@ -76,31 +79,31 @@ pub trait TransactionPool: Send + Sync + Clone {
|
||||
/// given transaction.
|
||||
///
|
||||
/// Consumer: Custom
|
||||
async fn add_transaction_and_subscribe(
|
||||
fn add_transaction_and_subscribe(
|
||||
&self,
|
||||
origin: TransactionOrigin,
|
||||
transaction: Self::Transaction,
|
||||
) -> PoolResult<TransactionEvents>;
|
||||
) -> impl Future<Output = PoolResult<TransactionEvents>> + Send;
|
||||
|
||||
/// Adds an _unvalidated_ transaction into the pool.
|
||||
///
|
||||
/// Consumer: RPC
|
||||
async fn add_transaction(
|
||||
fn add_transaction(
|
||||
&self,
|
||||
origin: TransactionOrigin,
|
||||
transaction: Self::Transaction,
|
||||
) -> PoolResult<TxHash>;
|
||||
) -> impl Future<Output = PoolResult<TxHash>> + Send;
|
||||
|
||||
/// Adds the given _unvalidated_ transaction into the pool.
|
||||
///
|
||||
/// Returns a list of results.
|
||||
///
|
||||
/// Consumer: RPC
|
||||
async fn add_transactions(
|
||||
fn add_transactions(
|
||||
&self,
|
||||
origin: TransactionOrigin,
|
||||
transactions: Vec<Self::Transaction>,
|
||||
) -> Vec<PoolResult<TxHash>>;
|
||||
) -> impl Future<Output = Vec<PoolResult<TxHash>>> + Send;
|
||||
|
||||
/// Returns a new transaction change event stream for the given transaction.
|
||||
///
|
||||
|
||||
@ -67,7 +67,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<Client, Tx> TransactionValidator for EthTransactionValidator<Client, Tx>
|
||||
where
|
||||
Client: StateProviderFactory + BlockReaderIdExt,
|
||||
|
||||
@ -9,7 +9,7 @@ use reth_primitives::{
|
||||
Address, BlobTransactionSidecar, IntoRecoveredTransaction, SealedBlock,
|
||||
TransactionSignedEcRecovered, TxHash, B256, U256,
|
||||
};
|
||||
use std::{fmt, time::Instant};
|
||||
use std::{fmt, future::Future, time::Instant};
|
||||
|
||||
mod constants;
|
||||
mod eth;
|
||||
@ -142,7 +142,6 @@ impl<T: PoolTransaction> ValidTransaction<T> {
|
||||
}
|
||||
|
||||
/// Provides support for validating transaction at any given state of the chain
|
||||
#[async_trait::async_trait]
|
||||
pub trait TransactionValidator: Send + Sync {
|
||||
/// The transaction type to validate.
|
||||
type Transaction: PoolTransaction;
|
||||
@ -172,26 +171,28 @@ pub trait TransactionValidator: Send + Sync {
|
||||
/// function.
|
||||
///
|
||||
/// See [TransactionValidationTaskExecutor] for a reference implementation.
|
||||
async fn validate_transaction(
|
||||
fn validate_transaction(
|
||||
&self,
|
||||
origin: TransactionOrigin,
|
||||
transaction: Self::Transaction,
|
||||
) -> TransactionValidationOutcome<Self::Transaction>;
|
||||
) -> impl Future<Output = TransactionValidationOutcome<Self::Transaction>> + Send;
|
||||
|
||||
/// Validates a batch of transactions.
|
||||
///
|
||||
/// Must return all outcomes for the given transactions in the same order.
|
||||
///
|
||||
/// See also [Self::validate_transaction].
|
||||
async fn validate_transactions(
|
||||
fn validate_transactions(
|
||||
&self,
|
||||
transactions: Vec<(TransactionOrigin, Self::Transaction)>,
|
||||
) -> Vec<TransactionValidationOutcome<Self::Transaction>> {
|
||||
) -> impl Future<Output = Vec<TransactionValidationOutcome<Self::Transaction>>> + Send {
|
||||
async {
|
||||
futures_util::future::join_all(
|
||||
transactions.into_iter().map(|(origin, tx)| self.validate_transaction(origin, tx)),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
/// Invoked when the head block changes.
|
||||
///
|
||||
|
||||
@ -153,7 +153,6 @@ impl<V> TransactionValidationTaskExecutor<V> {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<V> TransactionValidator for TransactionValidationTaskExecutor<V>
|
||||
where
|
||||
V: TransactionValidator + Clone + 'static,
|
||||
|
||||
@ -72,7 +72,6 @@ async fn main() -> eyre::Result<()> {
|
||||
#[non_exhaustive]
|
||||
struct OkValidator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl TransactionValidator for OkValidator {
|
||||
type Transaction = EthPooledTransaction;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user