malus: add finality_delay cli flag (#5770)

* add malus_finality_delay flag

* cargo update -p sp-io

* no warnings when malus is disabled

* subpar workaround for feature unification problem

* remove malus_finality_delay from regular cli

* document finality_delay param, rename cli arg
This commit is contained in:
Andronik
2022-07-23 01:24:33 +02:00
committed by GitHub
parent d6334447ae
commit b1f8445d62
6 changed files with 40 additions and 6 deletions
+6 -2
View File
@@ -53,6 +53,8 @@ enum NemesisVariant {
struct MalusCli {
#[clap(subcommand)]
pub variant: NemesisVariant,
/// Sets the minimum delay between the best and finalized block.
pub finality_delay: Option<u32>,
}
fn run_cmd(run: RunCmd) -> Cli {
@@ -62,14 +64,16 @@ fn run_cmd(run: RunCmd) -> Cli {
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)?,
polkadot_cli::run_node(run_cmd(cmd), BackGarbageCandidate, finality_delay)?,
NemesisVariant::SuggestGarbageCandidate(cmd) =>
polkadot_cli::run_node(run_cmd(cmd), BackGarbageCandidateWrapper)?,
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::PvfPrepareWorker(cmd) => {
#[cfg(target_os = "android")]
+15 -1
View File
@@ -725,6 +725,7 @@ pub fn new_full<RuntimeApi, ExecutorDispatch, OverseerGenerator>(
overseer_enable_anyways: bool,
overseer_gen: OverseerGenerator,
overseer_message_channel_capacity_override: Option<usize>,
_malus_finality_delay: Option<u32>,
hwbench: Option<sc_sysinfo::HwBench>,
) -> Result<NewFull<Arc<FullClient<RuntimeApi, ExecutorDispatch>>>, Error>
where
@@ -1222,7 +1223,15 @@ where
// add a custom voting rule to temporarily stop voting for new blocks
// after the given pause block is finalized and restarting after the
// given delay.
let builder = grandpa::VotingRulesBuilder::default();
let mut builder = grandpa::VotingRulesBuilder::default();
#[cfg(not(feature = "malus"))]
let _malus_finality_delay = None;
if let Some(delay) = _malus_finality_delay {
info!(?delay, "Enabling malus finality delay",);
builder = builder.add(grandpa::BeforeBestBlockBy(delay));
};
let voting_rule = match grandpa_pause {
Some((block, delay)) => {
@@ -1350,6 +1359,7 @@ pub fn build_full(
overseer_enable_anyways: bool,
overseer_gen: impl OverseerGen,
overseer_message_channel_override: Option<usize>,
malus_finality_delay: Option<u32>,
hwbench: Option<sc_sysinfo::HwBench>,
) -> Result<NewFull<Client>, Error> {
#[cfg(feature = "rococo-native")]
@@ -1368,6 +1378,7 @@ pub fn build_full(
overseer_enable_anyways,
overseer_gen,
overseer_message_channel_override,
malus_finality_delay,
hwbench,
)
.map(|full| full.with_client(Client::Rococo))
@@ -1386,6 +1397,7 @@ pub fn build_full(
overseer_enable_anyways,
overseer_gen,
overseer_message_channel_override,
malus_finality_delay,
hwbench,
)
.map(|full| full.with_client(Client::Kusama))
@@ -1404,6 +1416,7 @@ pub fn build_full(
overseer_enable_anyways,
overseer_gen,
overseer_message_channel_override,
malus_finality_delay,
hwbench,
)
.map(|full| full.with_client(Client::Westend))
@@ -1425,6 +1438,7 @@ pub fn build_full(
gum::warn!("Channel capacity should _never_ be tampered with on polkadot!");
capacity
}),
malus_finality_delay,
hwbench,
)
.map(|full| full.with_client(Client::Polkadot))
+1
View File
@@ -102,6 +102,7 @@ pub fn new_full(
polkadot_service::RealOverseerGen,
None,
None,
None,
)
}