referrerpolicy=no-referrer-when-downgrade

polkadot_subsystem_bench/mock/
dummy.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Dummy subsystem mocks.
18
19use futures::FutureExt;
20use paste::paste;
21use polkadot_node_subsystem::{overseer, SpawnedSubsystem, SubsystemError};
22use std::time::Duration;
23use tokio::time::sleep;
24
25const LOG_TARGET: &str = "subsystem-bench::mockery";
26
27macro_rules! mock {
28	// Just query by relay parent
29	($subsystem_name:ident) => {
30		paste! {
31			pub struct [<Mock $subsystem_name >] {}
32			#[overseer::subsystem($subsystem_name, error=SubsystemError, prefix=self::overseer)]
33			impl<Context> [<Mock $subsystem_name >] {
34				fn start(self, ctx: Context) -> SpawnedSubsystem {
35					let future = self.run(ctx).map(|_| Ok(())).boxed();
36
37                    // The name will appear in substrate CPU task metrics as `task_group`.`
38					SpawnedSubsystem { name: "test-environment", future }
39				}
40			}
41
42			#[overseer::contextbounds($subsystem_name, prefix = self::overseer)]
43			impl [<Mock $subsystem_name >] {
44				async fn run<Context>(self, mut ctx: Context) {
45					let mut count_total_msg = 0;
46					loop {
47						futures::select!{
48                            msg = ctx.recv().fuse() => {
49                                match msg.unwrap() {
50                                    orchestra::FromOrchestra::Signal(signal) => {
51                                        match signal {
52                                            polkadot_node_subsystem_types::OverseerSignal::Conclude => {return},
53                                            _ => {}
54                                        }
55                                    },
56                                    orchestra::FromOrchestra::Communication { msg } => {
57                                        gum::debug!(target: LOG_TARGET, msg = ?msg, "mocked subsystem received message");
58                                    }
59                                }
60
61                                count_total_msg  +=1;
62                            }
63                            _ = sleep(Duration::from_secs(6)).fuse() => {
64                                if count_total_msg > 0 {
65                                    gum::trace!(target: LOG_TARGET, "Subsystem {} processed {} messages since last time", stringify!($subsystem_name), count_total_msg);
66                                }
67                                count_total_msg = 0;
68                            }
69						}
70					}
71				}
72			}
73		}
74	};
75}
76
77// Generate dummy implementation for all subsystems
78mock!(AvailabilityStore);
79mock!(StatementDistribution);
80mock!(BitfieldSigning);
81mock!(BitfieldDistribution);
82mock!(Provisioner);
83mock!(NetworkBridgeRx);
84mock!(CollationGeneration);
85mock!(CollatorProtocol);
86mock!(GossipSupport);
87mock!(DisputeDistribution);
88mock!(DisputeCoordinator);
89mock!(ProspectiveParachains);
90mock!(PvfChecker);
91mock!(CandidateBacking);
92mock!(AvailabilityDistribution);
93mock!(CandidateValidation);
94mock!(AvailabilityRecovery);
95mock!(NetworkBridgeTx);
96mock!(ChainApi);
97mock!(ChainSelection);
98mock!(ApprovalVoting);
99mock!(ApprovalVotingParallel);
100mock!(ApprovalDistribution);
101mock!(RuntimeApi);