Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Polkadot Coretime chain #34

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/build_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -437,6 +441,23 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec<Cal
));
authorization_calls.push(call);
},
Network::PolkadotCoretime => {
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
Expand Down Expand Up @@ -632,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,
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/submit_referendum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
Expand Down
1 change: 1 addition & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
34 changes: 33 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -80,6 +84,7 @@ pub(super) enum Network {
PolkadotCollectives,
PolkadotBridgeHub,
PolkadotPeople,
PolkadotCoretime,
}

impl Network {
Expand All @@ -100,6 +105,7 @@ impl Network {
PolkadotBridgeHub => Ok(1_002),
PolkadotCollectives => Ok(1_001),
PolkadotPeople => Ok(1_004),
PolkadotCoretime => Ok(1_005),
}
}

Expand All @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny formatting but lint allows it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea the lint actually enforced it, I originally wrote them on multiple lines and the linter combined these on the same line 🧐

)
}
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<PolkadotCoretimeRuntimeCall, &'static str> {
match &self.network {
Network::PolkadotCoretime => {
let bytes = &self.encoded;
Ok(<PolkadotCoretimeRuntimeCall as parity_scale_codec::Decode>::decode(
&mut &bytes[..],
)
.unwrap())
},
_ => Err("not a polkadot coretime call"),
}
}

pub(super) async fn get_transact_weight_needed(
&self,
network: &Network,
Expand All @@ -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();
Expand Down
Loading