diff --git a/.gitignore b/.gitignore index a8d6ec5..c9481a0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ kusama_types.rs kusama_ah_types.rs polkadot_types.rs .DS_Store +self-notes.md diff --git a/src/build_upgrade.rs b/src/build_upgrade.rs index efe1609..9867b1f 100644 --- a/src/build_upgrade.rs +++ b/src/build_upgrade.rs @@ -38,6 +38,11 @@ pub(crate) struct UpgradeArgs { #[clap(long = "encointer")] pub(crate) encointer: 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")] + pub(crate) coretime: Option, + /// Name of the file to which to write the output. If not provided, a default will be /// constructed. #[clap(long = "filename")] @@ -101,6 +106,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 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); @@ -134,6 +140,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) = coretime_version.clone() { + networks.push(VersionedNetwork { network: Network::KusamaCoretime, version: v }); + } Network::Kusama }, _ => panic!("`network` must be `polkadot` or `kusama`"), @@ -153,10 +162,11 @@ pub(crate) fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails { None => None, }; - 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(String::from("no-version"))), - ))); + 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"))), + )), + )); let directory = format!("./upgrade-{}-{}/", &prefs.network, &version); let output_file = if let Some(user_filename) = prefs.filename { @@ -207,6 +217,7 @@ async fn download_runtimes(upgrade_details: &UpgradeDetails) { Network::Polkadot => "polkadot", Network::KusamaAssetHub => "asset-hub-kusama", Network::KusamaBridgeHub => "bridge-hub-kusama", + Network::KusamaCoretime => "coretime-kusama", Network::KusamaEncointer => "encointer-kusama", Network::PolkadotAssetHub => "asset-hub-polkadot", Network::PolkadotCollectives => "collectives-polkadot", @@ -276,6 +287,24 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec { + use kusama_coretime::runtime_types::cumulus_pallet_parachain_system::pallet::Call; + let path = format!( + "{}coretime-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 Coretime Runtime Hash: 0x{}", hex::encode(runtime_hash)); + + let call = CallInfo::from_runtime_call(NetworkRuntimeCall::KusamaCoretime( + KusamaCoretimeRuntimeCall::ParachainSystem(Call::authorize_upgrade { + code_hash: H256(runtime_hash), + check_version: true, + }), + )); + authorization_calls.push(call); + }, Network::KusamaEncointer => { use kusama_encointer::runtime_types::cumulus_pallet_parachain_system::pallet::Call; let path = format!( @@ -437,6 +466,10 @@ async fn construct_kusama_batch( let send_auth = send_as_superuser_from_kusama(&auth).await; batch_calls.push(send_auth); }, + Network::KusamaCoretime => { + let send_auth = send_as_superuser_from_kusama(&auth).await; + batch_calls.push(send_auth); + }, Network::KusamaEncointer => { let send_auth = send_as_superuser_from_kusama(&auth).await; batch_calls.push(send_auth); @@ -468,8 +501,10 @@ async fn construct_polkadot_batch( match auth.network { Network::Kusama | Network::Polkadot => panic!("para calls should not contain relay calls"), - Network::KusamaAssetHub | Network::KusamaBridgeHub | Network::KusamaEncointer => - panic!("not polkadot parachains"), + Network::KusamaAssetHub + | Network::KusamaBridgeHub + | Network::KusamaCoretime + | Network::KusamaEncointer => panic!("not polkadot parachains"), Network::PolkadotAssetHub => { let send_auth = send_as_superuser_from_polkadot(&auth).await; batch_calls.push(send_auth); diff --git a/src/tests.rs b/src/tests.rs index 9f1f4cf..cdfdf0a 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -127,6 +127,7 @@ fn upgrade_args_for_only_relay() -> UpgradeArgs { bridge_hub: None, collectives: None, encointer: None, + coretime: None, filename: None, additional: None, } @@ -141,6 +142,7 @@ fn upgrade_args_for_only_asset_hub() -> UpgradeArgs { bridge_hub: None, collectives: None, encointer: None, + coretime: None, filename: None, additional: None, } @@ -155,6 +157,7 @@ fn upgrade_args_for_all() -> UpgradeArgs { bridge_hub: None, collectives: None, encointer: None, + coretime: None, filename: None, additional: None, } diff --git a/src/types.rs b/src/types.rs index fe8bda6..a5f7d29 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,5 +1,8 @@ pub(super) use parity_scale_codec::Encode as _; pub(super) use sp_core::{blake2_256, H256}; + +// Kusama Chains ----------------------------------------------------------------------------------- + #[subxt::subxt( runtime_metadata_insecure_url = "wss://kusama-rpc.dwellir.com:443", derive_for_all_types = "PartialEq, Clone" @@ -22,6 +25,12 @@ 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_runtime::RuntimeCall as KusamaEncointerRuntimeCall; +#[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; + +// Polkadot Chains --------------------------------------------------------------------------------- + #[subxt::subxt( runtime_metadata_insecure_url = "wss://polkadot-rpc.dwellir.com:443", derive_for_all_types = "PartialEq, Clone" @@ -55,6 +64,7 @@ pub(super) enum Network { Kusama, KusamaAssetHub, KusamaBridgeHub, + KusamaCoretime, KusamaEncointer, Polkadot, PolkadotAssetHub, @@ -69,6 +79,7 @@ impl Network { Kusama => Err("relay chain"), KusamaAssetHub => Ok(1_000), KusamaBridgeHub => Ok(1_002), + KusamaCoretime => Ok(1_005), KusamaEncointer => Ok(1_001), Polkadot => Err("relay chain"), PolkadotAssetHub => Ok(1_000), @@ -138,6 +149,7 @@ pub(super) enum NetworkRuntimeCall { Kusama(KusamaRuntimeCall), KusamaAssetHub(KusamaAssetHubRuntimeCall), KusamaBridgeHub(KusamaBridgeHubRuntimeCall), + KusamaCoretime(KusamaCoretimeRuntimeCall), KusamaEncointer(KusamaEncointerRuntimeCall), Polkadot(PolkadotRuntimeCall), PolkadotAssetHub(PolkadotAssetHubRuntimeCall), @@ -181,6 +193,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::KusamaCoretime(cc) => (Network::KusamaCoretime, cc.encode()), NetworkRuntimeCall::KusamaEncointer(cc) => (Network::KusamaEncointer, cc.encode()), NetworkRuntimeCall::Polkadot(cc) => (Network::Polkadot, cc.encode()), NetworkRuntimeCall::PolkadotAssetHub(cc) => (Network::PolkadotAssetHub, cc.encode()), @@ -263,6 +276,23 @@ impl CallInfo { } } + // Strip the outer enum and return a Kusama Coretime `RuntimeCall`. + #[allow(dead_code)] + pub(super) fn get_kusama_coretime_call( + &self, + ) -> Result { + match &self.network { + Network::KusamaCoretime => { + let bytes = &self.encoded; + Ok(::decode( + &mut &bytes[..], + ) + .unwrap()) + }, + _ => Err("not a kusama coretime call"), + } + } + // Strip the outer enum and return a Polkadot Relay `RuntimeCall`. pub(super) fn get_polkadot_call(&self) -> Result { match &self.network { @@ -336,7 +366,8 @@ 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::KusamaEncointer => "wss://kusama.api.encointer.org:443", + Network::KusamaCoretime => "wss://kusama-bridge-hub-rpc.polkadot.io:443", + Network::KusamaEncointer => "wss://kusama-coretime-rpc.polkadot.io:443", Network::Polkadot => "wss://polkadot-rpc.dwellir.com:443", Network::PolkadotAssetHub => "wss://polkadot-asset-hub-rpc.polkadot.io:443", Network::PolkadotCollectives => "wss://polkadot-collectives-rpc.polkadot.io:443",