Skip to content
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
33 changes: 32 additions & 1 deletion src/build_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ pub(crate) struct UpgradeArgs {
#[clap(long = "local")]
pub(crate) local: bool,

/// Skip sanity checks on the downloaded runtime blobs (e.g. their file size).
#[clap(long = "no-runtime-checks")]
pub(crate) no_runtime_checks: bool,

/// The Fellowship release version. Should be semver and correspond to the release published.
#[clap(long = "relay-version")]
pub(crate) relay_version: Option<String>,
Expand Down Expand Up @@ -184,6 +188,8 @@ pub(crate) fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails {
None => None,
};

let no_runtime_checks = prefs.no_runtime_checks;

// 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(
Expand All @@ -202,7 +208,7 @@ pub(crate) fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails {

make_version_directory(directory.as_str());

UpgradeDetails { relay, networks, directory, output_file, additional }
UpgradeDetails { relay, networks, directory, output_file, additional, no_runtime_checks }
}

// Create a directory into which to place runtime blobs and the final call data.
Expand Down Expand Up @@ -264,7 +270,32 @@ async fn download_runtimes(upgrade_details: &UpgradeDetails) {
let path_name = format!("{directory}{fname}");
println!("Downloading... {fname}");
let response = reqwest::get(download_url).await.expect("we need files to work");

let status = response.status();
assert!(status.is_success(), "Failed to download {}: HTTP {}", fname, status);

let runtime = response.bytes().await.expect("need bytes");

if !upgrade_details.no_runtime_checks {
// Substrate zstd-compressed blob magic (`sp_maybe_compressed_blob::ZSTD_PREFIX`).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not import?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is private, but I guess you could call decompress.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ah fair enough, magic string is fine for something so unlikely to ever change

const ZSTD_PREFIX: [u8; 8] = [82, 188, 83, 118, 70, 219, 142, 5];
assert!(
runtime.starts_with(&ZSTD_PREFIX),
"Downloaded {} is not a zstd-compressed Substrate runtime blob. \
Pass --no-runtime-checks to skip.",
fname,
);

let size = runtime.len();
assert!(
(100 * 1024..=10 * 1024 * 1024).contains(&size),
"Downloaded {} is {} bytes; expected between 100 KiB and 10 MiB. \
Pass --no-runtime-checks to skip.",
fname,
size,
);
}

// todo: we could actually just hash the file, mutate UpgradeDetails, and not write it.
// saving it may be more convenient anyway though, since someone needs to upload it after
// the referendum enacts.
Expand Down
2 changes: 1 addition & 1 deletion src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pub(crate) fn get_proposal_bytes(proposal: String) -> Vec<u8> {
} else {
// This is a file path
let contents = fs::read_to_string(proposal).expect("Should give a valid file path");
hex::decode(contents.as_str().trim_start_matches("0x")).expect("Valid proposal")
hex::decode(contents.as_str().trim_start_matches("0x").trim()).expect("Valid proposal")
}
}
10 changes: 3 additions & 7 deletions src/submit_referendum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ async fn polkadot_fellowship_for_kusama_referenda(
pallet_referenda::pallet::Call as ReferendaCall,
pallet_whitelist::pallet::Call as WhitelistCall,
};
use polkadot_collectives::runtime_types::staging_xcm::v5::junction::NetworkId;
use polkadot_collectives::runtime_types::{
bounded_collections::bounded_vec::BoundedVec as CollectivesBoundedVec,
collectives_polkadot_runtime::OriginCaller as CollectivesOriginCaller,
Expand All @@ -408,15 +409,10 @@ async fn polkadot_fellowship_for_kusama_referenda(
Instruction, Xcm,
},
xcm::{
double_encoded::DoubleEncoded,
v3::MaybeErrorCode,
v3::OriginKind,
v3::WeightLimit,
VersionedLocation,
VersionedXcm::V5,
double_encoded::DoubleEncoded, v3::MaybeErrorCode, v3::OriginKind, v3::WeightLimit,
VersionedLocation, VersionedXcm::V5,
},
};
use polkadot_collectives::runtime_types::staging_xcm::v5::junction::NetworkId;
// Fellowship is on the Polkadot Collectives chain.
//
// 1. Create a whitelist call on Kusama Asset Hub.
Expand Down
2 changes: 2 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ pub(super) struct UpgradeDetails {
pub(super) output_file: String,
// An additional call to be enacted in the same batch as the system upgrade.
pub(super) additional: Option<CallInfo>,
// Skip sanity checks on the downloaded runtime blobs.
pub(super) no_runtime_checks: bool,
}

// A network and the version to which it will upgrade.
Expand Down
Loading