mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-08 04:18:01 +00:00
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>
This commit is contained in:
@@ -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)]
|
||||
|
||||
@@ -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<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")]
|
||||
{
|
||||
@@ -126,7 +126,7 @@ mod tests {
|
||||
variant: NemesisVariant::DisputeAncestor(run),
|
||||
..
|
||||
} => {
|
||||
assert!(run.cmd.base.bob);
|
||||
assert!(run.cli.run.base.bob);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user