referrerpolicy=no-referrer-when-downgrade

malus/variants/
support_disabled.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//! This variant of Malus overrides the `disabled_validators` runtime API
18//! to always return an empty set of disabled validators.
19
20use polkadot_cli::{
21	service::{
22		AuxStore, Error, ExtendedOverseerGenArgs, Overseer, OverseerConnector, OverseerGen,
23		OverseerGenArgs, OverseerHandle,
24	},
25	validator_overseer_builder, Cli,
26};
27use polkadot_node_subsystem::SpawnGlue;
28use polkadot_node_subsystem_types::{ChainApiBackend, RuntimeApiSubsystemClient};
29use sp_core::traits::SpawnNamed;
30
31use crate::interceptor::*;
32
33use std::sync::Arc;
34
35#[derive(Debug, clap::Parser)]
36#[clap(rename_all = "kebab-case")]
37#[allow(missing_docs)]
38pub struct SupportDisabledOptions {
39	#[clap(flatten)]
40	pub cli: Cli,
41}
42
43/// Generates an overseer with a custom runtime API subsystem.
44pub(crate) struct SupportDisabled;
45
46impl OverseerGen for SupportDisabled {
47	fn generate<Spawner, RuntimeClient>(
48		&self,
49		connector: OverseerConnector,
50		args: OverseerGenArgs<'_, Spawner, RuntimeClient>,
51		ext_args: Option<ExtendedOverseerGenArgs>,
52	) -> Result<(Overseer<SpawnGlue<Spawner>, Arc<RuntimeClient>>, OverseerHandle), Error>
53	where
54		RuntimeClient: RuntimeApiSubsystemClient + ChainApiBackend + AuxStore + 'static,
55		Spawner: 'static + SpawnNamed + Clone + Unpin,
56	{
57		validator_overseer_builder(
58			args,
59			ext_args.expect("Extended arguments required to build validator overseer are provided"),
60		)?
61		.replace_runtime_api(move |ra_subsystem| {
62			InterceptedSubsystem::new(ra_subsystem, IgnoreDisabled)
63		})
64		.build_with_connector(connector)
65		.map_err(|e| e.into())
66	}
67}
68
69#[derive(Clone)]
70struct IgnoreDisabled;
71
72impl<Sender> MessageInterceptor<Sender> for IgnoreDisabled
73where
74	Sender: overseer::RuntimeApiSenderTrait + Clone + Send + 'static,
75{
76	type Message = RuntimeApiMessage;
77
78	/// Intercept incoming runtime api requests.
79	fn intercept_incoming(
80		&self,
81		_subsystem_sender: &mut Sender,
82		msg: FromOrchestra<Self::Message>,
83	) -> Option<FromOrchestra<Self::Message>> {
84		match msg {
85			FromOrchestra::Communication {
86				msg:
87					RuntimeApiMessage::Request(_relay_parent, RuntimeApiRequest::DisabledValidators(tx)),
88			} => {
89				let _ = tx.send(Ok(Vec::new()));
90				None
91			},
92			FromOrchestra::Communication { msg } => Some(FromOrchestra::Communication { msg }),
93			FromOrchestra::Signal(signal) => Some(FromOrchestra::Signal(signal)),
94		}
95	}
96}