referrerpolicy=no-referrer-when-downgrade

polkadot_subsystem_bench/mock/
approval_voting_parallel.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//! A generic mock approval voting parallel suitable to be used in benchmarks.
18
19use futures::FutureExt;
20use polkadot_node_subsystem::{
21	messages::ApprovalVotingParallelMessage, overseer, SpawnedSubsystem, SubsystemError,
22};
23use polkadot_node_subsystem_types::OverseerSignal;
24
25const LOG_TARGET: &str = "subsystem-bench::approval-voting-parallel-mock";
26
27pub struct MockApprovalVotingParallel {}
28
29impl MockApprovalVotingParallel {
30	pub fn new() -> Self {
31		Self {}
32	}
33}
34
35#[overseer::subsystem(ApprovalVotingParallel, error=SubsystemError, prefix=self::overseer)]
36impl<Context> MockApprovalVotingParallel {
37	fn start(self, ctx: Context) -> SpawnedSubsystem {
38		let future = self.run(ctx).map(|_| Ok(())).boxed();
39
40		SpawnedSubsystem { name: "test-environment", future }
41	}
42}
43
44#[overseer::contextbounds(ApprovalVotingParallel, prefix = self::overseer)]
45impl MockApprovalVotingParallel {
46	async fn run<Context>(self, mut ctx: Context) {
47		loop {
48			let msg = ctx.recv().await.expect("Overseer never fails us");
49			match msg {
50				orchestra::FromOrchestra::Signal(signal) =>
51					if signal == OverseerSignal::Conclude {
52						return
53					},
54				orchestra::FromOrchestra::Communication { msg } => match msg {
55					ApprovalVotingParallelMessage::GetApprovalSignaturesForCandidate(hash, tx) => {
56						gum::debug!(target: LOG_TARGET, "GetApprovalSignaturesForCandidate for candidate {:?}", hash);
57						tx.send(Default::default()).unwrap();
58					},
59					_ => todo!("Subsystem received unexpected message, {:?}", msg),
60				},
61			}
62		}
63	}
64}