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

Malus: add disputed block percentage #6100

Merged
merged 52 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
ed18805
Malus: add disputed block percentage
bredamatt Oct 4, 2022
1eb3844
Cleanup tests
bredamatt Oct 4, 2022
f46e97c
* Replace unwrap with expect and meaningful error message
bredamatt Oct 4, 2022
99bc912
* Remove Inner
bredamatt Oct 4, 2022
a259272
* Rename sampled variable
bredamatt Oct 6, 2022
f371e5e
* Add percentage option to dispute_ancestor
bredamatt Oct 6, 2022
f3dca67
* Support static probability for `ReplaceValidationResult` proxy
bredamatt Oct 7, 2022
d08d405
* Add `--percentage` to `back-garbage-candidate` variant
bredamatt Oct 7, 2022
e9a1b3e
* Add probabilistic behavior to `dispute-ancestor` variant
bredamatt Oct 7, 2022
4fff00b
* More descriptive comments
bredamatt Oct 7, 2022
bfe0aa7
* cargo +nightly fmt --all
bredamatt Oct 7, 2022
4704e98
* Move Bernoulli distributrion to ReplaceValidationResult constructor
bredamatt Oct 7, 2022
0ec9bc1
* Remove dangling comment
bredamatt Oct 7, 2022
563fa17
* Consistent log
bredamatt Oct 7, 2022
f789958
* Add logs based on sampled value
bredamatt Oct 7, 2022
decb9e2
* Cargo +nightly fmt --all
bredamatt Oct 7, 2022
3ad5cec
* Remove unused percentage attributed after moving Bernoulli to const…
bredamatt Oct 10, 2022
5001fa5
Squashed commit of the following:
bredamatt Oct 10, 2022
b6e446e
Revert "Squashed commit of the following:"
bredamatt Oct 10, 2022
0a4d2b9
Companion for BEEFY: Simplify hashing for pallet-beefy-mmr (#6098)
serban300 Oct 4, 2022
dffb976
Keep sessions in window for the full unfinalized chain (#6054)
sandreim Oct 4, 2022
89d1f31
Bump lru from 0.7.8 to 0.8.0 (#6060)
dependabot[bot] Oct 4, 2022
b012597
Batch vote import in dispute-distribution (#5894)
eskimor Oct 4, 2022
2fd74d9
Add unknown words (#6105)
eskimor Oct 4, 2022
7e89bab
Buffered connection management for collator-protocol (#6022)
slumber Oct 5, 2022
c169279
Properly migrate weights to v2 (#6091)
KiChjang Oct 5, 2022
233c158
Pass through `runtime-benchmark` feature (#6110)
athei Oct 5, 2022
1655839
Companion for #11649: Bound uses of `Call` (#5729)
gavofyork Oct 5, 2022
e2a977a
update kvdb & co (#6111)
ordian Oct 5, 2022
4a6cf48
Skip `unexpected metric type`
bkontur Oct 6, 2022
78b8294
service: use MmrRootProvider as custom BEEFY payload provider (compan…
acatangiu Oct 6, 2022
82f7ad5
Maximum value for `MultiplierUpdate` (#6021)
Szegoo Oct 6, 2022
978d87f
Companion for upgrading pin-project (#6118)
bkchr Oct 7, 2022
0717246
Companion for 12109 (#5929)
Lezek123 Oct 9, 2022
1e96dfd
Add event to asset claim (#6029)
girazoki Oct 10, 2022
857e635
Fix flaky test (#6131)
slumber Oct 10, 2022
96185c3
ci/guide: install mdbook-graphviz (#6119)
ordian Oct 10, 2022
612302c
Revert "Squashed commit of the following:"
bredamatt Oct 10, 2022
35af7ad
Merge branch 'master' of github.com:paritytech/polkadot into bredamat…
bredamatt Oct 10, 2022
cf3f453
* Remove unused imports
bredamatt Oct 10, 2022
f1440e7
* cargo +nightly fmt --all
bredamatt Oct 10, 2022
6f54587
Make tweaks based on PR comments
bredamatt Oct 11, 2022
9842ee9
unit test related to gum formatting
bredamatt Oct 11, 2022
56347c6
cargo +nightly fmt --all
bredamatt Oct 11, 2022
4a7dd91
Merge branch 'master' of github.com:paritytech/polkadot into bredamat…
bredamatt Oct 12, 2022
72591a9
Resolve merge conflicts
bredamatt Oct 12, 2022
23d9498
cargo +nightly fmt --all
bredamatt Oct 12, 2022
be1f5a9
Fix tests so they use cli rather than cmd
bredamatt Oct 12, 2022
cdc68c4
CI unused import check fix
bredamatt Oct 12, 2022
dd96c47
Move info! log to startup
bredamatt Oct 12, 2022
5c20d8c
make info log more comprehensible
bredamatt Oct 12, 2022
7529e94
Merge branch 'master' of github.com:paritytech/polkadot into bredamat…
bredamatt Oct 13, 2022
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
19 changes: 10 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion node/malus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ assert_matches = "1.5"
async-trait = "0.1.57"
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
clap = { version = "3.1", features = ["derive"] }
clap = { version = "3.2.21", features = ["derive"] }
futures = "0.3.21"
futures-timer = "3.0.2"
gum = { package = "tracing-gum", path = "../gum/" }
erasure = { package = "polkadot-erasure-coding", path = "../../erasure-coding" }
rand = "0.8.5"

[features]
default = []
Expand Down
93 changes: 86 additions & 7 deletions node/malus/src/malus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(SuggestGarbageCandidateOptions),
/// Back a candidate with a specifically crafted proof of validity.
BackGarbageCandidate(RunCmd),
BackGarbageCandidate(BackGarbageCandidateOptions),
/// Delayed disputing of ancestors that are perfectly fine.
DisputeAncestor(DisputeAncestorOptions),

Expand Down Expand Up @@ -66,13 +66,19 @@ impl MalusCli {
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::BackGarbageCandidate(opts) => polkadot_cli::run_node(
run_cmd(opts.clone().cmd),
BackGarbageCandidateWrapper::new(opts),
finality_delay,
)?,
NemesisVariant::SuggestGarbageCandidate(opts) => polkadot_cli::run_node(
run_cmd(opts.clone().cmd),
SuggestGarbageCandidateWrapper::new(opts),
finality_delay,
)?,
NemesisVariant::DisputeAncestor(opts) => polkadot_cli::run_node(
bredamatt marked this conversation as resolved.
Show resolved Hide resolved
run_cmd(opts.clone().cmd),
DisputeValidCandidates::new(opts),
DisputeValidCandidateWrapper::new(opts),
finality_delay,
)?,
NemesisVariant::PvfPrepareWorker(cmd) => {
Expand Down Expand Up @@ -129,4 +135,77 @@ mod tests {
assert!(run.cmd.base.bob);
});
}

#[test]
fn percentage_works_suggest_garbage() {
let cli = MalusCli::try_parse_from(IntoIterator::into_iter([
"malus",
"suggest-garbage-candidate",
"--percentage",
"100",
"--bob",
]))
.unwrap();
assert_matches::assert_matches!(cli, MalusCli {
variant: NemesisVariant::SuggestGarbageCandidate(run),
..
} => {
assert!(run.cmd.base.bob);
});
}

#[test]
fn percentage_works_dispute_ancestor() {
let cli = MalusCli::try_parse_from(IntoIterator::into_iter([
"malus",
"dispute-ancestor",
"--percentage",
"100",
"--bob",
]))
.unwrap();
assert_matches::assert_matches!(cli, MalusCli {
variant: NemesisVariant::DisputeAncestor(run),
..
} => {
assert!(run.cmd.base.bob);
});
}

#[test]
fn percentage_works_back_garbage() {
let cli = MalusCli::try_parse_from(IntoIterator::into_iter([
"malus",
"back-garbage-candidate",
"--percentage",
"100",
"--bob",
]))
.unwrap();
assert_matches::assert_matches!(cli, MalusCli {
variant: NemesisVariant::BackGarbageCandidate(run),
..
} => {
assert!(run.cmd.base.bob);
});
}

#[test]
#[should_panic]
bredamatt marked this conversation as resolved.
Show resolved Hide resolved
fn validate_range_for_percentage() {
let cli = MalusCli::try_parse_from(IntoIterator::into_iter([
"malus",
"suggest-garbage-candidate",
"--percentage",
"101",
"--bob",
]))
.unwrap();
assert_matches::assert_matches!(cli, MalusCli {
variant: NemesisVariant::DisputeAncestor(run),
..
} => {
assert!(run.cmd.base.bob);
});
}
}
28 changes: 26 additions & 2 deletions node/malus/src/variants/back_garbage_candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use polkadot_cli::{
OverseerConnector, OverseerGen, OverseerGenArgs, OverseerHandle, ParachainHost,
ProvideRuntimeApi,
},
RunCmd,
};
use polkadot_node_subsystem::SpawnGlue;
use sp_core::traits::SpawnNamed;
Expand All @@ -36,11 +37,33 @@ use crate::{

use std::sync::Arc;

#[derive(Clone, Debug, clap::Parser)]
#[clap(rename_all = "kebab-case")]
#[allow(missing_docs)]
pub struct BackGarbageCandidateOptions {
/// Determines the percentage of garbage candidates that should be backed.
/// Defaults to 100% of garbage candidates being backed.
#[clap(short, long, ignore_case = true, default_value_t = 100, value_parser = clap::value_parser!(u8).range(0..=100))]
pub percentage: u8,

#[clap(flatten)]
pub cmd: RunCmd,
}

/// Generates an overseer that replaces the candidate validation subsystem with our malicious
/// variant.
pub(crate) struct BackGarbageCandidate;
pub(crate) struct BackGarbageCandidateWrapper {
/// Options from CLI
opts: BackGarbageCandidateOptions
}

impl BackGarbageCandidateWrapper {
pub fn new(opts: BackGarbageCandidateOptions) -> Self {
Self { opts }
}
}

impl OverseerGen for BackGarbageCandidate {
impl OverseerGen for BackGarbageCandidateWrapper {
fn generate<'a, Spawner, RuntimeClient>(
&self,
connector: OverseerConnector,
Expand All @@ -55,6 +78,7 @@ impl OverseerGen for BackGarbageCandidate {
let validation_filter = ReplaceValidationResult::new(
FakeCandidateValidation::BackingAndApprovalValid,
FakeCandidateValidationError::InvalidOutputs,
f64::from(self.opts.percentage),
SpawnGlue(spawner),
);

Expand Down
Loading