feat: relax bounds for EthPubSub (#13203)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Arsenii Kulikov
2024-12-07 09:30:56 +04:00
committed by GitHub
parent 4d2c5767ec
commit 6b35b05993
8 changed files with 74 additions and 139 deletions

View File

@ -61,7 +61,8 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
type Network: FullNetwork; type Network: FullNetwork;
/// Builds new blocks. /// Builds new blocks.
type PayloadBuilder: PayloadBuilder + Clone; type PayloadBuilder: PayloadBuilder<PayloadType = <Self::Types as NodeTypesWithEngine>::Engine>
+ Clone;
/// Returns the transaction pool of the node. /// Returns the transaction pool of the node.
fn pool(&self) -> &Self::Pool; fn pool(&self) -> &Self::Pool;

View File

@ -13,9 +13,7 @@ use crate::{
AddOns, FullNode, AddOns, FullNode,
}; };
use reth_exex::ExExContext; use reth_exex::ExExContext;
use reth_node_api::{ use reth_node_api::{FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypes, NodeTypesWithDB};
FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypes, NodeTypesWithDB, PayloadBuilder,
};
use reth_node_core::node_config::NodeConfig; use reth_node_core::node_config::NodeConfig;
use reth_tasks::TaskExecutor; use reth_tasks::TaskExecutor;
use std::{fmt, future::Future}; use std::{fmt, future::Future};
@ -88,10 +86,7 @@ impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeTypes for NodeAdapter<T, C>
type Provider = T::Provider; type Provider = T::Provider;
} }
impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeComponents for NodeAdapter<T, C> impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeComponents for NodeAdapter<T, C> {
where
C::PayloadBuilder: PayloadBuilder,
{
type Pool = C::Pool; type Pool = C::Pool;
type Evm = C::Evm; type Evm = C::Evm;
type Executor = C::Executor; type Executor = C::Executor;

View File

@ -26,7 +26,7 @@ use reth_consensus::FullConsensus;
use reth_evm::execute::BlockExecutorProvider; use reth_evm::execute::BlockExecutorProvider;
use reth_network::NetworkHandle; use reth_network::NetworkHandle;
use reth_network_api::FullNetwork; use reth_network_api::FullNetwork;
use reth_node_api::{HeaderTy, NodeTypes, NodeTypesWithEngine, TxTy}; use reth_node_api::{HeaderTy, NodeTypes, NodeTypesWithEngine, PayloadBuilder, TxTy};
use reth_payload_builder::PayloadBuilderHandle; use reth_payload_builder::PayloadBuilderHandle;
use reth_transaction_pool::{PoolTransaction, TransactionPool}; use reth_transaction_pool::{PoolTransaction, TransactionPool};
@ -52,7 +52,8 @@ pub trait NodeComponents<T: FullNodeTypes>: Clone + Unpin + Send + Sync + 'stati
type Network: FullNetwork; type Network: FullNetwork;
/// Builds new blocks. /// Builds new blocks.
type PayloadBuilder: Clone; type PayloadBuilder: PayloadBuilder<PayloadType = <T::Types as NodeTypesWithEngine>::Engine>
+ Clone;
/// Returns the transaction pool of the node. /// Returns the transaction pool of the node.
fn pool(&self) -> &Self::Pool; fn pool(&self) -> &Self::Pool;

View File

@ -10,8 +10,8 @@ use std::{
use alloy_rpc_types::engine::ClientVersionV1; use alloy_rpc_types::engine::ClientVersionV1;
use futures::TryFutureExt; use futures::TryFutureExt;
use reth_node_api::{ use reth_node_api::{
AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, NodeTypes, NodeTypesWithEngine, AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, NodePrimitives, NodeTypes,
PayloadBuilder, NodeTypesWithEngine,
}; };
use reth_node_core::{ use reth_node_core::{
node_config::NodeConfig, node_config::NodeConfig,
@ -19,7 +19,7 @@ use reth_node_core::{
}; };
use reth_payload_builder::PayloadStore; use reth_payload_builder::PayloadStore;
use reth_primitives::EthPrimitives; use reth_primitives::EthPrimitives;
use reth_provider::{providers::ProviderNodeTypes, BlockReader}; use reth_provider::providers::ProviderNodeTypes;
use reth_rpc::{ use reth_rpc::{
eth::{EthApiTypes, FullEthApiServer}, eth::{EthApiTypes, FullEthApiServer},
EthApi, EthApi,
@ -33,7 +33,6 @@ use reth_rpc_builder::{
use reth_rpc_engine_api::{capabilities::EngineCapabilities, EngineApi}; use reth_rpc_engine_api::{capabilities::EngineCapabilities, EngineApi};
use reth_tasks::TaskExecutor; use reth_tasks::TaskExecutor;
use reth_tracing::tracing::{debug, info}; use reth_tracing::tracing::{debug, info};
use reth_transaction_pool::TransactionPool;
use crate::EthApiBuilderCtx; use crate::EthApiBuilderCtx;
@ -404,18 +403,17 @@ where
impl<N, EthApi, EV> RpcAddOns<N, EthApi, EV> impl<N, EthApi, EV> RpcAddOns<N, EthApi, EV>
where where
N: FullNodeComponents< N: FullNodeComponents<
Types: ProviderNodeTypes<Primitives = EthPrimitives>, Types: ProviderNodeTypes<
PayloadBuilder: PayloadBuilder<PayloadType = <N::Types as NodeTypesWithEngine>::Engine>, Primitives: NodePrimitives<
Pool: TransactionPool<Transaction = <EthApi::Pool as TransactionPool>::Transaction>, Block = reth_primitives::Block,
BlockHeader = reth_primitives::Header,
BlockBody = reth_primitives::BlockBody,
>,
>,
>, >,
EthApi: EthApiTypes EthApi: EthApiTypes
+ FullEthApiServer< + FullEthApiServer<Provider = N::Provider, Pool = N::Pool, Network = N::Network>
Provider: BlockReader< + AddDevSigners
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
Header = reth_primitives::Header,
>,
> + AddDevSigners
+ Unpin + Unpin
+ 'static, + 'static,
EV: EngineValidatorBuilder<N>, EV: EngineValidatorBuilder<N>,
@ -535,19 +533,10 @@ where
impl<N, EthApi, EV> NodeAddOns<N> for RpcAddOns<N, EthApi, EV> impl<N, EthApi, EV> NodeAddOns<N> for RpcAddOns<N, EthApi, EV>
where where
N: FullNodeComponents< N: FullNodeComponents<Types: ProviderNodeTypes<Primitives = EthPrimitives>>,
Types: ProviderNodeTypes<Primitives = EthPrimitives>,
PayloadBuilder: PayloadBuilder<PayloadType = <N::Types as NodeTypesWithEngine>::Engine>,
Pool: TransactionPool<Transaction = <EthApi::Pool as TransactionPool>::Transaction>,
>,
EthApi: EthApiTypes EthApi: EthApiTypes
+ FullEthApiServer< + FullEthApiServer<Provider = N::Provider, Pool = N::Pool, Network = N::Network>
Provider: BlockReader< + AddDevSigners
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
Header = reth_primitives::Header,
>,
> + AddDevSigners
+ Unpin + Unpin
+ 'static, + 'static,
EV: EngineValidatorBuilder<N>, EV: EngineValidatorBuilder<N>,

View File

@ -12,9 +12,7 @@ use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
use reth_db::transaction::{DbTx, DbTxMut}; use reth_db::transaction::{DbTx, DbTxMut};
use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvm}; use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvm};
use reth_network::{NetworkConfig, NetworkHandle, NetworkManager, PeersInfo}; use reth_network::{NetworkConfig, NetworkHandle, NetworkManager, PeersInfo};
use reth_node_api::{ use reth_node_api::{AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, TxTy};
AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, PayloadBuilder, TxTy,
};
use reth_node_builder::{ use reth_node_builder::{
components::{ components::{
ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder, ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder,
@ -241,7 +239,6 @@ impl<N> NodeAddOns<N> for OpAddOns<N>
where where
N: FullNodeComponents< N: FullNodeComponents<
Types: NodeTypes<ChainSpec = OpChainSpec, Primitives = OpPrimitives, Storage = OpStorage>, Types: NodeTypes<ChainSpec = OpChainSpec, Primitives = OpPrimitives, Storage = OpStorage>,
PayloadBuilder: PayloadBuilder<PayloadType = <N::Types as NodeTypesWithEngine>::Engine>,
>, >,
OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>, OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
{ {
@ -287,7 +284,6 @@ impl<N> RethRpcAddOns<N> for OpAddOns<N>
where where
N: FullNodeComponents< N: FullNodeComponents<
Types: NodeTypes<ChainSpec = OpChainSpec, Primitives = OpPrimitives, Storage = OpStorage>, Types: NodeTypes<ChainSpec = OpChainSpec, Primitives = OpPrimitives, Storage = OpStorage>,
PayloadBuilder: PayloadBuilder<PayloadType = <N::Types as NodeTypesWithEngine>::Engine>,
>, >,
OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>, OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
{ {

View File

@ -208,7 +208,7 @@ use reth_primitives::NodePrimitives;
use reth_provider::{ use reth_provider::{
AccountReader, BlockReader, CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader, AccountReader, BlockReader, CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader,
EvmEnvProvider, FullRpcProvider, ProviderBlock, ProviderHeader, ProviderReceipt, EvmEnvProvider, FullRpcProvider, ProviderBlock, ProviderHeader, ProviderReceipt,
ReceiptProvider, StateProviderFactory, StateProviderFactory,
}; };
use reth_rpc::{ use reth_rpc::{
AdminApi, DebugApi, EngineEthApi, EthBundle, MinerApi, NetApi, OtterscanApi, RPCApi, RethApi, AdminApi, DebugApi, EngineEthApi, EthBundle, MinerApi, NetApi, OtterscanApi, RPCApi, RethApi,
@ -286,18 +286,19 @@ where
Network: NetworkInfo + Peers + Clone + 'static, Network: NetworkInfo + Peers + Clone + 'static,
Tasks: TaskSpawner + Clone + 'static, Tasks: TaskSpawner + Clone + 'static,
Events: CanonStateSubscriptions<Primitives = BlockExecutor::Primitives> + Clone + 'static, Events: CanonStateSubscriptions<Primitives = BlockExecutor::Primitives> + Clone + 'static,
EvmConfig: ConfigureEvm<Header = alloy_consensus::Header>, EvmConfig: ConfigureEvm<
Header = <BlockExecutor::Primitives as NodePrimitives>::BlockHeader,
Transaction = <BlockExecutor::Primitives as NodePrimitives>::SignedTx,
>,
EthApi: FullEthApiServer< EthApi: FullEthApiServer<
Provider: BlockReader< Provider: BlockReader<
Block = reth_primitives::Block, Block = <BlockExecutor::Primitives as NodePrimitives>::Block,
Receipt = reth_primitives::Receipt, Receipt = <BlockExecutor::Primitives as NodePrimitives>::Receipt,
Header = reth_primitives::Header, Header = <BlockExecutor::Primitives as NodePrimitives>::BlockHeader,
>, >,
>, >,
BlockExecutor: BlockExecutorProvider< BlockExecutor: BlockExecutorProvider<
Primitives: NodePrimitives< Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
BlockHeader = reth_primitives::Header, BlockHeader = reth_primitives::Header,
BlockBody = reth_primitives::BlockBody, BlockBody = reth_primitives::BlockBody,
>, >,
@ -647,16 +648,21 @@ impl<Provider, Pool, Network, Tasks, Events, EvmConfig, BlockExecutor, Consensus
impl<Provider, Pool, Network, Tasks, Events, EvmConfig, BlockExecutor, Consensus> impl<Provider, Pool, Network, Tasks, Events, EvmConfig, BlockExecutor, Consensus>
RpcModuleBuilder<Provider, Pool, Network, Tasks, Events, EvmConfig, BlockExecutor, Consensus> RpcModuleBuilder<Provider, Pool, Network, Tasks, Events, EvmConfig, BlockExecutor, Consensus>
where where
Provider: FullRpcProvider + AccountReader + ChangeSetReader, Provider: FullRpcProvider<
Block = <Events::Primitives as NodePrimitives>::Block,
Receipt = <Events::Primitives as NodePrimitives>::Receipt,
> + AccountReader
+ ChangeSetReader,
Pool: TransactionPool + 'static, Pool: TransactionPool + 'static,
Network: NetworkInfo + Peers + Clone + 'static, Network: NetworkInfo + Peers + Clone + 'static,
Tasks: TaskSpawner + Clone + 'static, Tasks: TaskSpawner + Clone + 'static,
Events: CanonStateSubscriptions<Primitives = BlockExecutor::Primitives> + Clone + 'static, Events: CanonStateSubscriptions<Primitives = BlockExecutor::Primitives> + Clone + 'static,
EvmConfig: ConfigureEvm<Header = Header>, EvmConfig: ConfigureEvm<
Header = <BlockExecutor::Primitives as NodePrimitives>::BlockHeader,
Transaction = <BlockExecutor::Primitives as NodePrimitives>::SignedTx,
>,
BlockExecutor: BlockExecutorProvider< BlockExecutor: BlockExecutorProvider<
Primitives: NodePrimitives< Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
BlockHeader = reth_primitives::Header, BlockHeader = reth_primitives::Header,
BlockBody = reth_primitives::BlockBody, BlockBody = reth_primitives::BlockBody,
>, >,
@ -685,15 +691,11 @@ where
EngineApi: EngineApiServer<EngineT>, EngineApi: EngineApiServer<EngineT>,
EthApi: FullEthApiServer< EthApi: FullEthApiServer<
Provider: BlockReader< Provider: BlockReader<
Block = reth_primitives::Block, Block = <Events::Primitives as NodePrimitives>::Block,
Receipt = reth_primitives::Receipt, Receipt = <Events::Primitives as NodePrimitives>::Receipt,
Header = reth_primitives::Header, Header = <Events::Primitives as NodePrimitives>::BlockHeader,
>, >,
>, >,
Provider: BlockReader<
Block = <Events::Primitives as NodePrimitives>::Block,
Receipt = <Events::Primitives as NodePrimitives>::Receipt,
>,
{ {
let Self { let Self {
provider, provider,
@ -741,13 +743,16 @@ where
/// use reth_evm::ConfigureEvm; /// use reth_evm::ConfigureEvm;
/// use reth_evm_ethereum::execute::EthExecutorProvider; /// use reth_evm_ethereum::execute::EthExecutorProvider;
/// use reth_network_api::noop::NoopNetwork; /// use reth_network_api::noop::NoopNetwork;
/// use reth_primitives::TransactionSigned;
/// use reth_provider::test_utils::{NoopProvider, TestCanonStateSubscriptions}; /// use reth_provider::test_utils::{NoopProvider, TestCanonStateSubscriptions};
/// use reth_rpc::EthApi; /// use reth_rpc::EthApi;
/// use reth_rpc_builder::RpcModuleBuilder; /// use reth_rpc_builder::RpcModuleBuilder;
/// use reth_tasks::TokioTaskExecutor; /// use reth_tasks::TokioTaskExecutor;
/// use reth_transaction_pool::noop::NoopTransactionPool; /// use reth_transaction_pool::noop::NoopTransactionPool;
/// ///
/// fn init<Evm: ConfigureEvm<Header = Header> + 'static>(evm: Evm) { /// fn init<Evm: ConfigureEvm<Header = Header, Transaction = TransactionSigned> + 'static>(
/// evm: Evm,
/// ) {
/// let mut registry = RpcModuleBuilder::default() /// let mut registry = RpcModuleBuilder::default()
/// .with_provider(NoopProvider::default()) /// .with_provider(NoopProvider::default())
/// .with_pool(NoopTransactionPool::default()) /// .with_pool(NoopTransactionPool::default())
@ -769,11 +774,6 @@ where
) -> RpcRegistryInner<Provider, Pool, Network, Tasks, Events, EthApi, BlockExecutor, Consensus> ) -> RpcRegistryInner<Provider, Pool, Network, Tasks, Events, EthApi, BlockExecutor, Consensus>
where where
EthApi: EthApiTypes + 'static, EthApi: EthApiTypes + 'static,
Provider: BlockReader<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
Header = reth_primitives::Header,
>,
{ {
let Self { let Self {
provider, provider,
@ -809,15 +809,11 @@ where
where where
EthApi: FullEthApiServer< EthApi: FullEthApiServer<
Provider: BlockReader< Provider: BlockReader<
Block = reth_primitives::Block, Receipt = <Events::Primitives as NodePrimitives>::Receipt,
Receipt = reth_primitives::Receipt, Block = <Events::Primitives as NodePrimitives>::Block,
Header = reth_primitives::Header, Header = <Events::Primitives as NodePrimitives>::BlockHeader,
>, >,
>, >,
Provider: BlockReader<
Block = <EthApi::Provider as BlockReader>::Block,
Receipt = <EthApi::Provider as ReceiptProvider>::Receipt,
>,
Pool: TransactionPool<Transaction = <EthApi::Pool as TransactionPool>::Transaction>, Pool: TransactionPool<Transaction = <EthApi::Pool as TransactionPool>::Transaction>,
{ {
let mut modules = TransportRpcModules::default(); let mut modules = TransportRpcModules::default();
@ -1155,8 +1151,7 @@ where
RpcReceipt<EthApi::NetworkTypes>, RpcReceipt<EthApi::NetworkTypes>,
RpcHeader<EthApi::NetworkTypes>, RpcHeader<EthApi::NetworkTypes>,
> + EthApiTypes, > + EthApiTypes,
BlockExecutor: BlockExecutor: BlockExecutorProvider,
BlockExecutorProvider<Primitives: NodePrimitives<Block = reth_primitives::Block>>,
{ {
/// Register Eth Namespace /// Register Eth Namespace
/// ///
@ -1190,17 +1185,8 @@ where
/// If called outside of the tokio runtime. See also [`Self::eth_api`] /// If called outside of the tokio runtime. See also [`Self::eth_api`]
pub fn register_debug(&mut self) -> &mut Self pub fn register_debug(&mut self) -> &mut Self
where where
EthApi: EthApiSpec EthApi: EthApiSpec + EthTransactions + TraceExt,
+ EthTransactions< BlockExecutor::Primitives: NodePrimitives<Block = ProviderBlock<EthApi::Provider>>,
Provider: BlockReader<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
>,
> + TraceExt,
Provider: BlockReader<
Block = <EthApi::Provider as BlockReader>::Block,
Receipt = <EthApi::Provider as ReceiptProvider>::Receipt,
>,
{ {
let debug_api = self.debug_api(); let debug_api = self.debug_api();
self.modules.insert(RethRpcModule::Debug, debug_api.into_rpc().into()); self.modules.insert(RethRpcModule::Debug, debug_api.into_rpc().into());
@ -1303,8 +1289,7 @@ where
pub fn debug_api(&self) -> DebugApi<EthApi, BlockExecutor> pub fn debug_api(&self) -> DebugApi<EthApi, BlockExecutor>
where where
EthApi: EthApiSpec + EthTransactions + TraceExt, EthApi: EthApiSpec + EthTransactions + TraceExt,
BlockExecutor: BlockExecutor::Primitives: NodePrimitives<Block = ProviderBlock<EthApi::Provider>>,
BlockExecutorProvider<Primitives: NodePrimitives<Block = reth_primitives::Block>>,
{ {
DebugApi::new( DebugApi::new(
self.eth_api().clone(), self.eth_api().clone(),
@ -1363,10 +1348,8 @@ where
>, >,
BlockExecutor: BlockExecutorProvider< BlockExecutor: BlockExecutorProvider<
Primitives: NodePrimitives< Primitives: NodePrimitives<
Block = reth_primitives::Block,
BlockHeader = reth_primitives::Header, BlockHeader = reth_primitives::Header,
BlockBody = reth_primitives::BlockBody, BlockBody = reth_primitives::BlockBody,
Receipt = reth_primitives::Receipt,
>, >,
>, >,
Consensus: reth_consensus::FullConsensus<BlockExecutor::Primitives> + Clone + 'static, Consensus: reth_consensus::FullConsensus<BlockExecutor::Primitives> + Clone + 'static,

View File

@ -8,27 +8,28 @@ use alloy_primitives::TxHash;
use alloy_rpc_types_eth::{FilteredParams, Log}; use alloy_rpc_types_eth::{FilteredParams, Log};
use reth_chainspec::ChainInfo; use reth_chainspec::ChainInfo;
use reth_errors::ProviderError; use reth_errors::ProviderError;
use reth_primitives::{Receipt, SealedBlockWithSenders}; use reth_primitives::SealedBlockWithSenders;
use reth_primitives_traits::{BlockBody, SignedTransaction}; use reth_primitives_traits::{BlockBody, SignedTransaction};
use reth_storage_api::{BlockReader, ProviderBlock}; use reth_storage_api::{BlockReader, ProviderBlock};
use std::sync::Arc; use std::sync::Arc;
/// Returns all matching of a block's receipts when the transaction hashes are known. /// Returns all matching of a block's receipts when the transaction hashes are known.
pub fn matching_block_logs_with_tx_hashes<'a, I>( pub fn matching_block_logs_with_tx_hashes<'a, I, R>(
filter: &FilteredParams, filter: &FilteredParams,
block_num_hash: BlockNumHash, block_num_hash: BlockNumHash,
tx_hashes_and_receipts: I, tx_hashes_and_receipts: I,
removed: bool, removed: bool,
) -> Vec<Log> ) -> Vec<Log>
where where
I: IntoIterator<Item = (TxHash, &'a Receipt)>, I: IntoIterator<Item = (TxHash, &'a R)>,
R: TxReceipt<Log = alloy_primitives::Log> + 'a,
{ {
let mut all_logs = Vec::new(); let mut all_logs = Vec::new();
// Tracks the index of a log in the entire block. // Tracks the index of a log in the entire block.
let mut log_index: u64 = 0; let mut log_index: u64 = 0;
// Iterate over transaction hashes and receipts and append matching logs. // Iterate over transaction hashes and receipts and append matching logs.
for (receipt_idx, (tx_hash, receipt)) in tx_hashes_and_receipts.into_iter().enumerate() { for (receipt_idx, (tx_hash, receipt)) in tx_hashes_and_receipts.into_iter().enumerate() {
for log in &receipt.logs { for log in receipt.logs() {
if log_matches_filter(block_num_hash, log, filter) { if log_matches_filter(block_num_hash, log, filter) {
let log = Log { let log = Log {
inner: log.clone(), inner: log.clone(),

View File

@ -2,13 +2,9 @@
use std::sync::Arc; use std::sync::Arc;
use alloy_eips::eip2718::Encodable2718;
use alloy_primitives::TxHash; use alloy_primitives::TxHash;
use alloy_rpc_types_eth::{ use alloy_rpc_types_eth::{
pubsub::{ pubsub::{Params, PubSubSyncStatus, SubscriptionKind, SyncStatusMetadata},
Params, PubSubSyncStatus, SubscriptionKind, SubscriptionResult as EthSubscriptionResult,
SyncStatusMetadata,
},
FilteredParams, Header, Log, FilteredParams, Header, Log,
}; };
use futures::StreamExt; use futures::StreamExt;
@ -68,13 +64,7 @@ impl<Eth, Events> EthPubSub<Eth, Events> {
#[async_trait::async_trait] #[async_trait::async_trait]
impl<Eth, Events> EthPubSubApiServer<RpcTransaction<Eth::NetworkTypes>> for EthPubSub<Eth, Events> impl<Eth, Events> EthPubSubApiServer<RpcTransaction<Eth::NetworkTypes>> for EthPubSub<Eth, Events>
where where
Events: CanonStateSubscriptions< Events: CanonStateSubscriptions + 'static,
Primitives: NodePrimitives<
BlockHeader = reth_primitives::Header,
Receipt = reth_primitives::Receipt,
>,
> + Clone
+ 'static,
Eth: RpcNodeCore<Provider: BlockNumReader, Pool: TransactionPool, Network: NetworkInfo> Eth: RpcNodeCore<Provider: BlockNumReader, Pool: TransactionPool, Network: NetworkInfo>
+ EthApiTypes<TransactionCompat: TransactionCompat<PoolConsensusTx<Eth::Pool>>> + EthApiTypes<TransactionCompat: TransactionCompat<PoolConsensusTx<Eth::Pool>>>
+ 'static, + 'static,
@ -104,23 +94,13 @@ async fn handle_accepted<Eth, Events>(
params: Option<Params>, params: Option<Params>,
) -> Result<(), ErrorObject<'static>> ) -> Result<(), ErrorObject<'static>>
where where
Events: CanonStateSubscriptions< Events: CanonStateSubscriptions + 'static,
Primitives: NodePrimitives<
SignedTx: Encodable2718,
BlockHeader = reth_primitives::Header,
Receipt = reth_primitives::Receipt,
>,
> + Clone
+ 'static,
Eth: RpcNodeCore<Provider: BlockNumReader, Pool: TransactionPool, Network: NetworkInfo> Eth: RpcNodeCore<Provider: BlockNumReader, Pool: TransactionPool, Network: NetworkInfo>
+ EthApiTypes<TransactionCompat: TransactionCompat<PoolConsensusTx<Eth::Pool>>>, + EthApiTypes<TransactionCompat: TransactionCompat<PoolConsensusTx<Eth::Pool>>>,
{ {
match kind { match kind {
SubscriptionKind::NewHeads => { SubscriptionKind::NewHeads => {
let stream = pubsub pipe_from_stream(accepted_sink, pubsub.new_headers_stream()).await
.new_headers_stream()
.map(|header| EthSubscriptionResult::<()>::Header(Box::new(header.into())));
pipe_from_stream(accepted_sink, stream).await
} }
SubscriptionKind::Logs => { SubscriptionKind::Logs => {
// if no params are provided, used default filter params // if no params are provided, used default filter params
@ -131,10 +111,7 @@ where
} }
_ => FilteredParams::default(), _ => FilteredParams::default(),
}; };
let stream = pubsub pipe_from_stream(accepted_sink, pubsub.log_stream(filter)).await
.log_stream(filter)
.map(|log| EthSubscriptionResult::<()>::Log(Box::new(log)));
pipe_from_stream(accepted_sink, stream).await
} }
SubscriptionKind::NewPendingTransactions => { SubscriptionKind::NewPendingTransactions => {
if let Some(params) = params { if let Some(params) = params {
@ -146,9 +123,7 @@ where
tx.transaction.to_consensus(), tx.transaction.to_consensus(),
pubsub.eth_api.tx_resp_builder(), pubsub.eth_api.tx_resp_builder(),
) { ) {
Ok(tx) => { Ok(tx) => Some(tx),
Some(EthSubscriptionResult::FullTransaction(Box::new(tx)))
}
Err(err) => { Err(err) => {
error!(target = "rpc", error!(target = "rpc",
%err, %err,
@ -172,10 +147,7 @@ where
} }
} }
let stream = pubsub pipe_from_stream(accepted_sink, pubsub.pending_transaction_hashes_stream()).await
.pending_transaction_hashes_stream()
.map(EthSubscriptionResult::<()>::TransactionHash);
pipe_from_stream(accepted_sink, stream).await
} }
SubscriptionKind::Syncing => { SubscriptionKind::Syncing => {
// get new block subscription // get new block subscription
@ -285,7 +257,7 @@ where
Eth: RpcNodeCore<Provider: BlockNumReader>, Eth: RpcNodeCore<Provider: BlockNumReader>,
{ {
/// Returns the current sync status for the `syncing` subscription /// Returns the current sync status for the `syncing` subscription
fn sync_status(&self, is_syncing: bool) -> EthSubscriptionResult { fn sync_status(&self, is_syncing: bool) -> PubSubSyncStatus {
if is_syncing { if is_syncing {
let current_block = self let current_block = self
.eth_api .eth_api
@ -293,14 +265,14 @@ where
.chain_info() .chain_info()
.map(|info| info.best_number) .map(|info| info.best_number)
.unwrap_or_default(); .unwrap_or_default();
EthSubscriptionResult::SyncState(PubSubSyncStatus::Detailed(SyncStatusMetadata { PubSubSyncStatus::Detailed(SyncStatusMetadata {
syncing: true, syncing: true,
starting_block: 0, starting_block: 0,
current_block, current_block,
highest_block: Some(current_block), highest_block: Some(current_block),
})) })
} else { } else {
EthSubscriptionResult::SyncState(PubSubSyncStatus::Simple(false)) PubSubSyncStatus::Simple(false)
} }
} }
} }
@ -324,15 +296,12 @@ where
impl<Eth, Events> EthPubSubInner<Eth, Events> impl<Eth, Events> EthPubSubInner<Eth, Events>
where where
Events: CanonStateSubscriptions< Events: CanonStateSubscriptions,
Primitives: NodePrimitives<
BlockHeader = reth_primitives::Header,
Receipt = reth_primitives::Receipt,
>,
>,
{ {
/// Returns a stream that yields all new RPC blocks. /// Returns a stream that yields all new RPC blocks.
fn new_headers_stream(&self) -> impl Stream<Item = Header> { fn new_headers_stream(
&self,
) -> impl Stream<Item = Header<<Events::Primitives as NodePrimitives>::BlockHeader>> {
self.chain_events.canonical_state_stream().flat_map(|new_chain| { self.chain_events.canonical_state_stream().flat_map(|new_chain| {
let headers = new_chain.committed().headers().collect::<Vec<_>>(); let headers = new_chain.committed().headers().collect::<Vec<_>>();
futures::stream::iter( futures::stream::iter(