|
| 1 | +// Copyright (C) Parity Technologies (UK) Ltd. |
| 2 | +// This file is part of Polkadot. |
| 3 | + |
| 4 | +// Polkadot is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | + |
| 9 | +// Polkadot is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | + |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +// Test if disputes triggered on finalized blocks out of scope never get to be confirmed and |
| 18 | +// concluded. |
| 19 | + |
| 20 | +use anyhow::anyhow; |
| 21 | + |
| 22 | +use cumulus_zombienet_sdk_helpers::assert_para_throughput; |
| 23 | +use serde_json::json; |
| 24 | +use tokio::time::Duration; |
| 25 | +use zombienet_orchestrator::network::node::LogLineCountOptions; |
| 26 | + |
| 27 | +#[tokio::test(flavor = "multi_thread")] |
| 28 | +async fn dispute_old_finalized() -> Result<(), anyhow::Error> { |
| 29 | + let _ = env_logger::try_init_from_env( |
| 30 | + env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"), |
| 31 | + ); |
| 32 | + let images = zombienet_sdk::environment::get_images_from_env(); |
| 33 | + let config = zombienet_sdk::NetworkConfigBuilder::new() |
| 34 | + .with_relaychain(|r| { |
| 35 | + let r = r |
| 36 | + .with_chain("rococo-local") |
| 37 | + .with_default_command("polkadot") |
| 38 | + .with_default_image(images.polkadot.as_str()) |
| 39 | + .with_default_args(vec![("-lparachain=debug").into()]) |
| 40 | + .with_genesis_overrides(json!({ |
| 41 | + "patch": { |
| 42 | + "configuration" : { |
| 43 | + "config": { |
| 44 | + "needed_approvals": 1, |
| 45 | + "scheduler_params": { |
| 46 | + "max_validators_per_core": 1, |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + })) |
| 52 | + .with_default_resources(|r| { |
| 53 | + r.with_limit_memory("4G") |
| 54 | + .with_limit_cpu("2") |
| 55 | + .with_request_memory("2G") |
| 56 | + .with_request_cpu("1") |
| 57 | + }); |
| 58 | + // Add malus validator |
| 59 | + let r = r.with_node(|node| { |
| 60 | + node.with_name("malus") |
| 61 | + .with_args(vec![ |
| 62 | + "-lparachain=debug,MALUS=trace".into(), |
| 63 | + "--dispute-offset=14".into(), |
| 64 | + "--alice".into(), |
| 65 | + "--insecure-validator-i-know-what-i-do".into(), |
| 66 | + ]) |
| 67 | + .with_image( |
| 68 | + std::env::var("MALUS_IMAGE") |
| 69 | + .unwrap_or("docker.io/paritypr/malus".to_string()) |
| 70 | + .as_str(), |
| 71 | + ) |
| 72 | + .with_command("malus") |
| 73 | + .with_subcommand("dispute-finalized-candidates") |
| 74 | + .invulnerable(false) |
| 75 | + }); |
| 76 | + // Add honest validators |
| 77 | + let r = (0..6).fold(r, |acc, i| { |
| 78 | + acc.with_node(|node| { |
| 79 | + node.with_name(&format!("honest-{i}")) |
| 80 | + .with_args(vec!["-lparachain=debug".into()]) |
| 81 | + }) |
| 82 | + }); |
| 83 | + r |
| 84 | + }) |
| 85 | + .with_parachain(|p| { |
| 86 | + p.with_id(2000) |
| 87 | + .cumulus_based(false) |
| 88 | + .with_default_image( |
| 89 | + std::env::var("COL_IMAGE") |
| 90 | + .unwrap_or("docker.io/paritypr/colander:latest".to_string()) |
| 91 | + .as_str(), |
| 92 | + ) |
| 93 | + .with_default_command("undying-collator") |
| 94 | + .with_default_args(vec!["-lparachain=debug".into()]) |
| 95 | + .with_collator(|n| n.with_name("collator")) |
| 96 | + }) |
| 97 | + .build() |
| 98 | + .map_err(|e| { |
| 99 | + let errors = e.into_iter().map(|e| e.to_string()).collect::<Vec<_>>().join(" "); |
| 100 | + anyhow!("config errors: {errors}") |
| 101 | + })?; |
| 102 | + |
| 103 | + let spawn_fn = zombienet_sdk::environment::get_spawn_fn(); |
| 104 | + let network = spawn_fn(config).await?; |
| 105 | + |
| 106 | + let honest = network.get_node("honest-0")?; |
| 107 | + let relay_client = honest.wait_client().await?; |
| 108 | + let malus = network.get_node("malus")?; |
| 109 | + |
| 110 | + log::info!("Waiting for parablocks to be produced"); |
| 111 | + assert_para_throughput( |
| 112 | + &relay_client, |
| 113 | + 20, |
| 114 | + [(polkadot_primitives::Id::from(2000), 10..30)].into_iter().collect(), |
| 115 | + ) |
| 116 | + .await?; |
| 117 | + |
| 118 | + let result = malus |
| 119 | + .wait_log_line_count_with_timeout( |
| 120 | + "*😈 Disputing candidate with hash:*", |
| 121 | + true, |
| 122 | + LogLineCountOptions::new(|n| n == 1, Duration::from_secs(180_u64), false), |
| 123 | + ) |
| 124 | + .await?; |
| 125 | + assert!(result.success()); |
| 126 | + let result = honest |
| 127 | + .wait_log_line_count_with_timeout( |
| 128 | + "*Dispute on candidate concluded*", |
| 129 | + true, |
| 130 | + LogLineCountOptions::new(|n| n == 0, Duration::from_secs(180_u64), false), |
| 131 | + ) |
| 132 | + .await?; |
| 133 | + assert!(result.success()); |
| 134 | + Ok(()) |
| 135 | +} |
0 commit comments