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