mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-09 15:28:01 -05:00
feat(network): add customizable announcement filtering policy to APIs (#20861)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
use crate::{
|
||||
eth_requests::EthRequestHandler,
|
||||
transactions::{
|
||||
config::{StrictEthAnnouncementFilter, TransactionPropagationKind},
|
||||
config::{
|
||||
AnnouncementFilteringPolicy, StrictEthAnnouncementFilter, TransactionPropagationKind,
|
||||
},
|
||||
policy::NetworkPolicies,
|
||||
TransactionPropagationPolicy, TransactionsManager, TransactionsManagerConfig,
|
||||
},
|
||||
@@ -84,17 +86,41 @@ impl<Tx, Eth, N: NetworkPrimitives> NetworkBuilder<Tx, Eth, N> {
|
||||
}
|
||||
|
||||
/// Creates a new [`TransactionsManager`] and wires it to the network.
|
||||
pub fn transactions_with_policy<Pool: TransactionPool>(
|
||||
///
|
||||
/// Uses the default [`StrictEthAnnouncementFilter`] for announcement filtering.
|
||||
pub fn transactions_with_policy<Pool: TransactionPool, P: TransactionPropagationPolicy<N>>(
|
||||
self,
|
||||
pool: Pool,
|
||||
transactions_manager_config: TransactionsManagerConfig,
|
||||
propagation_policy: impl TransactionPropagationPolicy<N>,
|
||||
propagation_policy: P,
|
||||
) -> NetworkBuilder<TransactionsManager<Pool, N>, Eth, N> {
|
||||
self.transactions_with_policies(
|
||||
pool,
|
||||
transactions_manager_config,
|
||||
propagation_policy,
|
||||
StrictEthAnnouncementFilter::default(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Creates a new [`TransactionsManager`] with custom propagation and announcement policies.
|
||||
///
|
||||
/// This allows chains with custom transaction types (like CATX) to configure
|
||||
/// the announcement filter to accept their transaction types.
|
||||
pub fn transactions_with_policies<
|
||||
Pool: TransactionPool,
|
||||
P: TransactionPropagationPolicy<N>,
|
||||
A: AnnouncementFilteringPolicy<N>,
|
||||
>(
|
||||
self,
|
||||
pool: Pool,
|
||||
transactions_manager_config: TransactionsManagerConfig,
|
||||
propagation_policy: P,
|
||||
announcement_policy: A,
|
||||
) -> NetworkBuilder<TransactionsManager<Pool, N>, Eth, N> {
|
||||
let Self { mut network, request_handler, .. } = self;
|
||||
let (tx, rx) = mpsc::unbounded_channel();
|
||||
network.set_transactions(tx);
|
||||
let handle = network.handle().clone();
|
||||
let announcement_policy = StrictEthAnnouncementFilter::default();
|
||||
let policies = NetworkPolicies::new(propagation_policy, announcement_policy);
|
||||
|
||||
let transactions = TransactionsManager::with_policy(
|
||||
|
||||
@@ -15,7 +15,10 @@ use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
|
||||
use reth_db_api::{database::Database, database_metrics::DatabaseMetrics};
|
||||
use reth_exex::ExExContext;
|
||||
use reth_network::{
|
||||
transactions::{TransactionPropagationPolicy, TransactionsManagerConfig},
|
||||
transactions::{
|
||||
config::{AnnouncementFilteringPolicy, StrictEthAnnouncementFilter},
|
||||
TransactionPropagationPolicy, TransactionsManagerConfig,
|
||||
},
|
||||
NetworkBuilder, NetworkConfig, NetworkConfigBuilder, NetworkHandle, NetworkManager,
|
||||
NetworkPrimitives,
|
||||
};
|
||||
@@ -832,6 +835,7 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
|
||||
/// Convenience function to start the network tasks.
|
||||
///
|
||||
/// Accepts the config for the transaction task and the policy for propagation.
|
||||
/// Uses the default [`StrictEthAnnouncementFilter`] for announcement filtering.
|
||||
///
|
||||
/// Spawns the configured network and associated tasks and returns the [`NetworkHandle`]
|
||||
/// connected to that network.
|
||||
@@ -853,9 +857,47 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
|
||||
+ 'static,
|
||||
Node::Provider: BlockReaderFor<N>,
|
||||
Policy: TransactionPropagationPolicy<N>,
|
||||
{
|
||||
self.start_network_with_policies(
|
||||
builder,
|
||||
pool,
|
||||
tx_config,
|
||||
propagation_policy,
|
||||
StrictEthAnnouncementFilter::default(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Convenience function to start the network tasks with custom policies.
|
||||
///
|
||||
/// Accepts the config for the transaction task, the policy for propagation,
|
||||
/// and a custom announcement filter. This is useful for configuring which tx types are accepted
|
||||
/// in announcements.
|
||||
///
|
||||
/// Spawns the configured network and associated tasks and returns the [`NetworkHandle`]
|
||||
/// connected to that network.
|
||||
pub fn start_network_with_policies<Pool, N, PropPolicy, AnnPolicy>(
|
||||
&self,
|
||||
builder: NetworkBuilder<(), (), N>,
|
||||
pool: Pool,
|
||||
tx_config: TransactionsManagerConfig,
|
||||
propagation_policy: PropPolicy,
|
||||
announcement_policy: AnnPolicy,
|
||||
) -> NetworkHandle<N>
|
||||
where
|
||||
N: NetworkPrimitives,
|
||||
Pool: TransactionPool<
|
||||
Transaction: PoolTransaction<
|
||||
Consensus = N::BroadcastedTransaction,
|
||||
Pooled = N::PooledTransaction,
|
||||
>,
|
||||
> + Unpin
|
||||
+ 'static,
|
||||
Node::Provider: BlockReaderFor<N>,
|
||||
PropPolicy: TransactionPropagationPolicy<N>,
|
||||
AnnPolicy: AnnouncementFilteringPolicy<N>,
|
||||
{
|
||||
let (handle, network, txpool, eth) = builder
|
||||
.transactions_with_policy(pool, tx_config, propagation_policy)
|
||||
.transactions_with_policies(pool, tx_config, propagation_policy, announcement_policy)
|
||||
.request_handler(self.provider().clone())
|
||||
.split_with_handle();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user