|
| 1 | +// Copyright (C) Parity Technologies (UK) Ltd. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +// Test that checks approval voting coalescing does not lag finality. |
| 5 | + |
| 6 | +use anyhow::anyhow; |
| 7 | + |
| 8 | +use crate::helpers::{ |
| 9 | + assert_finality_lag_less_than, assert_finalized_block_height, assert_para_throughput, |
| 10 | +}; |
| 11 | +use polkadot_primitives::Id as ParaId; |
| 12 | +use serde_json::json; |
| 13 | +use subxt::{OnlineClient, PolkadotConfig}; |
| 14 | +use zombienet_sdk::NetworkConfigBuilder; |
| 15 | + |
| 16 | +#[tokio::test(flavor = "multi_thread")] |
| 17 | +async fn approval_voting_coalescing_test() -> Result<(), anyhow::Error> { |
| 18 | + let _ = env_logger::try_init_from_env( |
| 19 | + env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"), |
| 20 | + ); |
| 21 | + |
| 22 | + let images = zombienet_sdk::environment::get_images_from_env(); |
| 23 | + let no_show_slots = 4; |
| 24 | + let config = NetworkConfigBuilder::new() |
| 25 | + .with_relaychain(|r| { |
| 26 | + let r = r |
| 27 | + .with_chain("rococo-local") |
| 28 | + .with_default_command("polkadot") |
| 29 | + .with_default_image(images.polkadot.as_str()) |
| 30 | + .with_default_args(vec![("-lparachain=debug,runtime=debug").into()]) |
| 31 | + .with_genesis_overrides(json!({ |
| 32 | + "configuration": { |
| 33 | + "config": { |
| 34 | + "needed_approvals": 4, |
| 35 | + "relay_vrf_modulo_samples": 6, |
| 36 | + "no_show_slots": no_show_slots, |
| 37 | + "approval_voting_params": { |
| 38 | + "max_approval_coalesce_count": 5 |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + })) |
| 43 | + .with_node(|node| node.with_name("validator-0")); |
| 44 | + |
| 45 | + (1..12) |
| 46 | + .fold(r, |acc, i| acc.with_node(|node| node.with_name(&format!("validator-{i}")))) |
| 47 | + }) |
| 48 | + .with_parachain(|p| { |
| 49 | + p.with_id(2000) |
| 50 | + .with_default_command("undying-collator") |
| 51 | + .with_default_image( |
| 52 | + std::env::var("COL_IMAGE") |
| 53 | + .unwrap_or("docker.io/paritypr/colander:latest".to_string()) |
| 54 | + .as_str(), |
| 55 | + ) |
| 56 | + .cumulus_based(false) |
| 57 | + .with_default_args(vec![("-lparachain=debug").into()]) |
| 58 | + .with_collator(|n| n.with_name("collator-undying-2000")) |
| 59 | + }) |
| 60 | + .with_parachain(|p| { |
| 61 | + p.with_id(2001) |
| 62 | + .with_default_command("undying-collator") |
| 63 | + .with_default_image( |
| 64 | + std::env::var("COL_IMAGE") |
| 65 | + .unwrap_or("docker.io/paritypr/colander:latest".to_string()) |
| 66 | + .as_str(), |
| 67 | + ) |
| 68 | + .cumulus_based(false) |
| 69 | + .with_default_args(vec![("-lparachain=debug").into()]) |
| 70 | + .with_collator(|n| n.with_name("collator-undying-2001")) |
| 71 | + }) |
| 72 | + .with_parachain(|p| { |
| 73 | + p.with_id(2002) |
| 74 | + .with_default_command("undying-collator") |
| 75 | + .with_default_image( |
| 76 | + std::env::var("COL_IMAGE") |
| 77 | + .unwrap_or("docker.io/paritypr/colander:latest".to_string()) |
| 78 | + .as_str(), |
| 79 | + ) |
| 80 | + .cumulus_based(false) |
| 81 | + .with_default_args(vec![("-lparachain=debug").into()]) |
| 82 | + .with_collator(|n| n.with_name("collator-undying-2002")) |
| 83 | + }) |
| 84 | + .with_parachain(|p| { |
| 85 | + p.with_id(2003) |
| 86 | + .with_default_command("undying-collator") |
| 87 | + .with_default_image( |
| 88 | + std::env::var("COL_IMAGE") |
| 89 | + .unwrap_or("docker.io/paritypr/colander:latest".to_string()) |
| 90 | + .as_str(), |
| 91 | + ) |
| 92 | + .cumulus_based(false) |
| 93 | + .with_default_args(vec![("-lparachain=debug").into()]) |
| 94 | + .with_collator(|n| n.with_name("collator-undying-2003")) |
| 95 | + }) |
| 96 | + .with_parachain(|p| { |
| 97 | + p.with_id(2004) |
| 98 | + .with_default_command("undying-collator") |
| 99 | + .with_default_image( |
| 100 | + std::env::var("COL_IMAGE") |
| 101 | + .unwrap_or("docker.io/paritypr/colander:latest".to_string()) |
| 102 | + .as_str(), |
| 103 | + ) |
| 104 | + .cumulus_based(false) |
| 105 | + .with_default_args(vec![("-lparachain=debug").into()]) |
| 106 | + .with_collator(|n| n.with_name("collator-undying-2004")) |
| 107 | + }) |
| 108 | + .with_parachain(|p| { |
| 109 | + p.with_id(2005) |
| 110 | + .with_default_command("undying-collator") |
| 111 | + .with_default_image( |
| 112 | + std::env::var("COL_IMAGE") |
| 113 | + .unwrap_or("docker.io/paritypr/colander:latest".to_string()) |
| 114 | + .as_str(), |
| 115 | + ) |
| 116 | + .cumulus_based(false) |
| 117 | + .with_default_args(vec![("-lparachain=debug").into()]) |
| 118 | + .with_collator(|n| n.with_name("collator-undying-2005")) |
| 119 | + }) |
| 120 | + .with_parachain(|p| { |
| 121 | + p.with_id(2006) |
| 122 | + .with_default_command("undying-collator") |
| 123 | + .with_default_image( |
| 124 | + std::env::var("COL_IMAGE") |
| 125 | + .unwrap_or("docker.io/paritypr/colander:latest".to_string()) |
| 126 | + .as_str(), |
| 127 | + ) |
| 128 | + .cumulus_based(false) |
| 129 | + .with_default_args(vec![("-lparachain=debug").into()]) |
| 130 | + .with_collator(|n| n.with_name("collator-undying-2006")) |
| 131 | + }) |
| 132 | + .with_parachain(|p| { |
| 133 | + p.with_id(2007) |
| 134 | + .with_default_command("undying-collator") |
| 135 | + .with_default_image( |
| 136 | + std::env::var("COL_IMAGE") |
| 137 | + .unwrap_or("docker.io/paritypr/colander:latest".to_string()) |
| 138 | + .as_str(), |
| 139 | + ) |
| 140 | + .cumulus_based(false) |
| 141 | + .with_default_args(vec![("-lparachain=debug").into()]) |
| 142 | + .with_collator(|n| n.with_name("collator-undying-2007")) |
| 143 | + }) |
| 144 | + .build() |
| 145 | + .map_err(|e| { |
| 146 | + let errs = e.into_iter().map(|e| e.to_string()).collect::<Vec<_>>().join(" "); |
| 147 | + anyhow!("config errs: {errs}") |
| 148 | + })?; |
| 149 | + |
| 150 | + let spawn_fn = zombienet_sdk::environment::get_spawn_fn(); |
| 151 | + |
| 152 | + log::info!("Spawning network"); |
| 153 | + let network = spawn_fn(config).await?; |
| 154 | + |
| 155 | + log::info!("Waiting for network to initialize"); |
| 156 | + let relay_node = network.get_node("validator-0")?; |
| 157 | + let para_node_2001 = network.get_node("collator-undying-2000")?; |
| 158 | + |
| 159 | + let relay_client: OnlineClient<PolkadotConfig> = relay_node.wait_client().await?; |
| 160 | + |
| 161 | + log::info!("Waiting for parachains to advance to block 15"); |
| 162 | + assert_para_throughput( |
| 163 | + &relay_client, |
| 164 | + 15, |
| 165 | + [ |
| 166 | + (ParaId::from(2000), 11..16), |
| 167 | + (ParaId::from(2001), 11..16), |
| 168 | + (ParaId::from(2002), 11..16), |
| 169 | + (ParaId::from(2003), 11..16), |
| 170 | + (ParaId::from(2004), 11..16), |
| 171 | + (ParaId::from(2005), 11..16), |
| 172 | + (ParaId::from(2006), 11..16), |
| 173 | + (ParaId::from(2007), 11..16), |
| 174 | + ] |
| 175 | + .into_iter() |
| 176 | + .collect(), |
| 177 | + ) |
| 178 | + .await?; |
| 179 | + |
| 180 | + log::info!("Checking finality does not log and no-shows are within range"); |
| 181 | + for node in network.nodes() { |
| 182 | + assert_finality_lag_less_than(&node.wait_client().await?, no_show_slots).await?; |
| 183 | + assert!( |
| 184 | + node.reports("polkadot_parachain_approvals_no_shows_total").await.unwrap() < 3.1, |
| 185 | + "No-shows should be less than 3" |
| 186 | + ); |
| 187 | + } |
| 188 | + |
| 189 | + log::info!("Test finished successfully"); |
| 190 | + |
| 191 | + Ok(()) |
| 192 | +} |
0 commit comments