doc(hidden) for TransactionsManager handle only used in tests (#6748)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Emilia Hane
2024-02-24 15:35:19 +01:00
committed by GitHub
parent 94cb6a8bcd
commit 8abbe19392
4 changed files with 24 additions and 5 deletions

View File

@ -7,4 +7,4 @@ pub use init::{
enr_to_peer_id, unused_port, unused_tcp_addr, unused_tcp_and_udp_port, unused_tcp_udp,
unused_udp_addr, unused_udp_port, GETH_TIMEOUT,
};
pub use testnet::{NetworkEventStream, Peer, PeerConfig, Testnet};
pub use testnet::{NetworkEventStream, Peer, PeerConfig, PeerHandle, Testnet};

View File

@ -491,10 +491,12 @@ impl<Pool> PeerHandle<Pool> {
self.network.peer_id()
}
/// Returns the [`PeersHandle`] from the network.
pub fn peer_handle(&self) -> &PeersHandle {
self.network.peers_handle()
}
/// Returns the local socket as configured for the network.
pub fn local_addr(&self) -> SocketAddr {
self.network.local_addr()
}

View File

@ -88,14 +88,21 @@ use self::constants::{tx_manager::*, DEFAULT_SOFT_LIMIT_BYTE_SIZE_TRANSACTIONS_B
/// The future for inserting a function into the pool
pub type PoolImportFuture = Pin<Box<dyn Future<Output = Vec<PoolResult<TxHash>>> + Send + 'static>>;
/// Api to interact with [`TransactionsManager`] task.
/// Api to interact with [TransactionsManager] task.
///
/// This can be obtained via [TransactionsManager::handle] and can be used to manually interact with
/// the [TransactionsManager] task once it is spawned.
///
/// For example [TransactionsHandle::get_peer_transaction_hashes] returns the transaction hashes
/// known by a specific peer.
#[derive(Debug, Clone)]
pub struct TransactionsHandle {
/// Command channel to the [`TransactionsManager`]
manager_tx: mpsc::UnboundedSender<TransactionsCommand>,
}
/// Implementation of the `TransactionsHandle` API.
/// Implementation of the `TransactionsHandle` API for use in testnet via type
/// [`PeerHandle`](crate::test_utils::PeerHandle).
impl TransactionsHandle {
fn send(&self, cmd: TransactionsCommand) {
let _ = self.manager_tx.send(cmd);
@ -180,8 +187,9 @@ impl TransactionsHandle {
/// Manages transactions on top of the p2p network.
///
/// This can be spawned to another task and is supposed to be run as background service while
/// [`TransactionsHandle`] is used as frontend to send commands to.
/// This can be spawned to another task and is supposed to be run as background service.
/// [`TransactionsHandle`] can be used as frontend to programmatically send commands to it and
/// interact with it.
///
/// The [`TransactionsManager`] is responsible for:
/// - handling incoming eth messages for transactions.
@ -221,8 +229,13 @@ pub struct TransactionsManager<Pool> {
/// All the connected peers.
peers: HashMap<PeerId, Peer>,
/// Send half for the command channel.
///
/// This is kept so that a new [TransactionsHandle] can be created at any time.
command_tx: mpsc::UnboundedSender<TransactionsCommand>,
/// Incoming commands from [`TransactionsHandle`].
///
/// This will only receive commands if a user manually sends a command to the manager through
/// the [TransactionsHandle] to interact with this type directly.
command_rx: UnboundedReceiverStream<TransactionsCommand>,
/// Incoming commands from [`TransactionsHandle`].
pending_transactions: ReceiverStream<TxHash>,
@ -243,6 +256,7 @@ impl<Pool: TransactionPool> TransactionsManager<Pool> {
transactions_manager_config: TransactionsManagerConfig,
) -> Self {
let network_events = network.event_listener();
let (command_tx, command_rx) = mpsc::unbounded_channel();
let transaction_fetcher = TransactionFetcher::default().with_transaction_fetcher_config(

View File

@ -42,6 +42,9 @@ async fn main() -> eyre::Result<()> {
.transactions(pool.clone(), transactions_manager_config)
.split_with_handle();
// this can be used to interact with the `txpool` service directly
let _txs_handle = txpool.handle();
// spawn the network task
tokio::task::spawn(network);
// spawn the pool task