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

Commit a28b257

Browse files
bredamattserban300sandreimdependabot[bot]skunert
authored
Malus: add disputed block percentage (#6100)
* Malus: add disputed block percentage * Bump clap to support value_parser with range * Add rand crate and use Bernoulli and Distribution * Add conditional logic based on sampled value from Bernoulli distribution * Add SuggestGarbageCandidateOptions struct * Cleanup tests * * Replace unwrap with expect and meaningful error message * * Remove Inner * Remove intercept_outgoing * * Rename sampled variable * Move info! logs to include candidate hash of malicious candidate * * Add percentage option to dispute_ancestor * * Support static probability for `ReplaceValidationResult` proxy * Update some comments and docs * * Add `--percentage` to `back-garbage-candidate` variant * Rename structs for consistency * * Add probabilistic behavior to `dispute-ancestor` variant * Add probabilistic behavior to `back-garbage-candidate` variant * Rename structs in dispute variant * * More descriptive comments * * cargo +nightly fmt --all * * Move Bernoulli distributrion to ReplaceValidationResult constructor * Rename random_bool to behave_maliciously * * Remove dangling comment * * Consistent log * * Add logs based on sampled value * * Cargo +nightly fmt --all * * Remove unused percentage attributed after moving Bernoulli to constructor * Squashed commit of the following: commit e36cc59 Author: Chris Sosnin <[email protected]> Date: Mon Oct 10 10:06:44 2022 +0400 Fix flaky test (#6131) * Split test + decrease test timeout * fmt * spellcheck commit f85f96c Author: girazoki <[email protected]> Date: Mon Oct 10 06:39:30 2022 +0200 Add event to asset claim (#6029) commit fb0dd8e Author: Leszek Wiesner <[email protected]> Date: Mon Oct 10 00:23:54 2022 +0200 Companion for 12109 (#5929) * Update following `pallet-vesting` configurable `WithdrawReasons` * Update lib.rs * Update lib.rs * Update lib.rs * update lockfile for {"substrate"} * fix warning Co-authored-by: Shawn Tabrizi <[email protected]> Co-authored-by: parity-processbot <> commit 1c786b3 Author: Bastian Köcher <[email protected]> Date: Fri Oct 7 13:40:40 2022 +0200 Companion for upgrading pin-project (#6118) * Companion for upgrading pin-project This will remove some warnings with the latest rustc nightly/stable. paritytech/substrate#12426 * update lockfile for {"substrate"} Co-authored-by: parity-processbot <> commit 3d6b563 Author: Sergej Sakac <[email protected]> Date: Thu Oct 6 19:20:58 2022 +0200 Maximum value for `MultiplierUpdate` (#6021) * update multiplier * fix * update lockfile for {"substrate"} * fmt * fix typo Co-authored-by: parity-processbot <> commit 09f340c Author: Adrian Catangiu <[email protected]> Date: Thu Oct 6 12:58:39 2022 +0300 service: use MmrRootProvider as custom BEEFY payload provider (companion for 12428) (#6112) * service: use MmrRootProvider as custom BEEFY payload provider * update lockfile for {"substrate"} Co-authored-by: parity-processbot <> commit d12042f Author: Branislav Kontur <[email protected]> Date: Thu Oct 6 10:03:34 2022 +0200 Skip `unexpected metric type` * Dump more info for `unexpected metric type` * Skip `unexpected metric type` commit 3646202 Author: Andronik <[email protected]> Date: Thu Oct 6 00:36:51 2022 +0200 update kvdb & co (#6111) * toml changes * REVERTME: patch * adapt parachains db interface * fix Cargo.toml patch after master rebase * fix av-store * fix chain-selection * fix parachains-db? * Revert "fix Cargo.toml patch after master rebase" This reverts commit 3afcbf0. * Revert "REVERTME: patch" This reverts commit 464b717. * Use `Ok` imported from prelude Co-authored-by: Bastian Köcher <[email protected]> * update lockfile for {"substrate"} * Revert "update lockfile for {"substrate"}" This reverts commit fdc623d. * cargo update -p sp-io Co-authored-by: Bastian Köcher <[email protected]> Co-authored-by: parity-processbot <> commit 7870daf Author: Gavin Wood <[email protected]> Date: Wed Oct 5 22:17:59 2022 +0100 Companion for #11649: Bound uses of `Call` (#5729) * Fixes * Clear out old weights Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Resolve merges Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Fix weight traits Signed-off-by: Oliver Tale-Yazdi <[email protected]> * polkadot runtime: Clippy Signed-off-by: Oliver Tale-Yazdi <[email protected]> * rococo runtime: update pallet configs Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Add preimage migration Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Add all migrations Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Democracy is not on Westend Signed-off-by: Oliver Tale-Yazdi <[email protected]> * [Migration] Refund stored multisig calls (#6075) * Add Preimages to referenda config Needed since Gov V2 just merged. Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Update weights Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Add multisig migration to Westend+Rococo Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Fix Executive syntax Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Bump Substrate Signed-off-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: parity-processbot <> Co-authored-by: Roman Useinov <[email protected]> commit df4a1c3 Author: Alexander Theißen <[email protected]> Date: Wed Oct 5 15:15:07 2022 +0200 Pass through `runtime-benchmark` feature (#6110) commit 3eb61f8 Author: Keith Yeung <[email protected]> Date: Wed Oct 5 17:47:15 2022 +0800 Properly migrate weights to v2 (#6091) * Create migration for config pallet * Use XcmWeight in XCM pallet extrinsics * Link to PR in doc comment * cargo fmt * Fix tests * Fix tests * Remove unused import * Update runtime/parachains/src/configuration/migration.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Add missing on_runtime_upgrade implementation * Use new migration API * cargo fmt * Fix log message Co-authored-by: Oliver Tale-Yazdi <[email protected]> commit edd6499 Author: Chris Sosnin <[email protected]> Date: Wed Oct 5 11:48:50 2022 +0400 Buffered connection management for collator-protocol (#6022) * Extract metrics into a separate module * Introduce validators buffer * Integrate buffer into the subsystem * Only reconnect on new advertisements * Test * comma * doc comment * Make capacity buffer compile time non-zero * Add doc comments * nits * remove derives * review * better naming * check timeout * Extract interval stream into lib * Ensure collator disconnects after timeout * spellcheck * rename buf * Remove double interval * Add a log on timeout * Cleanup buffer on timeout commit c913107 Author: Robert Klotzner <[email protected]> Date: Tue Oct 4 18:47:52 2022 +0200 Add unknown words (#6105) commit ce430c2 Author: Robert Klotzner <[email protected]> Date: Tue Oct 4 18:02:05 2022 +0200 Batch vote import in dispute-distribution (#5894) * Start work on batching in dispute-distribution. * Guide work. * More guide changes. Still very much WIP. * Finish guide changes. * Clarification * Adjust argument about slashing. * WIP: Add constants to receiver. * Maintain order of disputes. * dispute-distribuion sender Rate limit. * Cleanup * WIP: dispute-distribution receiver. - [ ] Rate limiting - [ ] Batching * WIP: Batching. * fmt * Update `PeerQueues` to maintain more invariants. * WIP: Batching. * Small cleanup * Batching logic. * Some integration work. * Finish. Missing: Tests * Typo. * Docs. * Report missing metric. * Doc pass. * Tests for waiting_queue. * Speed up some crypto by 10x. * Fix redundant import. * Add some tracing. * Better sender rate limit * Some tests. * Tests * Add logging to rate limiter * Update roadmap/implementers-guide/src/node/disputes/dispute-distribution.md Co-authored-by: Tsvetomir Dimitrov <[email protected]> * Update roadmap/implementers-guide/src/node/disputes/dispute-distribution.md Co-authored-by: Tsvetomir Dimitrov <[email protected]> * Update node/network/dispute-distribution/src/receiver/mod.rs Co-authored-by: Tsvetomir Dimitrov <[email protected]> * Review feedback. * Also log peer in log messages. * Fix indentation. * waker -> timer * Guide improvement. * Remove obsolete comment. * waker -> timer * Fix spell complaints. * Fix Cargo.lock Co-authored-by: Tsvetomir Dimitrov <[email protected]> commit efb82ef Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue Oct 4 11:28:21 2022 +0000 Bump lru from 0.7.8 to 0.8.0 (#6060) * Bump lru from 0.7.8 to 0.8.0 Bumps [lru](https://github.com/jeromefroe/lru-rs) from 0.7.8 to 0.8.0. - [Release notes](https://github.com/jeromefroe/lru-rs/releases) - [Changelog](https://github.com/jeromefroe/lru-rs/blob/master/CHANGELOG.md) - [Commits](jeromefroe/lru-rs@0.7.8...0.8.0) --- updated-dependencies: - dependency-name: lru dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * Change `LruCache` paramerter to `NonZeroUsize` * Change type of `session_cache_lru_size` to `NonZeroUsize` * Add expects instead of unwrap Co-authored-by: Bastian Köcher <[email protected]> * Use match to get rid of expects Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sebastian Kunert <[email protected]> Co-authored-by: Bastian Köcher <[email protected]> commit 60554e1 Author: Andrei Sandu <[email protected]> Date: Tue Oct 4 13:36:42 2022 +0300 Keep sessions in window for the full unfinalized chain (#6054) * Impl dynamic window size. Keep sessions for unfinalized chain Signed-off-by: Andrei Sandu <[email protected]> * feedback Signed-off-by: Andrei Sandu <[email protected]> * Stretch also in contructor plus tests Signed-off-by: Andrei Sandu <[email protected]> * review feedback Signed-off-by: Andrei Sandu <[email protected]> * fix approval-voting tests Signed-off-by: Andrei Sandu <[email protected]> * grunting: dispute coordinator tests Signed-off-by: Andrei Sandu <[email protected]> Signed-off-by: Andrei Sandu <[email protected]> commit 4ddf0ff Author: Serban Iorga <[email protected]> Date: Tue Oct 4 12:25:48 2022 +0300 Companion for BEEFY: Simplify hashing for pallet-beefy-mmr (#6098) * beefy-mmr: Simplify hashing * update lockfile for {"substrate"} Co-authored-by: parity-processbot <> * Revert "Squashed commit of the following:" This reverts commit 5001fa5. * Companion for BEEFY: Simplify hashing for pallet-beefy-mmr (#6098) * beefy-mmr: Simplify hashing * update lockfile for {"substrate"} Co-authored-by: parity-processbot <> * Keep sessions in window for the full unfinalized chain (#6054) * Impl dynamic window size. Keep sessions for unfinalized chain Signed-off-by: Andrei Sandu <[email protected]> * feedback Signed-off-by: Andrei Sandu <[email protected]> * Stretch also in contructor plus tests Signed-off-by: Andrei Sandu <[email protected]> * review feedback Signed-off-by: Andrei Sandu <[email protected]> * fix approval-voting tests Signed-off-by: Andrei Sandu <[email protected]> * grunting: dispute coordinator tests Signed-off-by: Andrei Sandu <[email protected]> Signed-off-by: Andrei Sandu <[email protected]> * Bump lru from 0.7.8 to 0.8.0 (#6060) * Bump lru from 0.7.8 to 0.8.0 Bumps [lru](https://github.com/jeromefroe/lru-rs) from 0.7.8 to 0.8.0. - [Release notes](https://github.com/jeromefroe/lru-rs/releases) - [Changelog](https://github.com/jeromefroe/lru-rs/blob/master/CHANGELOG.md) - [Commits](jeromefroe/lru-rs@0.7.8...0.8.0) --- updated-dependencies: - dependency-name: lru dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * Change `LruCache` paramerter to `NonZeroUsize` * Change type of `session_cache_lru_size` to `NonZeroUsize` * Add expects instead of unwrap Co-authored-by: Bastian Köcher <[email protected]> * Use match to get rid of expects Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sebastian Kunert <[email protected]> Co-authored-by: Bastian Köcher <[email protected]> * Batch vote import in dispute-distribution (#5894) * Start work on batching in dispute-distribution. * Guide work. * More guide changes. Still very much WIP. * Finish guide changes. * Clarification * Adjust argument about slashing. * WIP: Add constants to receiver. * Maintain order of disputes. * dispute-distribuion sender Rate limit. * Cleanup * WIP: dispute-distribution receiver. - [ ] Rate limiting - [ ] Batching * WIP: Batching. * fmt * Update `PeerQueues` to maintain more invariants. * WIP: Batching. * Small cleanup * Batching logic. * Some integration work. * Finish. Missing: Tests * Typo. * Docs. * Report missing metric. * Doc pass. * Tests for waiting_queue. * Speed up some crypto by 10x. * Fix redundant import. * Add some tracing. * Better sender rate limit * Some tests. * Tests * Add logging to rate limiter * Update roadmap/implementers-guide/src/node/disputes/dispute-distribution.md Co-authored-by: Tsvetomir Dimitrov <[email protected]> * Update roadmap/implementers-guide/src/node/disputes/dispute-distribution.md Co-authored-by: Tsvetomir Dimitrov <[email protected]> * Update node/network/dispute-distribution/src/receiver/mod.rs Co-authored-by: Tsvetomir Dimitrov <[email protected]> * Review feedback. * Also log peer in log messages. * Fix indentation. * waker -> timer * Guide improvement. * Remove obsolete comment. * waker -> timer * Fix spell complaints. * Fix Cargo.lock Co-authored-by: Tsvetomir Dimitrov <[email protected]> * Add unknown words (#6105) * Buffered connection management for collator-protocol (#6022) * Extract metrics into a separate module * Introduce validators buffer * Integrate buffer into the subsystem * Only reconnect on new advertisements * Test * comma * doc comment * Make capacity buffer compile time non-zero * Add doc comments * nits * remove derives * review * better naming * check timeout * Extract interval stream into lib * Ensure collator disconnects after timeout * spellcheck * rename buf * Remove double interval * Add a log on timeout * Cleanup buffer on timeout * Properly migrate weights to v2 (#6091) * Create migration for config pallet * Use XcmWeight in XCM pallet extrinsics * Link to PR in doc comment * cargo fmt * Fix tests * Fix tests * Remove unused import * Update runtime/parachains/src/configuration/migration.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Add missing on_runtime_upgrade implementation * Use new migration API * cargo fmt * Fix log message Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Pass through `runtime-benchmark` feature (#6110) * Companion for #11649: Bound uses of `Call` (#5729) * Fixes * Clear out old weights Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Resolve merges Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Fix weight traits Signed-off-by: Oliver Tale-Yazdi <[email protected]> * polkadot runtime: Clippy Signed-off-by: Oliver Tale-Yazdi <[email protected]> * rococo runtime: update pallet configs Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Add preimage migration Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Add all migrations Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Democracy is not on Westend Signed-off-by: Oliver Tale-Yazdi <[email protected]> * [Migration] Refund stored multisig calls (#6075) * Add Preimages to referenda config Needed since Gov V2 just merged. Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Update weights Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Add multisig migration to Westend+Rococo Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Fix Executive syntax Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Bump Substrate Signed-off-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: parity-processbot <> Co-authored-by: Roman Useinov <[email protected]> * update kvdb & co (#6111) * toml changes * REVERTME: patch * adapt parachains db interface * fix Cargo.toml patch after master rebase * fix av-store * fix chain-selection * fix parachains-db? * Revert "fix Cargo.toml patch after master rebase" This reverts commit 3afcbf0. * Revert "REVERTME: patch" This reverts commit 464b717. * Use `Ok` imported from prelude Co-authored-by: Bastian Köcher <[email protected]> * update lockfile for {"substrate"} * Revert "update lockfile for {"substrate"}" This reverts commit fdc623d. * cargo update -p sp-io Co-authored-by: Bastian Köcher <[email protected]> Co-authored-by: parity-processbot <> * Skip `unexpected metric type` * Dump more info for `unexpected metric type` * Skip `unexpected metric type` * service: use MmrRootProvider as custom BEEFY payload provider (companion for 12428) (#6112) * service: use MmrRootProvider as custom BEEFY payload provider * update lockfile for {"substrate"} Co-authored-by: parity-processbot <> * Maximum value for `MultiplierUpdate` (#6021) * update multiplier * fix * update lockfile for {"substrate"} * fmt * fix typo Co-authored-by: parity-processbot <> * Companion for upgrading pin-project (#6118) * Companion for upgrading pin-project This will remove some warnings with the latest rustc nightly/stable. paritytech/substrate#12426 * update lockfile for {"substrate"} Co-authored-by: parity-processbot <> * Companion for 12109 (#5929) * Update following `pallet-vesting` configurable `WithdrawReasons` * Update lib.rs * Update lib.rs * Update lib.rs * update lockfile for {"substrate"} * fix warning Co-authored-by: Shawn Tabrizi <[email protected]> Co-authored-by: parity-processbot <> * Add event to asset claim (#6029) * Fix flaky test (#6131) * Split test + decrease test timeout * fmt * spellcheck * ci/guide: install mdbook-graphviz (#6119) * ci/guide: install mdbook-graphviz * install graphviz in build-implementers-guide * Update scripts/ci/gitlab/pipeline/build.yml Co-authored-by: Alexander Samusev <[email protected]> * Revert "Squashed commit of the following:" This reverts commit 5001fa5. * * Remove unused imports * * cargo +nightly fmt --all * Make tweaks based on PR comments * unit test related to gum formatting * cargo +nightly fmt --all * Resolve merge conflicts * cargo +nightly fmt --all * Fix tests so they use cli rather than cmd * CI unused import check fix * Move info! log to startup * make info log more comprehensible Signed-off-by: Andrei Sandu <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Serban Iorga <[email protected]> Co-authored-by: Andrei Sandu <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sebastian Kunert <[email protected]> Co-authored-by: Bastian Köcher <[email protected]> Co-authored-by: Robert Klotzner <[email protected]> Co-authored-by: Tsvetomir Dimitrov <[email protected]> Co-authored-by: Chris Sosnin <[email protected]> Co-authored-by: Keith Yeung <[email protected]> Co-authored-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Alexander Theißen <[email protected]> Co-authored-by: Gavin Wood <[email protected]> Co-authored-by: Roman Useinov <[email protected]> Co-authored-by: Andronik <[email protected]> Co-authored-by: Branislav Kontur <[email protected]> Co-authored-by: Adrian Catangiu <[email protected]> Co-authored-by: Sergej Sakac <[email protected]> Co-authored-by: Leszek Wiesner <[email protected]> Co-authored-by: Shawn Tabrizi <[email protected]> Co-authored-by: girazoki <[email protected]> Co-authored-by: Alexander Samusev <[email protected]>
1 parent 0398050 commit a28b257

File tree

8 files changed

+445
-216
lines changed

8 files changed

+445
-216
lines changed

Cargo.lock

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/malus/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ assert_matches = "1.5"
2929
async-trait = "0.1.57"
3030
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
3131
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
32-
clap = { version = "3.1", features = ["derive"] }
32+
clap = { version = "3.2.21", features = ["derive"] }
3333
futures = "0.3.21"
3434
futures-timer = "3.0.2"
3535
gum = { package = "tracing-gum", path = "../gum/" }
3636
erasure = { package = "polkadot-erasure-coding", path = "../../erasure-coding" }
37+
rand = "0.8.5"
3738

3839
[features]
3940
default = []

node/malus/src/malus.rs

Lines changed: 96 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
1919
use clap::Parser;
2020
use color_eyre::eyre;
21-
use polkadot_cli::Cli;
2221

2322
pub(crate) mod interceptor;
2423
pub(crate) mod shared;
@@ -33,9 +32,9 @@ use variants::*;
3332
#[clap(rename_all = "kebab-case")]
3433
enum NemesisVariant {
3534
/// Suggest a candidate with an invalid proof of validity.
36-
SuggestGarbageCandidate(Cli),
35+
SuggestGarbageCandidate(SuggestGarbageCandidateOptions),
3736
/// Back a candidate with a specifically crafted proof of validity.
38-
BackGarbageCandidate(Cli),
37+
BackGarbageCandidate(BackGarbageCandidateOptions),
3938
/// Delayed disputing of ancestors that are perfectly fine.
4039
DisputeAncestor(DisputeAncestorOptions),
4140

@@ -62,16 +61,31 @@ impl MalusCli {
6261
fn launch(self) -> eyre::Result<()> {
6362
let finality_delay = self.finality_delay;
6463
match self.variant {
65-
NemesisVariant::BackGarbageCandidate(cli) =>
66-
polkadot_cli::run_node(cli, BackGarbageCandidate, finality_delay)?,
67-
NemesisVariant::SuggestGarbageCandidate(cli) =>
68-
polkadot_cli::run_node(cli, BackGarbageCandidateWrapper, finality_delay)?,
64+
NemesisVariant::BackGarbageCandidate(opts) => {
65+
let BackGarbageCandidateOptions { percentage, cli } = opts;
66+
67+
polkadot_cli::run_node(cli, BackGarbageCandidates { percentage }, finality_delay)?
68+
},
69+
NemesisVariant::SuggestGarbageCandidate(opts) => {
70+
let SuggestGarbageCandidateOptions { percentage, cli } = opts;
71+
72+
polkadot_cli::run_node(
73+
cli,
74+
SuggestGarbageCandidates { percentage },
75+
finality_delay,
76+
)?
77+
},
6978
NemesisVariant::DisputeAncestor(opts) => {
70-
let DisputeAncestorOptions { fake_validation, fake_validation_error, cli } = opts;
79+
let DisputeAncestorOptions {
80+
fake_validation,
81+
fake_validation_error,
82+
percentage,
83+
cli,
84+
} = opts;
7185

7286
polkadot_cli::run_node(
7387
cli,
74-
DisputeValidCandidates { fake_validation, fake_validation_error },
88+
DisputeValidCandidates { fake_validation, fake_validation_error, percentage },
7589
finality_delay,
7690
)?
7791
},
@@ -129,4 +143,77 @@ mod tests {
129143
assert!(run.cli.run.base.bob);
130144
});
131145
}
146+
147+
#[test]
148+
fn percentage_works_suggest_garbage() {
149+
let cli = MalusCli::try_parse_from(IntoIterator::into_iter([
150+
"malus",
151+
"suggest-garbage-candidate",
152+
"--percentage",
153+
"100",
154+
"--bob",
155+
]))
156+
.unwrap();
157+
assert_matches::assert_matches!(cli, MalusCli {
158+
variant: NemesisVariant::SuggestGarbageCandidate(run),
159+
..
160+
} => {
161+
assert!(run.cli.run.base.bob);
162+
});
163+
}
164+
165+
#[test]
166+
fn percentage_works_dispute_ancestor() {
167+
let cli = MalusCli::try_parse_from(IntoIterator::into_iter([
168+
"malus",
169+
"dispute-ancestor",
170+
"--percentage",
171+
"100",
172+
"--bob",
173+
]))
174+
.unwrap();
175+
assert_matches::assert_matches!(cli, MalusCli {
176+
variant: NemesisVariant::DisputeAncestor(run),
177+
..
178+
} => {
179+
assert!(run.cli.run.base.bob);
180+
});
181+
}
182+
183+
#[test]
184+
fn percentage_works_back_garbage() {
185+
let cli = MalusCli::try_parse_from(IntoIterator::into_iter([
186+
"malus",
187+
"back-garbage-candidate",
188+
"--percentage",
189+
"100",
190+
"--bob",
191+
]))
192+
.unwrap();
193+
assert_matches::assert_matches!(cli, MalusCli {
194+
variant: NemesisVariant::BackGarbageCandidate(run),
195+
..
196+
} => {
197+
assert!(run.cli.run.base.bob);
198+
});
199+
}
200+
201+
#[test]
202+
#[should_panic]
203+
fn validate_range_for_percentage() {
204+
let cli = MalusCli::try_parse_from(IntoIterator::into_iter([
205+
"malus",
206+
"suggest-garbage-candidate",
207+
"--percentage",
208+
"101",
209+
"--bob",
210+
]))
211+
.unwrap();
212+
assert_matches::assert_matches!(cli, MalusCli {
213+
variant: NemesisVariant::DisputeAncestor(run),
214+
..
215+
} => {
216+
assert!(run.cli.run.base.bob);
217+
});
218+
}
132219
}

node/malus/src/variants/back_garbage_candidate.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use polkadot_cli::{
2525
OverseerConnector, OverseerGen, OverseerGenArgs, OverseerHandle, ParachainHost,
2626
ProvideRuntimeApi,
2727
},
28+
Cli,
2829
};
2930
use polkadot_node_subsystem::SpawnGlue;
3031
use sp_core::traits::SpawnNamed;
@@ -36,11 +37,27 @@ use crate::{
3637

3738
use std::sync::Arc;
3839

40+
#[derive(Debug, clap::Parser)]
41+
#[clap(rename_all = "kebab-case")]
42+
#[allow(missing_docs)]
43+
pub struct BackGarbageCandidateOptions {
44+
/// Determines the percentage of garbage candidates that should be backed.
45+
/// Defaults to 100% of garbage candidates being backed.
46+
#[clap(short, long, ignore_case = true, default_value_t = 100, value_parser = clap::value_parser!(u8).range(0..=100))]
47+
pub percentage: u8,
48+
49+
#[clap(flatten)]
50+
pub cli: Cli,
51+
}
52+
3953
/// Generates an overseer that replaces the candidate validation subsystem with our malicious
4054
/// variant.
41-
pub(crate) struct BackGarbageCandidate;
55+
pub(crate) struct BackGarbageCandidates {
56+
/// The probability of behaving maliciously.
57+
pub percentage: u8,
58+
}
4259

43-
impl OverseerGen for BackGarbageCandidate {
60+
impl OverseerGen for BackGarbageCandidates {
4461
fn generate<'a, Spawner, RuntimeClient>(
4562
&self,
4663
connector: OverseerConnector,
@@ -55,6 +72,7 @@ impl OverseerGen for BackGarbageCandidate {
5572
let validation_filter = ReplaceValidationResult::new(
5673
FakeCandidateValidation::BackingAndApprovalValid,
5774
FakeCandidateValidationError::InvalidOutputs,
75+
f64::from(self.percentage),
5876
SpawnGlue(spawner),
5977
);
6078

0 commit comments

Comments
 (0)