referrerpolicy=no-referrer-when-downgrade

sc_transaction_pool/common/
mod.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! Common components re-used across different txpool implementations.
20
21pub(crate) mod api;
22pub(crate) mod enactment_state;
23pub(crate) mod error;
24pub(crate) mod metrics;
25pub(crate) mod sliding_stat;
26#[cfg(test)]
27pub(crate) mod tests;
28pub(crate) mod tracing_log_xt;
29
30use futures::StreamExt;
31use std::sync::Arc;
32
33/// Stat sliding window, in seconds for per-transaction activities.
34pub(crate) const STAT_SLIDING_WINDOW: u64 = 3;
35
36/// Inform the transaction pool about imported and finalized blocks.
37///
38/// If `all_block_notifications` is `true`, the pool is informed about every imported block (all
39/// forks); otherwise it is only informed about blocks imported as the new best.
40pub async fn notification_future<Client, Pool, Block>(
41	client: Arc<Client>,
42	txpool: Arc<Pool>,
43	all_block_notifications: bool,
44) where
45	Block: sp_runtime::traits::Block,
46	Client: sc_client_api::BlockchainEvents<Block>,
47	Pool: sc_transaction_pool_api::MaintainedTransactionPool<Block = Block>,
48{
49	let import_stream = client
50		.import_notification_stream()
51		.filter_map(move |n| {
52			futures::future::ready((all_block_notifications || n.is_new_best).then(|| n.into()))
53		})
54		.fuse();
55	let finality_stream = client.finality_notification_stream().map(Into::into).fuse();
56
57	futures::stream::select(import_stream, finality_stream)
58		.for_each(|evt| txpool.maintain(evt))
59		.await
60}