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

Expose node subcommands in Malus CLI #6135

Merged
merged 3 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
34 changes: 17 additions & 17 deletions node/malus/src/malus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),

Expand All @@ -57,24 +57,24 @@ struct MalusCli {
pub finality_delay: Option<u32>,
}

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")]
{
Expand Down Expand Up @@ -126,7 +126,7 @@ mod tests {
variant: NemesisVariant::DisputeAncestor(run),
..
} => {
assert!(run.cmd.base.bob);
assert!(run.cli.run.base.bob);
});
}
}
20 changes: 8 additions & 12 deletions node/malus/src/variants/dispute_valid_candidates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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()),
);

Expand Down