From 14a421c8836e63ed7e552190c6ecf5a4edee6d65 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Tue, 11 Oct 2022 10:29:28 +0000 Subject: [PATCH 1/2] Expose the full Cli through malus Signed-off-by: Andrei Sandu --- cli/src/cli.rs | 1 - node/malus/src/malus.rs | 32 +++++++++---------- .../src/variants/dispute_valid_candidates.rs | 20 +++++------- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 804c4a9f81c6..43e49019c019 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -84,7 +84,6 @@ pub struct ValidationWorkerCommand { #[allow(missing_docs)] #[derive(Debug, Parser)] -#[cfg_attr(feature = "malus", derive(Clone))] pub struct RunCmd { #[allow(missing_docs)] #[clap(flatten)] diff --git a/node/malus/src/malus.rs b/node/malus/src/malus.rs index dd9f1377f14a..d1d30cdd7233 100644 --- a/node/malus/src/malus.rs +++ b/node/malus/src/malus.rs @@ -18,7 +18,7 @@ use clap::Parser; use color_eyre::eyre; -use polkadot_cli::{Cli, RunCmd}; +use polkadot_cli::Cli; pub(crate) mod interceptor; pub(crate) mod shared; @@ -33,9 +33,9 @@ use variants::*; #[clap(rename_all = "kebab-case")] enum NemesisVariant { /// Suggest a candidate with an invalid proof of validity. - SuggestGarbageCandidate(RunCmd), + SuggestGarbageCandidate(Cli), /// Back a candidate with a specifically crafted proof of validity. - BackGarbageCandidate(RunCmd), + BackGarbageCandidate(Cli), /// Delayed disputing of ancestors that are perfectly fine. DisputeAncestor(DisputeAncestorOptions), @@ -57,24 +57,24 @@ struct MalusCli { pub finality_delay: Option, } -fn run_cmd(run: RunCmd) -> Cli { - Cli { subcommand: None, run } -} - impl MalusCli { /// Launch a malus node. fn launch(self) -> eyre::Result<()> { let finality_delay = self.finality_delay; match self.variant { - NemesisVariant::BackGarbageCandidate(cmd) => - polkadot_cli::run_node(run_cmd(cmd), BackGarbageCandidate, finality_delay)?, - NemesisVariant::SuggestGarbageCandidate(cmd) => - polkadot_cli::run_node(run_cmd(cmd), BackGarbageCandidateWrapper, finality_delay)?, - NemesisVariant::DisputeAncestor(opts) => polkadot_cli::run_node( - run_cmd(opts.clone().cmd), - DisputeValidCandidates::new(opts), - finality_delay, - )?, + NemesisVariant::BackGarbageCandidate(cli) => + polkadot_cli::run_node(cli, BackGarbageCandidate, finality_delay)?, + NemesisVariant::SuggestGarbageCandidate(cli) => + polkadot_cli::run_node(cli, BackGarbageCandidateWrapper, finality_delay)?, + NemesisVariant::DisputeAncestor(opts) => { + let DisputeAncestorOptions { fake_validation, fake_validation_error, cli } = opts; + + polkadot_cli::run_node( + cli, + DisputeValidCandidates { fake_validation, fake_validation_error }, + finality_delay, + )? + }, NemesisVariant::PvfPrepareWorker(cmd) => { #[cfg(target_os = "android")] { diff --git a/node/malus/src/variants/dispute_valid_candidates.rs b/node/malus/src/variants/dispute_valid_candidates.rs index 17ac070e619b..175cdecee916 100644 --- a/node/malus/src/variants/dispute_valid_candidates.rs +++ b/node/malus/src/variants/dispute_valid_candidates.rs @@ -29,7 +29,7 @@ use polkadot_cli::{ OverseerConnector, OverseerGen, OverseerGenArgs, OverseerHandle, ParachainHost, ProvideRuntimeApi, }, - RunCmd, + Cli, }; use polkadot_node_subsystem::SpawnGlue; use sp_core::traits::SpawnNamed; @@ -40,7 +40,7 @@ use crate::{interceptor::*, variants::ReplaceValidationResult}; use std::sync::Arc; -#[derive(Clone, Debug, clap::Parser)] +#[derive(Debug, clap::Parser)] #[clap(rename_all = "kebab-case")] #[allow(missing_docs)] pub struct DisputeAncestorOptions { @@ -56,18 +56,14 @@ pub struct DisputeAncestorOptions { pub fake_validation_error: FakeCandidateValidationError, #[clap(flatten)] - pub cmd: RunCmd, + pub cli: Cli, } pub(crate) struct DisputeValidCandidates { /// Fake validation config (applies to disputes as well). - opts: DisputeAncestorOptions, -} - -impl DisputeValidCandidates { - pub fn new(opts: DisputeAncestorOptions) -> Self { - Self { opts } - } + pub fake_validation: FakeCandidateValidation, + /// Fake validation error config. + pub fake_validation_error: FakeCandidateValidationError, } impl OverseerGen for DisputeValidCandidates { @@ -83,8 +79,8 @@ impl OverseerGen for DisputeValidCandidates { { let spawner = args.spawner.clone(); let validation_filter = ReplaceValidationResult::new( - self.opts.fake_validation, - self.opts.fake_validation_error, + self.fake_validation, + self.fake_validation_error, SpawnGlue(spawner.clone()), ); From 9f153320f3d24ea28974905271db1d95f0e8c5d2 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Tue, 11 Oct 2022 11:19:52 +0000 Subject: [PATCH 2/2] fix lonely test Signed-off-by: Andrei Sandu --- node/malus/src/malus.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/malus/src/malus.rs b/node/malus/src/malus.rs index d1d30cdd7233..aa14b8e3d38f 100644 --- a/node/malus/src/malus.rs +++ b/node/malus/src/malus.rs @@ -126,7 +126,7 @@ mod tests { variant: NemesisVariant::DisputeAncestor(run), .. } => { - assert!(run.cmd.base.bob); + assert!(run.cli.run.base.bob); }); } }