From e10e9a1a380fb021a8db951e899e84d97ae16168 Mon Sep 17 00:00:00 2001 From: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Date: Tue, 21 May 2024 10:26:10 +0200 Subject: [PATCH] add kusama people (#31) --- src/build_upgrade.rs | 34 +++++++++++++++++++++++++++++++--- src/tests.rs | 3 +++ src/types.rs | 29 +++++++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/build_upgrade.rs b/src/build_upgrade.rs index ce38734..90b0d4f 100644 --- a/src/build_upgrade.rs +++ b/src/build_upgrade.rs @@ -45,6 +45,11 @@ pub(crate) struct UpgradeArgs { #[clap(long = "encointer")] pub(crate) encointer: Option, + /// Optional. The runtime version of People to which to upgrade. If not provided, it will use + /// the Relay Chain's version. + #[clap(long = "people")] + pub(crate) people: Option, + /// Optional. The runtime version of Coretime to which to upgrade. If not provided, it will use /// the Relay Chain's version. #[clap(long = "coretime")] @@ -113,6 +118,7 @@ pub(crate) fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails { let relay_version = chain_version(prefs.relay_version, None, only); let asset_hub_version = chain_version(prefs.asset_hub, relay_version.clone(), only); let bridge_hub_version = chain_version(prefs.bridge_hub, relay_version.clone(), only); + let people_version = chain_version(prefs.people, relay_version.clone(), only); let coretime_version = chain_version(prefs.coretime, relay_version.clone(), only); let encointer_version = chain_version(prefs.encointer, relay_version.clone(), only); let collectives_version = chain_version(prefs.collectives, relay_version.clone(), only); @@ -147,6 +153,9 @@ pub(crate) fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails { if let Some(v) = bridge_hub_version.clone() { networks.push(VersionedNetwork { network: Network::KusamaBridgeHub, version: v }); } + if let Some(v) = people_version.clone() { + networks.push(VersionedNetwork { network: Network::KusamaPeople, version: v }); + } if let Some(v) = coretime_version.clone() { networks.push(VersionedNetwork { network: Network::KusamaCoretime, version: v }); } @@ -173,9 +182,9 @@ pub(crate) fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails { // Get a version from one of the args. (This still feels dirty.) let version = relay_version.clone().unwrap_or(asset_hub_version.unwrap_or( - bridge_hub_version.unwrap_or(encointer_version.unwrap_or( - collectives_version.unwrap_or(coretime_version.unwrap_or(String::from("no-version"))), - )), + bridge_hub_version.unwrap_or(encointer_version.unwrap_or(collectives_version.unwrap_or( + coretime_version.unwrap_or(people_version.unwrap_or(String::from("no-version"))), + ))), )); // Set up a directory to store information fetched/written during this program. @@ -236,6 +245,7 @@ async fn download_runtimes(upgrade_details: &UpgradeDetails) { Network::Polkadot => "polkadot", Network::KusamaAssetHub => "asset-hub-kusama", Network::KusamaBridgeHub => "bridge-hub-kusama", + Network::KusamaPeople => "people-kusama", Network::KusamaCoretime => "coretime-kusama", Network::KusamaEncointer => "encointer-kusama", Network::PolkadotAssetHub => "asset-hub-polkadot", @@ -306,6 +316,24 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec { + use kusama_people::runtime_types::cumulus_pallet_parachain_system::pallet::Call; + let path = format!( + "{}people-kusama_runtime-v{}.compact.compressed.wasm", + upgrade_details.directory, runtime_version + ); + let runtime = fs::read(path).expect("Should give a valid file path"); + let runtime_hash = blake2_256(&runtime); + println!("Kusama People Runtime Hash: 0x{}", hex::encode(runtime_hash)); + + let call = CallInfo::from_runtime_call(NetworkRuntimeCall::KusamaPeople( + KusamaPeopleRuntimeCall::ParachainSystem(Call::authorize_upgrade { + code_hash: H256(runtime_hash), + check_version: true, + }), + )); + authorization_calls.push(call); + }, Network::KusamaCoretime => { use kusama_coretime::runtime_types::cumulus_pallet_parachain_system::pallet::Call; let path = format!( diff --git a/src/tests.rs b/src/tests.rs index ddc173a..a52264a 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -128,6 +128,7 @@ fn upgrade_args_for_only_relay() -> UpgradeArgs { bridge_hub: None, collectives: None, encointer: None, + people: None, coretime: None, filename: None, additional: None, @@ -144,6 +145,7 @@ fn upgrade_args_for_only_asset_hub() -> UpgradeArgs { bridge_hub: None, collectives: None, encointer: None, + people: None, coretime: None, filename: None, additional: None, @@ -160,6 +162,7 @@ fn upgrade_args_for_all() -> UpgradeArgs { bridge_hub: None, collectives: None, encointer: None, + people: None, coretime: None, filename: None, additional: None, diff --git a/src/types.rs b/src/types.rs index 8bf8457..db574c0 100644 --- a/src/types.rs +++ b/src/types.rs @@ -25,6 +25,10 @@ pub(super) use kusama_bridge_hub::runtime_types::bridge_hub_kusama_runtime::Runt pub mod kusama_encointer {} pub(super) use kusama_encointer::runtime_types::encointer_kusama_runtime::RuntimeCall as KusamaEncointerRuntimeCall; +#[subxt::subxt(runtime_metadata_insecure_url = "wss://kusama-people-rpc.polkadot.io:443")] +pub mod kusama_people {} +pub(super) use kusama_people::runtime_types::people_kusama_runtime::RuntimeCall as KusamaPeopleRuntimeCall; + #[subxt::subxt(runtime_metadata_insecure_url = "wss://kusama-coretime-rpc.polkadot.io:443")] pub mod kusama_coretime {} pub(super) use kusama_coretime::runtime_types::coretime_kusama_runtime::RuntimeCall as KusamaCoretimeRuntimeCall; @@ -63,9 +67,10 @@ pub(super) use polkadot_bridge_hub::runtime_types::bridge_hub_polkadot_runtime:: pub(super) enum Network { Kusama, KusamaAssetHub, + KusamaEncointer, KusamaBridgeHub, + KusamaPeople, KusamaCoretime, - KusamaEncointer, Polkadot, PolkadotAssetHub, PolkadotCollectives, @@ -81,6 +86,7 @@ impl Network { Kusama => Err("relay chain"), KusamaAssetHub => Ok(1_000), KusamaBridgeHub => Ok(1_002), + KusamaPeople => Ok(1_004), KusamaCoretime => Ok(1_005), KusamaEncointer => Ok(1_001), // Polkadot @@ -94,7 +100,10 @@ impl Network { /// Returns `true` if the network is a Kusama _parachain_. pub(super) fn is_kusama_para(&self) -> bool { use Network::*; - matches!(self, KusamaAssetHub | KusamaBridgeHub | KusamaCoretime | KusamaEncointer) + matches!( + self, + KusamaAssetHub | KusamaBridgeHub | KusamaPeople | KusamaCoretime | KusamaEncointer + ) } /// Returns `true` if the network is a Polkadot _parachain_. @@ -166,6 +175,7 @@ pub(super) enum NetworkRuntimeCall { Kusama(KusamaRuntimeCall), KusamaAssetHub(KusamaAssetHubRuntimeCall), KusamaBridgeHub(KusamaBridgeHubRuntimeCall), + KusamaPeople(KusamaPeopleRuntimeCall), KusamaCoretime(KusamaCoretimeRuntimeCall), KusamaEncointer(KusamaEncointerRuntimeCall), Polkadot(PolkadotRuntimeCall), @@ -210,6 +220,7 @@ impl CallInfo { NetworkRuntimeCall::Kusama(cc) => (Network::Kusama, cc.encode()), NetworkRuntimeCall::KusamaAssetHub(cc) => (Network::KusamaAssetHub, cc.encode()), NetworkRuntimeCall::KusamaBridgeHub(cc) => (Network::KusamaBridgeHub, cc.encode()), + NetworkRuntimeCall::KusamaPeople(cc) => (Network::KusamaPeople, cc.encode()), NetworkRuntimeCall::KusamaCoretime(cc) => (Network::KusamaCoretime, cc.encode()), NetworkRuntimeCall::KusamaEncointer(cc) => (Network::KusamaEncointer, cc.encode()), NetworkRuntimeCall::Polkadot(cc) => (Network::Polkadot, cc.encode()), @@ -293,6 +304,19 @@ impl CallInfo { } } + // Strip the outer enum and return a Kusama People `RuntimeCall`. + #[allow(dead_code)] + pub(super) fn get_kusama_people_call(&self) -> Result { + match &self.network { + Network::KusamaPeople => { + let bytes = &self.encoded; + Ok(::decode(&mut &bytes[..]) + .unwrap()) + }, + _ => Err("not a kusama people call"), + } + } + // Strip the outer enum and return a Kusama Coretime `RuntimeCall`. #[allow(dead_code)] pub(super) fn get_kusama_coretime_call( @@ -383,6 +407,7 @@ impl CallInfo { Network::Kusama => "wss://kusama-rpc.dwellir.com:443", Network::KusamaAssetHub => "wss://kusama-asset-hub-rpc.polkadot.io:443", Network::KusamaBridgeHub => "wss://kusama-bridge-hub-rpc.polkadot.io:443", + Network::KusamaPeople => "wss://kusama-people-rpc.polkadot.io:443", Network::KusamaCoretime => "wss://kusama-coretime-rpc.polkadot.io:443", Network::KusamaEncointer => "wss://encointer-kusama-rpc.dwellir.com:443", Network::Polkadot => "wss://polkadot-rpc.dwellir.com:443",