Skip to main content

soil_txpool/common/
mod.rs

1// This file is part of Soil.
2
3// Copyright (C) Soil contributors.
4// Copyright (C) Parity Technologies (UK) Ltd.
5// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
6
7//! Common components re-used across different txpool implementations.
8
9pub(crate) mod api;
10pub(crate) mod enactment_state;
11pub(crate) mod error;
12pub(crate) mod metrics;
13pub(crate) mod sliding_stat;
14#[cfg(test)]
15pub(crate) mod tests;
16pub(crate) mod tracing_log_xt;
17
18use futures::StreamExt;
19use std::sync::Arc;
20
21/// Stat sliding window, in seconds for per-transaction activities.
22pub(crate) const STAT_SLIDING_WINDOW: u64 = 3;
23
24/// Inform the transaction pool about imported and finalized blocks.
25pub async fn notification_future<Client, Pool, Block>(client: Arc<Client>, txpool: Arc<Pool>)
26where
27	Block: subsoil::runtime::traits::Block,
28	Client: soil_client::client_api::BlockchainEvents<Block>,
29	Pool: soil_client::transaction_pool::MaintainedTransactionPool<Block = Block>,
30{
31	let import_stream = client
32		.import_notification_stream()
33		.filter_map(|n| futures::future::ready(n.try_into().ok()))
34		.fuse();
35	let finality_stream = client.finality_notification_stream().map(Into::into).fuse();
36
37	futures::stream::select(import_stream, finality_stream)
38		.for_each(|evt| txpool.maintain(evt))
39		.await
40}