Skip to content

Commit b0a8746

Browse files
author
ordian
authored
malus: add new variant SupportDisabled (#2835)
This variant pretends that nobody is disabled onchain.
1 parent 5b9e69d commit b0a8746

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed

polkadot/node/malus/src/malus.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ use variants::*;
3232
enum NemesisVariant {
3333
/// Suggest a candidate with an invalid proof of validity.
3434
SuggestGarbageCandidate(SuggestGarbageCandidateOptions),
35+
/// Support disabled validators in backing and statement distribution.
36+
SupportDisabled(SupportDisabledOptions),
3537
/// Back a candidate with a specifically crafted proof of validity.
3638
BackGarbageCandidate(BackGarbageCandidateOptions),
3739
/// Delayed disputing of ancestors that are perfectly fine.
@@ -68,6 +70,11 @@ impl MalusCli {
6870
finality_delay,
6971
)?
7072
},
73+
NemesisVariant::SupportDisabled(opts) => {
74+
let SupportDisabledOptions { cli } = opts;
75+
76+
polkadot_cli::run_node(cli, SupportDisabled, finality_delay)?
77+
},
7178
NemesisVariant::DisputeAncestor(opts) => {
7279
let DisputeAncestorOptions {
7380
fake_validation,

polkadot/node/malus/src/variants/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ mod common;
2121
mod dispute_finalized_candidates;
2222
mod dispute_valid_candidates;
2323
mod suggest_garbage_candidate;
24+
mod support_disabled;
2425

2526
pub(crate) use self::{
2627
back_garbage_candidate::{BackGarbageCandidateOptions, BackGarbageCandidates},
2728
dispute_finalized_candidates::{DisputeFinalizedCandidates, DisputeFinalizedCandidatesOptions},
2829
dispute_valid_candidates::{DisputeAncestorOptions, DisputeValidCandidates},
2930
suggest_garbage_candidate::{SuggestGarbageCandidateOptions, SuggestGarbageCandidates},
31+
support_disabled::{SupportDisabled, SupportDisabledOptions},
3032
};
3133
pub(crate) use common::*;
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
}

prdoc/pr_2835.prdoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
title: New malus variant `support-disabled`
2+
3+
doc:
4+
- audience: Node Dev
5+
description: |
6+
A new malicious flavor added to pretend that nobody
7+
is disabled onchain.
8+
9+
crates: [ ]

0 commit comments

Comments
 (0)