Skip to content

Commit 8507e70

Browse files
michalkucharczykgithub-actions[bot]iulianbarbu
authored
fatxpool: event streams moved to view domain (#7545)
#### Overview This pull request refactors the transaction pool `graph` module by renaming components for better clarity. The `EventHandler` trait was introduced to enhance flexibility in handling transaction lifecycle events. Changes include renaming `graph::Listener` to `graph::EventDispatcher` and moving certain functionalities from `graph` to `view` module in order to decouple `graph` from `view`-related specifics. This PR does not introduce changes in the logic. #### Notes for Reviewers All the changes looks dense at first, but in fact following was done: - The `graph::Listener` was renamed to [`graph::EventDispatcher`](https://github.com/paritytech/polkadot-sdk/blob/515cb4042d097581ed6b4195e57b04494e385a17/substrate/client/transaction-pool/src/graph/listener.rs#L74C12-L74C27), to better reflect its role in dispatching transaction-related events from `ValidatedPool`. The `EventDispatcher` now utilizes the `L: EventHandler` generic type to handle transaction status events. - The new [`EventHandler`](https://github.com/paritytech/polkadot-sdk/blob/515cb4042d097581ed6b4195e57b04494e385a17/substrate/client/transaction-pool/src/graph/listener.rs#L34) trait was introduced to handle transaction lifecycle events, improving implementation flexibility and providing clearer role descriptions within the system. Introduction of this trait allowed the removal of `View` related entities (e.g. streams) from the `ValidatedPool`'s event dispatcher (previously _listener_). - The _dropped monitoring_ and _aggregated events_ stream [functionalities](https://github.com/paritytech/polkadot-sdk/blob/515cb4042d097581ed6b4195e57b04494e385a17/substrate/client/transaction-pool/src/fork_aware_txpool/view.rs#L157-L188) and [related types](https://github.com/paritytech/polkadot-sdk/blob/515cb4042d097581ed6b4195e57b04494e385a17/substrate/client/transaction-pool/src/fork_aware_txpool/view.rs#L112-L121) were moved from `graph::listener` to the `view` module. The [`ViewPoolObserver`](https://github.com/paritytech/polkadot-sdk/blob/515cb4042d097581ed6b4195e57b04494e385a17/substrate/client/transaction-pool/src/fork_aware_txpool/view.rs#L128C19-L128C35), which implements `EventHandler`, now provides the implementation of streams feeding. - Fields, arguments, and variables previously named `listener` were renamed to `event_dispatcher` to align with their purpose and type naming. - Various structs such as `Pool` and `ValidatedPool` were updated to include a generic `L: EventHandler` across the codebase. --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Iulian Barbu <[email protected]>
1 parent ba7cb48 commit 8507e70

File tree

17 files changed

+460
-260
lines changed

17 files changed

+460
-260
lines changed

prdoc/pr_7545.prdoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
title: '`fatxpool`: event streams moved to view domain'
2+
doc:
3+
- audience: Node Dev
4+
description: |-
5+
This pull request refactors the transaction pool `graph` module by renaming components for better clarity and decouples `graph` module from `view` module related specifics.
6+
This PR does not introduce changes in the logic.
7+
crates:
8+
- name: sc-transaction-pool
9+
bump: minor

substrate/client/transaction-pool/benches/basics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn uxt(transfer: TransferData) -> Extrinsic {
151151
ExtrinsicBuilder::new_bench_call(transfer).build()
152152
}
153153

154-
fn bench_configured(pool: Pool<TestApi>, number: u64, api: Arc<TestApi>) {
154+
fn bench_configured(pool: Pool<TestApi, ()>, number: u64, api: Arc<TestApi>) {
155155
let source = TimedTransactionSource::new_external(false);
156156
let mut futures = Vec::new();
157157
let mut tags = Vec::new();

substrate/client/transaction-pool/src/common/tests.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
//! Testing related primitives for internal usage in this crate.
2020
21-
use crate::graph::{BlockHash, ChainApi, ExtrinsicFor, NumberFor, Pool, RawExtrinsicFor};
21+
use crate::graph::{BlockHash, ChainApi, ExtrinsicFor, NumberFor, RawExtrinsicFor};
2222
use codec::Encode;
2323
use parking_lot::Mutex;
2424
use sc_transaction_pool_api::error;
@@ -36,6 +36,8 @@ use substrate_test_runtime::{
3636
ExtrinsicBuilder, Hashing, RuntimeCall, Transfer, TransferData, H256,
3737
};
3838

39+
type Pool<Api> = crate::graph::Pool<Api, ()>;
40+
3941
pub(crate) const INVALID_NONCE: u64 = 254;
4042

4143
/// Test api that implements [`ChainApi`].

substrate/client/transaction-pool/src/fork_aware_txpool/dropped_watcher.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ pub enum DroppedReason<Hash> {
8181
}
8282

8383
/// Dropped-logic related event from the single view.
84-
pub type ViewStreamEvent<C> = crate::graph::TransactionStatusEvent<ExtrinsicHash<C>, BlockHash<C>>;
84+
pub type ViewStreamEvent<C> =
85+
crate::fork_aware_txpool::view::TransactionStatusEvent<ExtrinsicHash<C>, BlockHash<C>>;
8586

8687
/// Dropped-logic stream of events coming from the single view.
8788
type ViewStream<C> = Pin<Box<dyn futures::Stream<Item = ViewStreamEvent<C>> + Send>>;

substrate/client/transaction-pool/src/fork_aware_txpool/fork_aware_txpool.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ where
478478
};
479479

480480
if let Ok((Some(best_tree_route), Some(best_view))) = best_result {
481-
let tmp_view: View<ChainApi> =
481+
let (tmp_view, _, _): (View<ChainApi>, _, _) =
482482
View::new_from_other(&best_view, &HashAndNumber { hash: at, number: block_number });
483483

484484
let mut all_extrinsics = vec![];
@@ -1085,26 +1085,28 @@ where
10851085
?tree_route,
10861086
"build_new_view"
10871087
);
1088-
let mut view = if let Some(origin_view) = origin_view {
1089-
let mut view = View::new_from_other(&origin_view, at);
1090-
if !tree_route.retracted().is_empty() {
1091-
view.pool.clear_recently_pruned();
1092-
}
1093-
view
1094-
} else {
1095-
debug!(
1096-
target: LOG_TARGET,
1097-
?at,
1098-
"creating non-cloned view"
1099-
);
1100-
View::new(
1101-
self.api.clone(),
1102-
at.clone(),
1103-
self.options.clone(),
1104-
self.metrics.clone(),
1105-
self.is_validator.clone(),
1106-
)
1107-
};
1088+
let (mut view, view_dropped_stream, view_aggregated_stream) =
1089+
if let Some(origin_view) = origin_view {
1090+
let (mut view, view_dropped_stream, view_aggragated_stream) =
1091+
View::new_from_other(&origin_view, at);
1092+
if !tree_route.retracted().is_empty() {
1093+
view.pool.clear_recently_pruned();
1094+
}
1095+
(view, view_dropped_stream, view_aggragated_stream)
1096+
} else {
1097+
debug!(
1098+
target: LOG_TARGET,
1099+
?at,
1100+
"creating non-cloned view"
1101+
);
1102+
View::new(
1103+
self.api.clone(),
1104+
at.clone(),
1105+
self.options.clone(),
1106+
self.metrics.clone(),
1107+
self.is_validator.clone(),
1108+
)
1109+
};
11081110

11091111
let start = Instant::now();
11101112
// 1. Capture all import notification from the very beginning, so first register all
@@ -1114,15 +1116,13 @@ where
11141116
view.pool.validated_pool().import_notification_stream().boxed(),
11151117
);
11161118

1117-
self.view_store.dropped_stream_controller.add_view(
1118-
view.at.hash,
1119-
view.pool.validated_pool().create_dropped_by_limits_stream().boxed(),
1120-
);
1119+
self.view_store
1120+
.dropped_stream_controller
1121+
.add_view(view.at.hash, view_dropped_stream.boxed());
11211122

1122-
self.view_store.listener.add_view_aggregated_stream(
1123-
view.at.hash,
1124-
view.pool.validated_pool().create_aggregated_stream().boxed(),
1125-
);
1123+
self.view_store
1124+
.listener
1125+
.add_view_aggregated_stream(view.at.hash, view_aggregated_stream.boxed());
11261126
// sync the transactions statuses and referencing views in all the listeners with newly
11271127
// cloned view.
11281128
view.pool.validated_pool().retrigger_notifications();

substrate/client/transaction-pool/src/fork_aware_txpool/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@
323323
//! [`MultiViewListener`]: crate::fork_aware_txpool::multi_view_listener::MultiViewListener
324324
//! [`Pool`]: crate::graph::Pool
325325
//! [`Watcher`]: crate::graph::watcher::Watcher
326-
//! [`AggregatedStream`]: crate::graph::AggregatedStream
326+
//! [`AggregatedStream`]: crate::fork_aware_txpool::view::AggregatedStream
327327
//! [`Options`]: crate::graph::Options
328328
//! [`vp::import_notification_stream`]: ../graph/validated_pool/struct.ValidatedPool.html#method.import_notification_stream
329329
//! [`vp::enforce_limits`]: ../graph/validated_pool/struct.ValidatedPool.html#method.enforce_limits

substrate/client/transaction-pool/src/fork_aware_txpool/multi_view_listener.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
2323
use crate::{
2424
common::tracing_log_xt::log_xt_trace,
25-
fork_aware_txpool::stream_map_util::next_event,
26-
graph::{self, BlockHash, ExtrinsicHash, TransactionStatusEvent},
25+
fork_aware_txpool::{stream_map_util::next_event, view::TransactionStatusEvent},
26+
graph::{self, BlockHash, ExtrinsicHash},
2727
LOG_TARGET,
2828
};
2929
use futures::{Future, FutureExt, Stream, StreamExt};

substrate/client/transaction-pool/src/fork_aware_txpool/revalidation_worker.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,9 @@ mod tests {
211211
let api = Arc::new(TestApi::default());
212212
let block0 = api.expect_hash_and_number(0);
213213

214-
let view = Arc::new(View::new(
215-
api.clone(),
216-
block0,
217-
Default::default(),
218-
Default::default(),
219-
false.into(),
220-
));
214+
let view = Arc::new(
215+
View::new(api.clone(), block0, Default::default(), Default::default(), false.into()).0,
216+
);
221217
let queue = Arc::new(RevalidationQueue::new());
222218

223219
let uxt = uxt(Transfer {

0 commit comments

Comments
 (0)