-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: switch pop network configuration to paseo with hrmp channels * test: add relay+asset hub network config files * feat: clean dmpq state at genesis (#279) * dispatch kill tx * paseo-local metadata * chore: address hrmp channels at creation * clean unnecessary deps * fix: don't wait for finalisation * Provide documentation * refactor: improve ux * feat: add rococo-local metadata * fix: resolve merge conflict * chore: update zombienet-sdk * chore: update cargo.lock * refactor: use dynamic tx * docs: add variant doc comment * refactor: address clippy warning * chore: remove duplicate dependency after rebase * refactor: identify hrmp_channels earlier * test: add supported relay chains test * refactor: use construct_sudo_extrinsic * refactor: split into smaller functions for better testing * chore: add westend network configs * refactor: replace rococo with westend * refactor: remove duplicate import Co-authored-by: Peter White <[email protected]> * refactor: remove unusued parameter Co-authored-by: Peter White <[email protected]> * refactor: use global import Co-authored-by: Peter White <[email protected]> * fix: update error message * refactor: improve function name * refactor: use non-clashing variable name to support global import * refactor: reuse spinner --------- Co-authored-by: Alejandro Martinez Andres <[email protected]> Co-authored-by: Peter White <[email protected]>
- Loading branch information
1 parent
22a74b3
commit c1ed1ce
Showing
16 changed files
with
364 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
use crate::{call, DynamicPayload, Error}; | ||
use sp_core::twox_128; | ||
use subxt::{ | ||
config::BlockHash, | ||
dynamic::{self, Value}, | ||
ext::sp_core, | ||
OnlineClient, PolkadotConfig, | ||
}; | ||
|
||
/// Clears the DMPQ state for the given parachain IDs. | ||
/// | ||
/// # Arguments | ||
/// * `client` - Client for the network which state is to be modified. | ||
/// * `para_ids` - List of ids to build the keys that will be mutated. | ||
pub async fn clear_dmpq( | ||
client: OnlineClient<PolkadotConfig>, | ||
para_ids: &[u32], | ||
) -> Result<impl BlockHash, Error> { | ||
// Wait for blocks to be produced. | ||
let mut sub = client.blocks().subscribe_finalized().await?; | ||
for _ in 0..2 { | ||
sub.next().await; | ||
} | ||
|
||
// Generate storage keys to be removed | ||
let clear_dmq_keys = generate_storage_keys(para_ids); | ||
|
||
// Submit calls to remove specified keys | ||
let kill_storage = construct_kill_storage_call(clear_dmq_keys); | ||
let sudo = subxt_signer::sr25519::dev::alice(); | ||
let sudo_call = call::construct_sudo_extrinsic(kill_storage); | ||
Ok(client.tx().sign_and_submit_default(&sudo_call, &sudo).await?) | ||
} | ||
|
||
fn construct_kill_storage_call(keys: Vec<Vec<u8>>) -> DynamicPayload { | ||
dynamic::tx( | ||
"System", | ||
"kill_storage", | ||
vec![Value::unnamed_composite(keys.into_iter().map(Value::from_bytes))], | ||
) | ||
} | ||
|
||
fn generate_storage_keys(para_ids: &[u32]) -> Vec<Vec<u8>> { | ||
let dmp = twox_128("Dmp".as_bytes()); | ||
let dmp_queue_heads = twox_128("DownwardMessageQueueHeads".as_bytes()); | ||
let dmp_queues = twox_128("DownwardMessageQueues".as_bytes()); | ||
let mut clear_dmq_keys = Vec::<Vec<u8>>::new(); | ||
for id in para_ids { | ||
let id = id.to_le_bytes(); | ||
// DMP Queue Head | ||
let mut key = dmp.to_vec(); | ||
key.extend(&dmp_queue_heads); | ||
key.extend(sp_core::twox_64(&id)); | ||
key.extend(id); | ||
clear_dmq_keys.push(key); | ||
// DMP Queue | ||
let mut key = dmp.to_vec(); | ||
key.extend(&dmp_queues); | ||
key.extend(sp_core::twox_64(&id)); | ||
key.extend(id); | ||
clear_dmq_keys.push(key); | ||
} | ||
clear_dmq_keys | ||
} | ||
|
||
/// A supported relay chain. | ||
#[derive(Debug, PartialEq)] | ||
pub enum RelayChain { | ||
/// Paseo. | ||
PaseoLocal, | ||
/// Westend. | ||
WestendLocal, | ||
} | ||
|
||
impl RelayChain { | ||
/// Attempts to convert a chain identifier into a supported `RelayChain` variant. | ||
/// | ||
/// # Arguments | ||
/// * `id` - The relay chain identifier. | ||
pub fn from(id: &str) -> Option<RelayChain> { | ||
match id { | ||
"paseo-local" => Some(RelayChain::PaseoLocal), | ||
"westend-local" => Some(RelayChain::WestendLocal), | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use subxt::ext::sp_core::twox_64; | ||
use RelayChain::*; | ||
|
||
#[test] | ||
fn construct_kill_storage_call_works() { | ||
let keys = vec!["key".as_bytes().to_vec()]; | ||
assert_eq!( | ||
construct_kill_storage_call(keys.clone()), | ||
dynamic::tx( | ||
"System", | ||
"kill_storage", | ||
vec![Value::unnamed_composite(keys.into_iter().map(Value::from_bytes))], | ||
) | ||
) | ||
} | ||
|
||
#[test] | ||
fn generate_storage_keys_works() { | ||
let para_ids = vec![1_000, 4_385]; | ||
let dmp = twox_128("Dmp".as_bytes()); | ||
let dmp_queue_heads = [dmp, twox_128("DownwardMessageQueueHeads".as_bytes())].concat(); | ||
let dmp_queues = [dmp, twox_128("DownwardMessageQueues".as_bytes())].concat(); | ||
|
||
assert_eq!( | ||
generate_storage_keys(¶_ids), | ||
para_ids | ||
.iter() | ||
.flat_map(|id| { | ||
let id = id.to_le_bytes().to_vec(); | ||
[ | ||
// DMP Queue Head | ||
[dmp_queue_heads.clone(), twox_64(&id).to_vec(), id.clone()].concat(), | ||
// DMP Queue | ||
[dmp_queues.clone(), twox_64(&id).to_vec(), id].concat(), | ||
] | ||
}) | ||
.collect::<Vec<_>>() | ||
) | ||
} | ||
|
||
#[test] | ||
fn supported_relay_chains() { | ||
for (s, e) in [ | ||
// Only chains with sudo supported | ||
("paseo-local", Some(PaseoLocal)), | ||
("westend-local", Some(WestendLocal)), | ||
("kusama-local", None), | ||
("polkadot-local", None), | ||
] { | ||
assert_eq!(RelayChain::from(s), e) | ||
} | ||
} | ||
} |
Oops, something went wrong.