Skip to content

Commit 48f69cc

Browse files
authored
malus-collator: implement malicious collator submitting same collation to all backing groups (#6924)
## Issues - [[#5049] Elastic scaling: zombienet tests](#5049) - [[#4526] Add zombienet tests for malicious collators](#4526) ## Description Modified the undying collator to include a malus mode, in which it submits the same collation to all assigned backing groups. ## TODO * [X] Implement malicious collator that submits the same collation to all backing groups; * [X] Avoid the core index check in the collation generation subsystem: https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/node/collation-generation/src/lib.rs#L552-L553; * [X] Resolve the mismatch between the descriptor and the commitments core index: #7104 * [X] Implement `duplicate_collations` test with zombienet-sdk; * [X] Add PRdoc.
1 parent 07d4b46 commit 48f69cc

File tree

15 files changed

+596
-35
lines changed

15 files changed

+596
-35
lines changed

.gitlab/pipeline/zombienet/polkadot.yml

+16
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,19 @@ zombienet-polkadot-functional-async-backing-6-seconds-rate:
464464
- unset NEXTEST_FAILURE_OUTPUT
465465
- unset NEXTEST_SUCCESS_OUTPUT
466466
- cargo nextest run --archive-file ./artifacts/polkadot-zombienet-tests.tar.zst --no-capture -- functional::async_backing_6_seconds_rate::async_backing_6_seconds_rate_test
467+
468+
zombienet-polkadot-functional-duplicate-collations:
469+
extends:
470+
- .zombienet-polkadot-common
471+
needs:
472+
- job: build-polkadot-zombienet-tests
473+
artifacts: true
474+
before_script:
475+
- !reference [ ".zombienet-polkadot-common", "before_script" ]
476+
- export POLKADOT_IMAGE="${ZOMBIENET_INTEGRATION_TEST_IMAGE}"
477+
- export X_INFRA_INSTANCE=spot # use spot by default
478+
script:
479+
# we want to use `--no-capture` in zombienet tests.
480+
- unset NEXTEST_FAILURE_OUTPUT
481+
- unset NEXTEST_SUCCESS_OUTPUT
482+
- cargo nextest run --archive-file ./artifacts/polkadot-zombienet-tests.tar.zst --no-capture -- functional::duplicate_collations::duplicate_collations_test

Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

polkadot/node/test/service/src/chain_spec.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
1919
use pallet_staking::Forcing;
2020
use polkadot_primitives::{
21-
AccountId, AssignmentId, SchedulerParams, ValidatorId, MAX_CODE_SIZE, MAX_POV_SIZE,
21+
node_features, AccountId, AssignmentId, NodeFeatures, SchedulerParams, ValidatorId,
22+
MAX_CODE_SIZE, MAX_POV_SIZE,
2223
};
2324
use polkadot_service::chain_spec::Extensions;
2425
use polkadot_test_runtime::BABE_GENESIS_EPOCH_CONFIG;
@@ -110,6 +111,11 @@ fn polkadot_testnet_genesis(
110111
const ENDOWMENT: u128 = 1_000_000 * DOTS;
111112
const STASH: u128 = 100 * DOTS;
112113

114+
// Prepare node features with V2 receipts enabled.
115+
let mut node_features = NodeFeatures::new();
116+
node_features.resize(node_features::FeatureIndex::CandidateReceiptV2 as usize + 1, false);
117+
node_features.set(node_features::FeatureIndex::CandidateReceiptV2 as u8 as usize, true);
118+
113119
serde_json::json!({
114120
"balances": {
115121
"balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::<Vec<_>>(),
@@ -158,6 +164,7 @@ fn polkadot_testnet_genesis(
158164
no_show_slots: 10,
159165
minimum_validation_upgrade_delay: 5,
160166
max_downward_message_size: 1024,
167+
node_features,
161168
scheduler_params: SchedulerParams {
162169
group_rotation_frequency: 20,
163170
paras_availability_period: 4,

polkadot/parachain/test-parachains/undying/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ codec = { features = ["derive"], workspace = true }
1616
dlmalloc = { features = ["global"], workspace = true }
1717
log = { workspace = true }
1818
polkadot-parachain-primitives = { features = ["wasm-api"], workspace = true }
19+
polkadot-primitives = { workspace = true, default-features = false }
1920
tiny-keccak = { features = ["keccak"], workspace = true }
2021

2122
# We need to make sure the global allocator is disabled until we have support of full substrate externalities
@@ -30,5 +31,6 @@ std = [
3031
"codec/std",
3132
"log/std",
3233
"polkadot-parachain-primitives/std",
34+
"polkadot-primitives/std",
3335
"sp-io/std",
3436
]

polkadot/parachain/test-parachains/undying/collator/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ futures-timer = { workspace = true }
2222
log = { workspace = true, default-features = true }
2323

2424
polkadot-cli = { workspace = true, default-features = true }
25+
polkadot-erasure-coding = { workspace = true, default-features = true }
2526
polkadot-node-primitives = { workspace = true, default-features = true }
2627
polkadot-node-subsystem = { workspace = true, default-features = true }
2728
polkadot-primitives = { workspace = true, default-features = true }
2829
polkadot-service = { features = ["rococo-native"], workspace = true, default-features = true }
2930
test-parachain-undying = { workspace = true }
3031

3132
sc-cli = { workspace = true, default-features = true }
33+
sc-client-api = { workspace = true, default-features = true }
3234
sc-service = { workspace = true, default-features = true }
3335
sp-core = { workspace = true, default-features = true }
3436

polkadot/parachain/test-parachains/undying/collator/src/cli.rs

+13
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ pub struct ExportGenesisWasmCommand {
6161
pub output: Option<PathBuf>,
6262
}
6363

64+
/// Enum representing different types of malicious behaviors for collators.
65+
#[derive(Debug, Parser, Clone, PartialEq, clap::ValueEnum)]
66+
pub enum MalusType {
67+
/// No malicious behavior.
68+
None,
69+
/// Submit the same collations to all assigned cores.
70+
DuplicateCollations,
71+
}
72+
6473
#[allow(missing_docs)]
6574
#[derive(Debug, Parser)]
6675
#[group(skip)]
@@ -81,6 +90,10 @@ pub struct RunCmd {
8190
/// we compute per block.
8291
#[arg(long, default_value_t = 1)]
8392
pub pvf_complexity: u32,
93+
94+
/// Specifies the malicious behavior of the collator.
95+
#[arg(long, value_enum, default_value_t = MalusType::None)]
96+
pub malus_type: MalusType,
8497
}
8598

8699
#[allow(missing_docs)]

0 commit comments

Comments
 (0)