Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate zombie past slashing test #7147

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
26 changes: 9 additions & 17 deletions .gitlab/pipeline/zombienet/polkadot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,6 @@ zombienet-polkadot-functional-0004-parachains-disputes-garbage-candidate:
--local-dir="${LOCAL_DIR}/functional"
--test="0004-parachains-garbage-candidate.zndsl"

.zombienet-polkadot-functional-0005-parachains-disputes-past-session:
extends:
- .zombienet-polkadot-common
script:
- /home/nonroot/zombie-net/scripts/ci/run-test-local-env-manager.sh
--local-dir="${LOCAL_DIR}/functional"
--test="0005-parachains-disputes-past-session.zndsl"

zombienet-polkadot-functional-0006-parachains-max-tranche0:
extends:
- .zombienet-polkadot-common
Expand Down Expand Up @@ -188,7 +180,7 @@ zombienet-polkadot-functional-0015-coretime-shared-core:
extends:
- .zombienet-polkadot-common
before_script:
- !reference [ .zombienet-polkadot-common, before_script ]
- !reference [.zombienet-polkadot-common, before_script]
- cp --remove-destination ${LOCAL_DIR}/assign-core.js ${LOCAL_DIR}/functional
script:
- /home/nonroot/zombie-net/scripts/ci/run-test-local-env-manager.sh
Expand All @@ -207,7 +199,7 @@ zombienet-polkadot-functional-0018-shared-core-idle-parachain:
extends:
- .zombienet-polkadot-common
before_script:
- !reference [ .zombienet-polkadot-common, before_script ]
- !reference [.zombienet-polkadot-common, before_script]
- cp --remove-destination ${LOCAL_DIR}/assign-core.js ${LOCAL_DIR}/functional
script:
- /home/nonroot/zombie-net/scripts/ci/run-test-local-env-manager.sh
Expand All @@ -218,7 +210,7 @@ zombienet-polkadot-functional-0019-coretime-collation-fetching-fairness:
extends:
- .zombienet-polkadot-common
before_script:
- !reference [ .zombienet-polkadot-common, before_script ]
- !reference [.zombienet-polkadot-common, before_script]
- cp --remove-destination ${LOCAL_DIR}/assign-core.js ${LOCAL_DIR}/functional
script:
- /home/nonroot/zombie-net/scripts/ci/run-test-local-env-manager.sh
Expand Down Expand Up @@ -354,7 +346,7 @@ zombienet-polkadot-malus-0001-dispute-valid:
- job: build-polkadot-zombienet-tests
artifacts: true
before_script:
- !reference [ ".zombienet-polkadot-common", "before_script" ]
- !reference [".zombienet-polkadot-common", "before_script"]
- export POLKADOT_IMAGE="${ZOMBIENET_INTEGRATION_TEST_IMAGE}"
script:
# we want to use `--no-capture` in zombienet tests.
Expand All @@ -369,7 +361,7 @@ zombienet-polkadot-elastic-scaling-slot-based-3cores:
- job: build-polkadot-zombienet-tests
artifacts: true
before_script:
- !reference [ ".zombienet-polkadot-common", "before_script" ]
- !reference [".zombienet-polkadot-common", "before_script"]
- export POLKADOT_IMAGE="${ZOMBIENET_INTEGRATION_TEST_IMAGE}"
- export CUMULUS_IMAGE="docker.io/paritypr/test-parachain:${PIPELINE_IMAGE_TAG}"
- export X_INFRA_INSTANCE=spot # use spot by default
Expand All @@ -386,7 +378,7 @@ zombienet-polkadot-elastic-scaling-doesnt-break-parachains:
- job: build-polkadot-zombienet-tests
artifacts: true
before_script:
- !reference [ ".zombienet-polkadot-common", "before_script" ]
- !reference [".zombienet-polkadot-common", "before_script"]
- export POLKADOT_IMAGE="${ZOMBIENET_INTEGRATION_TEST_IMAGE}"
- export X_INFRA_INSTANCE=spot # use spot by default
variables:
Expand All @@ -404,7 +396,7 @@ zombienet-polkadot-elastic-scaling-basic-3cores:
- job: build-polkadot-zombienet-tests
artifacts: true
before_script:
- !reference [ ".zombienet-polkadot-common", "before_script" ]
- !reference [".zombienet-polkadot-common", "before_script"]
- export POLKADOT_IMAGE="${ZOMBIENET_INTEGRATION_TEST_IMAGE}"
- export CUMULUS_IMAGE="${COL_IMAGE}"
- export X_INFRA_INSTANCE=spot # use spot by default
Expand All @@ -421,7 +413,7 @@ zombienet-polkadot-functional-sync-backing:
- job: build-polkadot-zombienet-tests
artifacts: true
before_script:
- !reference [ ".zombienet-polkadot-common", "before_script" ]
- !reference [".zombienet-polkadot-common", "before_script"]
- export POLKADOT_IMAGE="${ZOMBIENET_INTEGRATION_TEST_IMAGE}"
# Hardcoded to an old polkadot-parachain image, pre async backing.
- export CUMULUS_IMAGE="docker.io/paritypr/polkadot-parachain-debug:master-99623e62"
Expand All @@ -439,7 +431,7 @@ zombienet-polkadot-functional-async-backing-6-seconds-rate:
- job: build-polkadot-zombienet-tests
artifacts: true
before_script:
- !reference [ ".zombienet-polkadot-common", "before_script" ]
- !reference [".zombienet-polkadot-common", "before_script"]
- export POLKADOT_IMAGE="${ZOMBIENET_INTEGRATION_TEST_IMAGE}"
- export X_INFRA_INSTANCE=spot # use spot by default
script:
Expand Down
4 changes: 4 additions & 0 deletions polkadot/zombienet-sdk-tests/tests/disabling/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

mod slashing;
144 changes: 144 additions & 0 deletions polkadot/zombienet-sdk-tests/tests/disabling/slashing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

//! Test past-session slashing when a malicious validator backs an invalid
//! candidate and a dispute concluding in a future session. We achieve that by
//! making some of the honest nodes go offline.

use anyhow::anyhow;

use crate::helpers::{
assert_blocks_are_being_finalized, assert_para_throughput, wait_for_session_change,
};
use polkadot_primitives::Id as ParaId;
use serde_json::json;
use subxt::{OnlineClient, PolkadotConfig};
use zombienet_sdk::{NetworkConfigBuilder, NetworkNode};

#[tokio::test(flavor = "multi_thread")]
async fn dispute_past_session_slashing() -> Result<(), anyhow::Error> {
let _ = env_logger::try_init_from_env(
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"),
);

let images = zombienet_sdk::environment::get_images_from_env();

let config = NetworkConfigBuilder::new()
.with_relaychain(|r| {
r.with_chain("westend-local")
.with_default_command("polkadot")
.with_default_image(images.polkadot.as_str())
.with_default_args(vec![
"--no-hardware-benchmarks".into(),
"-lparachain=debug".into(),
])
.with_genesis_overrides(json!({
"configuration": {
"config": {
"scheduler_params": {
"group_rotation_frequency": 3,
"max_validators_per_core": 1
},
"needed_approvals": 2
}
}
}))
.with_node(|node| node.with_name("honest-validator-0"))
.with_node(|node| node.with_name("honest-validator-1"))
.with_node(|node| node.with_name("honest-flaky-validator-0"))
.with_node(|node| {
node.with_name("malicious-backer")
.with_command("malus")
.with_subcommand("suggest-garbage-candidate")
.with_args(vec![
"--no-hardware-benchmarks".into(),
"--insecure-validator-i-know-what-i-do".into(),
"-lMALUS=trace,parachain=debug".into(),
])
})
})
.with_parachain(|p| {
p.with_id(1337)
.with_default_command("polkadot-parachain")
.with_default_image(images.cumulus.as_str())
.with_default_args(vec![("-lparachain=debug").into()])
.with_collator(|n| n.with_name("collator-1337"))
})
.with_parachain(|p| {
p.with_id(2025)
.with_default_command("polkadot-parachain")
.with_default_image(images.cumulus.as_str())
.with_default_args(vec![("-lparachain=debug").into()])
.with_collator(|n| n.with_name("collator-2025"))
})
.build()
.map_err(|e| {
let errs = e.into_iter().map(|e| e.to_string()).collect::<Vec<_>>().join(" ");
anyhow!("config errs: {errs}")
})?;

let spawn_fn = zombienet_sdk::environment::get_spawn_fn();
let network = spawn_fn(config).await?;

let malus = network.get_node("malicious-backer")?;
malus.pause().await?;

let honest = network.get_node("honest-validator-0")?;
let relay_client: OnlineClient<PolkadotConfig> = honest.wait_client().await?;

// Wait for some para blocks being produced
assert_para_throughput(&relay_client, 2, [(ParaId::from(1337), 1..5)].into_iter().collect())
.await?;

// Let's initiate a dispute
malus.resume().await?;

let timeout_secs: u64 = 360;
let disputes_total_metric = "polkadot_parachain_candidate_disputes_total";
wait_for_metric(&honest, disputes_total_metric, 1).await;

// Pause first flaky node, so they stop concluding
let flaky_0 = network.get_node("honest-flaky-validator-0")?;
flaky_0.pause().await?;

// Wait for a dispute that will not conclude
let disputes = wait_for_metric(&honest, disputes_total_metric, 2).await;
log::info!("Dispute initiated, now waiting for a session change");

wait_for_session_change(&relay_client).await?;

// Now resume flaky validator
log::info!("Resuming the flaky node - disputes should conclude");
flaky_0.resume().await?;
// We don't need malus anymore
malus.pause().await?;

wait_for_metric(&honest, "polkadot_parachain_candidate_dispute_concluded{validity=\"invalid\"}", disputes).await;
log::info!("A dispute has concluded");

honest
.wait_log_line_count_with_timeout(
"*Successfully reported pending slash*",
true,
1,
timeout_secs,
)
.await?;

assert_blocks_are_being_finalized(&relay_client).await?;

log::info!("Test finished successfully");

Ok(())
}

pub async fn wait_for_metric(node: &NetworkNode, metric: &str, value: u64) -> u64 {
ordian marked this conversation as resolved.
Show resolved Hide resolved
println!("Waiting for {metric} to reach {value}:");
loop {
let current = node.reports(metric).await.unwrap_or(0.0) as u64;
log::debug!("{metric} = {current}");
if current >= value {
return current;
}
}
}
42 changes: 42 additions & 0 deletions polkadot/zombienet-sdk-tests/tests/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use polkadot_primitives::Id as ParaId;
use std::{collections::HashMap, ops::Range};
use subxt::{OnlineClient, PolkadotConfig};
use tokio::time::{sleep, Duration};

#[subxt::subxt(runtime_metadata_path = "metadata-files/rococo-local.scale")]
pub mod rococo {}
Expand Down Expand Up @@ -79,3 +80,44 @@ pub async fn assert_finalized_block_height(
}
Ok(())
}

/// Assert that finality has not stalled.
pub async fn assert_blocks_are_being_finalized(
client: &OnlineClient<PolkadotConfig>,
) -> Result<(), anyhow::Error> {
let mut finalized_blocks = client.blocks().subscribe_finalized().await?;
let first_measurement = finalized_blocks
.next()
.await
.ok_or(anyhow::anyhow!("Can't get finalized block from stream"))??
.number();
sleep(Duration::from_secs(12)).await;
let second_measurement = finalized_blocks
.next()
.await
.ok_or(anyhow::anyhow!("Can't get finalized block from stream"))??
.number();

assert!(second_measurement > first_measurement);

Ok(())
}

/// Wait for a `NewSession` event.
pub async fn wait_for_session_change(
relay_client: &OnlineClient<PolkadotConfig>,
) -> Result<(), anyhow::Error> {
let mut blocks_sub = relay_client.blocks().subscribe_best().await?;

while let Some(block) = blocks_sub.next().await {
let block = block?;
let events = block.events().await?;
let is_session_change = events.has::<rococo::session::events::NewSession>()?;

if is_session_change {
log::info!("Session changed at block {}", block.number());
break
}
}
Ok(())
}
2 changes: 2 additions & 0 deletions polkadot/zombienet-sdk-tests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#[cfg(feature = "zombie-metadata")]
mod helpers;

#[cfg(feature = "zombie-metadata")]
mod disabling;
#[cfg(feature = "zombie-metadata")]
mod elastic_scaling;
#[cfg(feature = "zombie-metadata")]
Expand Down

This file was deleted.

Loading
Loading