Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 3147616

Browse files
authored
Expose node subcommands in Malus CLI (#6135)
* Expose the full Cli through malus Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fix lonely test Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
1 parent 9f4eae7 commit 3147616

File tree

3 files changed

+25
-30
lines changed

3 files changed

+25
-30
lines changed

cli/src/cli.rs

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ pub struct ValidationWorkerCommand {
8484

8585
#[allow(missing_docs)]
8686
#[derive(Debug, Parser)]
87-
#[cfg_attr(feature = "malus", derive(Clone))]
8887
pub struct RunCmd {
8988
#[allow(missing_docs)]
9089
#[clap(flatten)]

node/malus/src/malus.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
use clap::Parser;
2020
use color_eyre::eyre;
21-
use polkadot_cli::{Cli, RunCmd};
21+
use polkadot_cli::Cli;
2222

2323
pub(crate) mod interceptor;
2424
pub(crate) mod shared;
@@ -33,9 +33,9 @@ use variants::*;
3333
#[clap(rename_all = "kebab-case")]
3434
enum NemesisVariant {
3535
/// Suggest a candidate with an invalid proof of validity.
36-
SuggestGarbageCandidate(RunCmd),
36+
SuggestGarbageCandidate(Cli),
3737
/// Back a candidate with a specifically crafted proof of validity.
38-
BackGarbageCandidate(RunCmd),
38+
BackGarbageCandidate(Cli),
3939
/// Delayed disputing of ancestors that are perfectly fine.
4040
DisputeAncestor(DisputeAncestorOptions),
4141

@@ -57,24 +57,24 @@ struct MalusCli {
5757
pub finality_delay: Option<u32>,
5858
}
5959

60-
fn run_cmd(run: RunCmd) -> Cli {
61-
Cli { subcommand: None, run }
62-
}
63-
6460
impl MalusCli {
6561
/// Launch a malus node.
6662
fn launch(self) -> eyre::Result<()> {
6763
let finality_delay = self.finality_delay;
6864
match self.variant {
69-
NemesisVariant::BackGarbageCandidate(cmd) =>
70-
polkadot_cli::run_node(run_cmd(cmd), BackGarbageCandidate, finality_delay)?,
71-
NemesisVariant::SuggestGarbageCandidate(cmd) =>
72-
polkadot_cli::run_node(run_cmd(cmd), BackGarbageCandidateWrapper, finality_delay)?,
73-
NemesisVariant::DisputeAncestor(opts) => polkadot_cli::run_node(
74-
run_cmd(opts.clone().cmd),
75-
DisputeValidCandidates::new(opts),
76-
finality_delay,
77-
)?,
65+
NemesisVariant::BackGarbageCandidate(cli) =>
66+
polkadot_cli::run_node(cli, BackGarbageCandidate, finality_delay)?,
67+
NemesisVariant::SuggestGarbageCandidate(cli) =>
68+
polkadot_cli::run_node(cli, BackGarbageCandidateWrapper, finality_delay)?,
69+
NemesisVariant::DisputeAncestor(opts) => {
70+
let DisputeAncestorOptions { fake_validation, fake_validation_error, cli } = opts;
71+
72+
polkadot_cli::run_node(
73+
cli,
74+
DisputeValidCandidates { fake_validation, fake_validation_error },
75+
finality_delay,
76+
)?
77+
},
7878
NemesisVariant::PvfPrepareWorker(cmd) => {
7979
#[cfg(target_os = "android")]
8080
{
@@ -126,7 +126,7 @@ mod tests {
126126
variant: NemesisVariant::DisputeAncestor(run),
127127
..
128128
} => {
129-
assert!(run.cmd.base.bob);
129+
assert!(run.cli.run.base.bob);
130130
});
131131
}
132132
}

node/malus/src/variants/dispute_valid_candidates.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use polkadot_cli::{
2929
OverseerConnector, OverseerGen, OverseerGenArgs, OverseerHandle, ParachainHost,
3030
ProvideRuntimeApi,
3131
},
32-
RunCmd,
32+
Cli,
3333
};
3434
use polkadot_node_subsystem::SpawnGlue;
3535
use sp_core::traits::SpawnNamed;
@@ -40,7 +40,7 @@ use crate::{interceptor::*, variants::ReplaceValidationResult};
4040

4141
use std::sync::Arc;
4242

43-
#[derive(Clone, Debug, clap::Parser)]
43+
#[derive(Debug, clap::Parser)]
4444
#[clap(rename_all = "kebab-case")]
4545
#[allow(missing_docs)]
4646
pub struct DisputeAncestorOptions {
@@ -56,18 +56,14 @@ pub struct DisputeAncestorOptions {
5656
pub fake_validation_error: FakeCandidateValidationError,
5757

5858
#[clap(flatten)]
59-
pub cmd: RunCmd,
59+
pub cli: Cli,
6060
}
6161

6262
pub(crate) struct DisputeValidCandidates {
6363
/// Fake validation config (applies to disputes as well).
64-
opts: DisputeAncestorOptions,
65-
}
66-
67-
impl DisputeValidCandidates {
68-
pub fn new(opts: DisputeAncestorOptions) -> Self {
69-
Self { opts }
70-
}
64+
pub fake_validation: FakeCandidateValidation,
65+
/// Fake validation error config.
66+
pub fake_validation_error: FakeCandidateValidationError,
7167
}
7268

7369
impl OverseerGen for DisputeValidCandidates {
@@ -83,8 +79,8 @@ impl OverseerGen for DisputeValidCandidates {
8379
{
8480
let spawner = args.spawner.clone();
8581
let validation_filter = ReplaceValidationResult::new(
86-
self.opts.fake_validation,
87-
self.opts.fake_validation_error,
82+
self.fake_validation,
83+
self.fake_validation_error,
8884
SpawnGlue(spawner.clone()),
8985
);
9086

0 commit comments

Comments
 (0)