mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-23 10:51:10 +00:00
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:
@@ -267,14 +267,21 @@ fn host_perf_check() -> Result<()> {
|
|||||||
/// Launch a node, accepting arguments just like a regular node,
|
/// Launch a node, accepting arguments just like a regular node,
|
||||||
/// accepts an alternative overseer generator, to adjust behavior
|
/// accepts an alternative overseer generator, to adjust behavior
|
||||||
/// for integration tests as needed.
|
/// for integration tests as needed.
|
||||||
|
/// `malus_finality_delay` restrict finality votes of this node
|
||||||
|
/// to be at most `best_block - malus_finality_delay` height.
|
||||||
#[cfg(feature = "malus")]
|
#[cfg(feature = "malus")]
|
||||||
pub fn run_node(run: Cli, overseer_gen: impl service::OverseerGen) -> Result<()> {
|
pub fn run_node(
|
||||||
run_node_inner(run, overseer_gen, |_logger_builder, _config| {})
|
run: Cli,
|
||||||
|
overseer_gen: impl service::OverseerGen,
|
||||||
|
malus_finality_delay: Option<u32>,
|
||||||
|
) -> Result<()> {
|
||||||
|
run_node_inner(run, overseer_gen, malus_finality_delay, |_logger_builder, _config| {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_node_inner<F>(
|
fn run_node_inner<F>(
|
||||||
cli: Cli,
|
cli: Cli,
|
||||||
overseer_gen: impl service::OverseerGen,
|
overseer_gen: impl service::OverseerGen,
|
||||||
|
maybe_malus_finality_delay: Option<u32>,
|
||||||
logger_hook: F,
|
logger_hook: F,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
where
|
where
|
||||||
@@ -340,6 +347,7 @@ where
|
|||||||
false,
|
false,
|
||||||
overseer_gen,
|
overseer_gen,
|
||||||
cli.run.overseer_channel_capacity_override,
|
cli.run.overseer_channel_capacity_override,
|
||||||
|
maybe_malus_finality_delay,
|
||||||
hwbench,
|
hwbench,
|
||||||
)
|
)
|
||||||
.map(|full| full.task_manager)
|
.map(|full| full.task_manager)
|
||||||
@@ -377,7 +385,12 @@ pub fn run() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match &cli.subcommand {
|
match &cli.subcommand {
|
||||||
None => run_node_inner(cli, service::RealOverseerGen, polkadot_node_metrics::logger_hook()),
|
None => run_node_inner(
|
||||||
|
cli,
|
||||||
|
service::RealOverseerGen,
|
||||||
|
None,
|
||||||
|
polkadot_node_metrics::logger_hook(),
|
||||||
|
),
|
||||||
Some(Subcommand::BuildSpec(cmd)) => {
|
Some(Subcommand::BuildSpec(cmd)) => {
|
||||||
let runner = cli.create_runner(cmd)?;
|
let runner = cli.create_runner(cmd)?;
|
||||||
Ok(runner.sync_run(|config| cmd.run(config.chain_spec, config.network))?)
|
Ok(runner.sync_run(|config| cmd.run(config.chain_spec, config.network))?)
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ enum NemesisVariant {
|
|||||||
struct MalusCli {
|
struct MalusCli {
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
pub variant: NemesisVariant,
|
pub variant: NemesisVariant,
|
||||||
|
/// Sets the minimum delay between the best and finalized block.
|
||||||
|
pub finality_delay: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_cmd(run: RunCmd) -> Cli {
|
fn run_cmd(run: RunCmd) -> Cli {
|
||||||
@@ -62,14 +64,16 @@ fn run_cmd(run: RunCmd) -> Cli {
|
|||||||
impl MalusCli {
|
impl MalusCli {
|
||||||
/// Launch a malus node.
|
/// Launch a malus node.
|
||||||
fn launch(self) -> eyre::Result<()> {
|
fn launch(self) -> eyre::Result<()> {
|
||||||
|
let finality_delay = self.finality_delay;
|
||||||
match self.variant {
|
match self.variant {
|
||||||
NemesisVariant::BackGarbageCandidate(cmd) =>
|
NemesisVariant::BackGarbageCandidate(cmd) =>
|
||||||
polkadot_cli::run_node(run_cmd(cmd), BackGarbageCandidate)?,
|
polkadot_cli::run_node(run_cmd(cmd), BackGarbageCandidate, finality_delay)?,
|
||||||
NemesisVariant::SuggestGarbageCandidate(cmd) =>
|
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(
|
NemesisVariant::DisputeAncestor(opts) => polkadot_cli::run_node(
|
||||||
run_cmd(opts.clone().cmd),
|
run_cmd(opts.clone().cmd),
|
||||||
DisputeValidCandidates::new(opts),
|
DisputeValidCandidates::new(opts),
|
||||||
|
finality_delay,
|
||||||
)?,
|
)?,
|
||||||
NemesisVariant::PvfPrepareWorker(cmd) => {
|
NemesisVariant::PvfPrepareWorker(cmd) => {
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
|
|||||||
@@ -725,6 +725,7 @@ pub fn new_full<RuntimeApi, ExecutorDispatch, OverseerGenerator>(
|
|||||||
overseer_enable_anyways: bool,
|
overseer_enable_anyways: bool,
|
||||||
overseer_gen: OverseerGenerator,
|
overseer_gen: OverseerGenerator,
|
||||||
overseer_message_channel_capacity_override: Option<usize>,
|
overseer_message_channel_capacity_override: Option<usize>,
|
||||||
|
_malus_finality_delay: Option<u32>,
|
||||||
hwbench: Option<sc_sysinfo::HwBench>,
|
hwbench: Option<sc_sysinfo::HwBench>,
|
||||||
) -> Result<NewFull<Arc<FullClient<RuntimeApi, ExecutorDispatch>>>, Error>
|
) -> Result<NewFull<Arc<FullClient<RuntimeApi, ExecutorDispatch>>>, Error>
|
||||||
where
|
where
|
||||||
@@ -1222,7 +1223,15 @@ where
|
|||||||
// add a custom voting rule to temporarily stop voting for new blocks
|
// add a custom voting rule to temporarily stop voting for new blocks
|
||||||
// after the given pause block is finalized and restarting after the
|
// after the given pause block is finalized and restarting after the
|
||||||
// given delay.
|
// 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 {
|
let voting_rule = match grandpa_pause {
|
||||||
Some((block, delay)) => {
|
Some((block, delay)) => {
|
||||||
@@ -1350,6 +1359,7 @@ pub fn build_full(
|
|||||||
overseer_enable_anyways: bool,
|
overseer_enable_anyways: bool,
|
||||||
overseer_gen: impl OverseerGen,
|
overseer_gen: impl OverseerGen,
|
||||||
overseer_message_channel_override: Option<usize>,
|
overseer_message_channel_override: Option<usize>,
|
||||||
|
malus_finality_delay: Option<u32>,
|
||||||
hwbench: Option<sc_sysinfo::HwBench>,
|
hwbench: Option<sc_sysinfo::HwBench>,
|
||||||
) -> Result<NewFull<Client>, Error> {
|
) -> Result<NewFull<Client>, Error> {
|
||||||
#[cfg(feature = "rococo-native")]
|
#[cfg(feature = "rococo-native")]
|
||||||
@@ -1368,6 +1378,7 @@ pub fn build_full(
|
|||||||
overseer_enable_anyways,
|
overseer_enable_anyways,
|
||||||
overseer_gen,
|
overseer_gen,
|
||||||
overseer_message_channel_override,
|
overseer_message_channel_override,
|
||||||
|
malus_finality_delay,
|
||||||
hwbench,
|
hwbench,
|
||||||
)
|
)
|
||||||
.map(|full| full.with_client(Client::Rococo))
|
.map(|full| full.with_client(Client::Rococo))
|
||||||
@@ -1386,6 +1397,7 @@ pub fn build_full(
|
|||||||
overseer_enable_anyways,
|
overseer_enable_anyways,
|
||||||
overseer_gen,
|
overseer_gen,
|
||||||
overseer_message_channel_override,
|
overseer_message_channel_override,
|
||||||
|
malus_finality_delay,
|
||||||
hwbench,
|
hwbench,
|
||||||
)
|
)
|
||||||
.map(|full| full.with_client(Client::Kusama))
|
.map(|full| full.with_client(Client::Kusama))
|
||||||
@@ -1404,6 +1416,7 @@ pub fn build_full(
|
|||||||
overseer_enable_anyways,
|
overseer_enable_anyways,
|
||||||
overseer_gen,
|
overseer_gen,
|
||||||
overseer_message_channel_override,
|
overseer_message_channel_override,
|
||||||
|
malus_finality_delay,
|
||||||
hwbench,
|
hwbench,
|
||||||
)
|
)
|
||||||
.map(|full| full.with_client(Client::Westend))
|
.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!");
|
gum::warn!("Channel capacity should _never_ be tampered with on polkadot!");
|
||||||
capacity
|
capacity
|
||||||
}),
|
}),
|
||||||
|
malus_finality_delay,
|
||||||
hwbench,
|
hwbench,
|
||||||
)
|
)
|
||||||
.map(|full| full.with_client(Client::Polkadot))
|
.map(|full| full.with_client(Client::Polkadot))
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ pub fn new_full(
|
|||||||
polkadot_service::RealOverseerGen,
|
polkadot_service::RealOverseerGen,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ fn main() -> Result<()> {
|
|||||||
polkadot_service::RealOverseerGen,
|
polkadot_service::RealOverseerGen,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
let mut overseer_handle = full_node
|
let mut overseer_handle = full_node
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ fn main() -> Result<()> {
|
|||||||
polkadot_service::RealOverseerGen,
|
polkadot_service::RealOverseerGen,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
let mut overseer_handle = full_node
|
let mut overseer_handle = full_node
|
||||||
|
|||||||
Reference in New Issue
Block a user