referrerpolicy=no-referrer-when-downgrade

polkadot_subsystem_bench/mock/
prospective_parachains.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 prospective parachains subsystem mockup suitable to be used in benchmarks.
18
19use futures::FutureExt;
20use polkadot_node_subsystem::{
21	messages::ProspectiveParachainsMessage, overseer, SpawnedSubsystem, SubsystemError,
22};
23use polkadot_node_subsystem_types::OverseerSignal;
24use polkadot_primitives::Hash;
25
26pub struct MockProspectiveParachains {}
27
28impl MockProspectiveParachains {
29	pub fn new() -> Self {
30		Self {}
31	}
32}
33
34#[overseer::subsystem(ProspectiveParachains, error=SubsystemError, prefix=self::overseer)]
35impl<Context> MockProspectiveParachains {
36	fn start(self, ctx: Context) -> SpawnedSubsystem {
37		let future = self.run(ctx).map(|_| Ok(())).boxed();
38
39		SpawnedSubsystem { name: "test-environment", future }
40	}
41}
42
43#[overseer::contextbounds(ProspectiveParachains, prefix = self::overseer)]
44impl MockProspectiveParachains {
45	async fn run<Context>(self, mut ctx: Context) {
46		loop {
47			let msg = ctx.recv().await.expect("Overseer never fails us");
48			match msg {
49				orchestra::FromOrchestra::Signal(signal) =>
50					if signal == OverseerSignal::Conclude {
51						return
52					},
53				orchestra::FromOrchestra::Communication { msg } => match msg {
54					ProspectiveParachainsMessage::GetMinimumRelayParents(_relay_parent, tx) => {
55						tx.send(vec![]).unwrap();
56					},
57					ProspectiveParachainsMessage::GetHypotheticalMembership(req, tx) => {
58						tx.send(
59							req.candidates
60								.iter()
61								.cloned()
62								.map(|candidate| (candidate, vec![Hash::repeat_byte(0)]))
63								.collect(),
64						)
65						.unwrap();
66					},
67					_ => {
68						unimplemented!("Unexpected chain-api message")
69					},
70				},
71			}
72		}
73	}
74}