From 497ce04ea4eb1f41f2e5cc11144e04f83497e7a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Thu, 19 Sep 2024 09:56:42 +0100 Subject: [PATCH 1/3] Add Polkadot Coretime --- src/build_upgrade.rs | 21 +++++++++++++++++++++ src/types.rs | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/build_upgrade.rs b/src/build_upgrade.rs index 792cec6..ae6a5c5 100644 --- a/src/build_upgrade.rs +++ b/src/build_upgrade.rs @@ -141,6 +141,9 @@ pub(crate) fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails { if let Some(v) = people_version.clone() { networks.push(VersionedNetwork { network: Network::PolkadotPeople, version: v }); } + if let Some(v) = coretime_version.clone() { + networks.push(VersionedNetwork { network: Network::PolkadotCoretime, version: v }); + } Network::Polkadot }, "kusama" => { @@ -255,6 +258,7 @@ async fn download_runtimes(upgrade_details: &UpgradeDetails) { Network::PolkadotCollectives => "collectives-polkadot", Network::PolkadotBridgeHub => "bridge-hub-polkadot", Network::PolkadotPeople => "people-polkadot", + Network::PolkadotCoretime => "coretime-polkadot", }; let runtime_version = semver_to_intver(&chain.version); let fname = format!("{}_runtime-v{}.compact.compressed.wasm", chain_name, runtime_version); @@ -437,6 +441,23 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec { + use polkadot_coretime::runtime_types::frame_system::pallet::Call; + let path = format!( + "{}coretime-polkadot_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!("Polkadot Coretime Runtime Hash: 0x{}", hex::encode(runtime_hash)); + + let call = CallInfo::from_runtime_call(NetworkRuntimeCall::PolkadotCoretime( + PolkadotCoretimeRuntimeCall::System(Call::authorize_upgrade { + code_hash: H256(runtime_hash), + }), + )); + authorization_calls.push(call); + }, }; } authorization_calls diff --git a/src/types.rs b/src/types.rs index 4124cfa..a12881b 100644 --- a/src/types.rs +++ b/src/types.rs @@ -67,6 +67,10 @@ pub(super) use polkadot_bridge_hub::runtime_types::bridge_hub_polkadot_runtime:: pub mod polkadot_people {} pub(super) use polkadot_people::runtime_types::people_polkadot_runtime::RuntimeCall as PolkadotPeopleRuntimeCall; +#[subxt::subxt(runtime_metadata_insecure_url = "wss://polkadot-coretime-rpc.polkadot.io:443")] +pub mod polkadot_coretime {} +pub(super) use polkadot_coretime::runtime_types::coretime_polkadot_runtime::RuntimeCall as PolkadotCoretimeRuntimeCall; + #[derive(Clone, Debug, PartialEq)] pub(super) enum Network { Kusama, @@ -80,6 +84,7 @@ pub(super) enum Network { PolkadotCollectives, PolkadotBridgeHub, PolkadotPeople, + PolkadotCoretime, } impl Network { @@ -100,6 +105,7 @@ impl Network { PolkadotBridgeHub => Ok(1_002), PolkadotCollectives => Ok(1_001), PolkadotPeople => Ok(1_004), + PolkadotCoretime => Ok(1_005), } } @@ -115,7 +121,13 @@ impl Network { /// Returns `true` if the network is a Polkadot _parachain_. pub(super) fn is_polkadot_para(&self) -> bool { use Network::*; - matches!(self, PolkadotAssetHub | PolkadotCollectives | PolkadotBridgeHub | PolkadotPeople) + matches!( + self, + PolkadotAssetHub + | PolkadotCollectives + | PolkadotBridgeHub + | PolkadotPeople | PolkadotCoretime + ) } } @@ -189,6 +201,7 @@ pub(super) enum NetworkRuntimeCall { PolkadotCollectives(CollectivesRuntimeCall), PolkadotBridgeHub(PolkadotBridgeHubRuntimeCall), PolkadotPeople(PolkadotPeopleRuntimeCall), + PolkadotCoretime(PolkadotCoretimeRuntimeCall), } // How the user would like to see the output of the program. @@ -236,6 +249,7 @@ impl CallInfo { (Network::PolkadotCollectives, cc.encode()), NetworkRuntimeCall::PolkadotBridgeHub(cc) => (Network::PolkadotBridgeHub, cc.encode()), NetworkRuntimeCall::PolkadotPeople(cc) => (Network::PolkadotPeople, cc.encode()), + NetworkRuntimeCall::PolkadotCoretime(cc) => (Network::PolkadotCoretime, cc.encode()), }; let hash = blake2_256(&encoded); let length: u32 = (encoded.len()).try_into().unwrap(); @@ -419,6 +433,23 @@ impl CallInfo { } } + // Strip the outer enum and return a Polkadot Coretime `RuntimeCall`. + #[allow(dead_code)] + pub(super) fn get_polkadot_coretime_call( + &self, + ) -> Result { + match &self.network { + Network::PolkadotCoretime => { + let bytes = &self.encoded; + Ok(::decode( + &mut &bytes[..], + ) + .unwrap()) + }, + _ => Err("not a polkadot coretime call"), + } + } + pub(super) async fn get_transact_weight_needed( &self, network: &Network, @@ -440,6 +471,7 @@ impl CallInfo { Network::PolkadotCollectives => "wss://polkadot-collectives-rpc.polkadot.io:443", Network::PolkadotBridgeHub => "wss://polkadot-bridge-hub-rpc.polkadot.io:443", Network::PolkadotPeople => "wss://polkadot-people-rpc.polkadot.io:443", + Network::PolkadotCoretime => "wss://polkadot-coretime-rpc.polkadot.io:443", }; let mut args = self.encoded.clone(); From a8f793da5db54e552da6bfb31973c99a88215341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Thu, 19 Sep 2024 10:16:35 +0100 Subject: [PATCH 2/3] Update OriginKind to v3 --- src/build_upgrade.rs | 2 +- src/submit_referendum.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build_upgrade.rs b/src/build_upgrade.rs index ae6a5c5..9ab4736 100644 --- a/src/build_upgrade.rs +++ b/src/build_upgrade.rs @@ -653,7 +653,7 @@ async fn send_as_superuser_from_polkadot(auth: &CallInfo) -> PolkadotRuntimeCall Instruction, Xcm, }, xcm::{ - double_encoded::DoubleEncoded, v2::OriginKind, v3::WeightLimit, VersionedLocation, + double_encoded::DoubleEncoded, v3::OriginKind, v3::WeightLimit, VersionedLocation, VersionedXcm::V4, }, }; diff --git a/src/submit_referendum.rs b/src/submit_referendum.rs index 239cc26..511d130 100644 --- a/src/submit_referendum.rs +++ b/src/submit_referendum.rs @@ -340,7 +340,7 @@ async fn polkadot_fellowship_referenda( pallet_xcm::pallet::Call as CollectivesXcmCall, staging_xcm::v4::{junctions::Junctions::Here, location::Location, Instruction, Xcm}, xcm::{ - double_encoded::DoubleEncoded, v2::OriginKind, v3::WeightLimit, VersionedLocation, + double_encoded::DoubleEncoded, v3::OriginKind, v3::WeightLimit, VersionedLocation, VersionedXcm::V4, }, }; From a580aa72b82b5bb1eed2d6cf0cb31e003d152522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= Date: Thu, 19 Sep 2024 15:40:13 +0100 Subject: [PATCH 3/3] Fix tests --- src/tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests.rs b/src/tests.rs index ee06015..27d387d 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -491,6 +491,7 @@ fn upgrade_everything_works_with_just_relay_version() { VersionedNetwork { network: Network::PolkadotCollectives, version: String::from("1.2.0") }, VersionedNetwork { network: Network::PolkadotBridgeHub, version: String::from("1.2.0") }, VersionedNetwork { network: Network::PolkadotPeople, version: String::from("1.2.0") }, + VersionedNetwork { network: Network::PolkadotCoretime, version: String::from("1.2.0") }, ]; assert_eq!(details.networks, expected_networks); assert!(details.additional.is_none());