Skip to content

Commit

Permalink
coretime
Browse files Browse the repository at this point in the history
  • Loading branch information
joepetrowski committed Apr 15, 2024
1 parent 4b86dad commit 74ce462
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ kusama_types.rs
kusama_ah_types.rs
polkadot_types.rs
.DS_Store
self-notes.md
47 changes: 41 additions & 6 deletions src/build_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ pub(crate) struct UpgradeArgs {
#[clap(long = "encointer")]
pub(crate) encointer: Option<String>,

/// 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<String>,

/// Name of the file to which to write the output. If not provided, a default will be
/// constructed.
#[clap(long = "filename")]
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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`"),
Expand All @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -276,6 +287,24 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec<Cal
));
authorization_calls.push(call);
},
Network::KusamaCoretime => {
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!(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ fn upgrade_args_for_only_relay() -> UpgradeArgs {
bridge_hub: None,
collectives: None,
encointer: None,
coretime: None,
filename: None,
additional: None,
}
Expand All @@ -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,
}
Expand All @@ -155,6 +157,7 @@ fn upgrade_args_for_all() -> UpgradeArgs {
bridge_hub: None,
collectives: None,
encointer: None,
coretime: None,
filename: None,
additional: None,
}
Expand Down
33 changes: 32 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -55,6 +64,7 @@ pub(super) enum Network {
Kusama,
KusamaAssetHub,
KusamaBridgeHub,
KusamaCoretime,
KusamaEncointer,
Polkadot,
PolkadotAssetHub,
Expand All @@ -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),
Expand Down Expand Up @@ -138,6 +149,7 @@ pub(super) enum NetworkRuntimeCall {
Kusama(KusamaRuntimeCall),
KusamaAssetHub(KusamaAssetHubRuntimeCall),
KusamaBridgeHub(KusamaBridgeHubRuntimeCall),
KusamaCoretime(KusamaCoretimeRuntimeCall),
KusamaEncointer(KusamaEncointerRuntimeCall),
Polkadot(PolkadotRuntimeCall),
PolkadotAssetHub(PolkadotAssetHubRuntimeCall),
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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<KusamaCoretimeRuntimeCall, &'static str> {
match &self.network {
Network::KusamaCoretime => {
let bytes = &self.encoded;
Ok(<KusamaCoretimeRuntimeCall as parity_scale_codec::Decode>::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<PolkadotRuntimeCall, &'static str> {
match &self.network {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 74ce462

Please sign in to comment.