Skip to content

Commit

Permalink
Cleanup unused imports and enforce Clippy lints (#15)
Browse files Browse the repository at this point in the history
* remove unused imports and add clippy check

* remove unneeded return statement

* fix remaining issues

* clippy

* parallel ci

* nightly clippy toolchain

* concurrency

* install toolchain

* typo

* fix toolchain

* add fmt check

* rustfmt component

* restore cargo_term_color

* naming
  • Loading branch information
liamaharon authored Jan 22, 2024
1 parent e13181e commit 218d437
Show file tree
Hide file tree
Showing 5 changed files with 448 additions and 444 deletions.
45 changes: 38 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
name: Rust

# Cancel a currently running workflow from the same PR, branch or tag when a new workflow is
# triggered (ref https://stackoverflow.com/a/72408109)
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]
branches: ["master"]

env:
CARGO_TERM_COLOR: always
TOOLCHAIN_LINT: nightly-2023-11-13

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.TOOLCHAIN_LINT }}
components: rustfmt, clippy, rust-src
override: true

- name: Fmt
run: cargo +${{ env.TOOLCHAIN_LINT }} fmt --all -- --check

- name: Clippy
uses: actions-rs-plus/clippy-check@v2
with:
toolchain: ${{ env.TOOLCHAIN_LINT }}
args: --all-targets --all-features -- -D warnings

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- uses: actions/checkout@v3
- name: Run tests
run: cargo test --verbose
31 changes: 15 additions & 16 deletions src/build_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ pub(crate) async fn build_upgrade(prefs: UpgradeArgs) {
// Parse the CLI inputs and return a typed struct with all the details needed.
fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails {
let mut networks = Vec::new();
let relay_version = String::from(prefs.relay_version.trim_start_matches("v"));
let relay_version = String::from(prefs.relay_version.trim_start_matches('v'));
let paras_version = if let Some(user_para_version) = prefs.parachain_version {
String::from(user_para_version.trim_start_matches("v"))
String::from(user_para_version.trim_start_matches('v'))
} else {
relay_version.clone()
};
Expand Down Expand Up @@ -106,7 +106,7 @@ fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails {

make_version_directory(directory.as_str());

return UpgradeDetails { relay, networks, directory, output_file }
UpgradeDetails { relay, networks, directory, output_file }
}

// Create a directory into which to place runtime blobs and the final call data.
Expand All @@ -117,7 +117,7 @@ fn make_version_directory(dir_name: &str) {
}

// Convert a semver version (e.g. "1.2.3") to an integer runtime version (e.g. 1002003).
fn semver_to_intver(semver: &String) -> String {
fn semver_to_intver(semver: &str) -> String {
// M.m.p => M_mmm_ppp
let points =
semver.bytes().enumerate().filter(|(_, b)| *b == b'.').map(|(i, _)| i).collect::<Vec<_>>();
Expand Down Expand Up @@ -186,7 +186,7 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec<Cal
);
let runtime = fs::read(path).expect("Should give a valid file path");
let runtime_hash = blake2_256(&runtime);
println!("Kusama Asset Hub Runtime Hash: 0x{}", hex::encode(&runtime_hash));
println!("Kusama Asset Hub Runtime Hash: 0x{}", hex::encode(runtime_hash));

let call = CallInfo::from_runtime_call(NetworkRuntimeCall::KusamaAssetHub(
KusamaAssetHubRuntimeCall::ParachainSystem(Call::authorize_upgrade {
Expand All @@ -204,7 +204,7 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec<Cal
);
let runtime = fs::read(path).expect("Should give a valid file path");
let runtime_hash = blake2_256(&runtime);
println!("Kusama Bridge Hub Runtime Hash: 0x{}", hex::encode(&runtime_hash));
println!("Kusama Bridge Hub Runtime Hash: 0x{}", hex::encode(runtime_hash));

let call = CallInfo::from_runtime_call(NetworkRuntimeCall::KusamaBridgeHub(
KusamaBridgeHubRuntimeCall::ParachainSystem(Call::authorize_upgrade {
Expand All @@ -222,7 +222,7 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec<Cal
);
let runtime = fs::read(path).expect("Should give a valid file path");
let runtime_hash = blake2_256(&runtime);
println!("Polkadot Asset Hub Runtime Hash: 0x{}", hex::encode(&runtime_hash));
println!("Polkadot Asset Hub Runtime Hash: 0x{}", hex::encode(runtime_hash));

let call = CallInfo::from_runtime_call(NetworkRuntimeCall::PolkadotAssetHub(
PolkadotAssetHubRuntimeCall::ParachainSystem(Call::authorize_upgrade {
Expand All @@ -240,7 +240,7 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec<Cal
);
let runtime = fs::read(path).expect("Should give a valid file path");
let runtime_hash = blake2_256(&runtime);
println!("Polkadot Collectives Runtime Hash: 0x{}", hex::encode(&runtime_hash));
println!("Polkadot Collectives Runtime Hash: 0x{}", hex::encode(runtime_hash));

let call = CallInfo::from_runtime_call(NetworkRuntimeCall::PolkadotCollectives(
CollectivesRuntimeCall::ParachainSystem(Call::authorize_upgrade {
Expand All @@ -258,7 +258,7 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec<Cal
);
let runtime = fs::read(path).expect("Should give a valid file path");
let runtime_hash = blake2_256(&runtime);
println!("Polkadot Bridge Hub Runtime Hash: 0x{}", hex::encode(&runtime_hash));
println!("Polkadot Bridge Hub Runtime Hash: 0x{}", hex::encode(runtime_hash));

let call = CallInfo::from_runtime_call(NetworkRuntimeCall::PolkadotBridgeHub(
PolkadotBridgeHubRuntimeCall::ParachainSystem(Call::authorize_upgrade {
Expand All @@ -278,7 +278,7 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec<Cal
fn generate_relay_upgrade_call(upgrade_details: &UpgradeDetails) -> CallInfo {
println!("\nGenerating Relay Chain upgrade call. The runtime hash is logged if you would like to verify it with srtool.\n");
let runtime_version = semver_to_intver(&upgrade_details.relay.version);
let upgrade_call = match upgrade_details.relay.network {
match upgrade_details.relay.network {
Network::Kusama => {
use kusama_relay::runtime_types::frame_system::pallet::Call as SystemCall;

Expand All @@ -288,7 +288,7 @@ fn generate_relay_upgrade_call(upgrade_details: &UpgradeDetails) -> CallInfo {
);
let runtime = fs::read(path).expect("Should give a valid file path");
let runtime_hash = blake2_256(&runtime);
println!("Kusama Relay Chain Runtime Hash: 0x{}", hex::encode(&runtime_hash));
println!("Kusama Relay Chain Runtime Hash: 0x{}", hex::encode(runtime_hash));

CallInfo::from_runtime_call(NetworkRuntimeCall::Kusama(KusamaRuntimeCall::System(
SystemCall::set_code { code: runtime },
Expand All @@ -303,15 +303,14 @@ fn generate_relay_upgrade_call(upgrade_details: &UpgradeDetails) -> CallInfo {
);
let runtime = fs::read(path).expect("Should give a valid file path");
let runtime_hash = blake2_256(&runtime);
println!("Polkadot Relay Chain Runtime Hash: 0x{}", hex::encode(&runtime_hash));
println!("Polkadot Relay Chain Runtime Hash: 0x{}", hex::encode(runtime_hash));

CallInfo::from_runtime_call(NetworkRuntimeCall::Polkadot(PolkadotRuntimeCall::System(
SystemCall::set_code { code: runtime },
)))
},
_ => panic!("Not a Relay Chain"),
};
upgrade_call
}
}

// Take the parachain authorization calls and the Relay Chain call, and batch them into one call
Expand Down Expand Up @@ -407,7 +406,7 @@ async fn send_as_superuser_from_kusama(auth: &CallInfo) -> KusamaRuntimeCall {
},
};

let (ref_time, proof_size) = get_weight(&auth).await;
let (ref_time, proof_size) = get_weight(auth).await;
let para_id = auth.network.get_para_id().unwrap();
KusamaRuntimeCall::XcmPallet(XcmCall::send {
dest: Box::new(VersionedMultiLocation::V3(MultiLocation {
Expand Down Expand Up @@ -447,7 +446,7 @@ async fn send_as_superuser_from_polkadot(auth: &CallInfo) -> PolkadotRuntimeCall
},
};

let (ref_time, proof_size) = get_weight(&auth).await;
let (ref_time, proof_size) = get_weight(auth).await;
let para_id = auth.network.get_para_id().unwrap();
PolkadotRuntimeCall::XcmPallet(XcmCall::send {
dest: Box::new(VersionedMultiLocation::V3(MultiLocation {
Expand Down
20 changes: 10 additions & 10 deletions src/submit_referendum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn parse_inputs(prefs: ReferendumArgs) -> ProposalDetails {
AppsUiLink
};

return ProposalDetails {
ProposalDetails {
proposal,
track,
dispatch,
Expand All @@ -140,7 +140,7 @@ pub(crate) async fn generate_calls(proposal_details: &ProposalDetails) -> Possib
NetworkTrack::KusamaRoot => {
use kusama_relay::runtime_types::frame_support::dispatch::RawOrigin;
kusama_non_fellowship_referenda(
&proposal_details,
proposal_details,
KusamaOriginCaller::system(RawOrigin::Root),
)
},
Expand All @@ -150,11 +150,11 @@ pub(crate) async fn generate_calls(proposal_details: &ProposalDetails) -> Possib
match kusama_track {
// Whitelisted calls are special.
KusamaOpenGovOrigin::WhitelistedCaller =>
kusama_fellowship_referenda(&proposal_details),
kusama_fellowship_referenda(proposal_details),

// All other Kusama origins.
_ => kusama_non_fellowship_referenda(
&proposal_details,
proposal_details,
KusamaOriginCaller::Origins(kusama_track.clone()),
),
}
Expand All @@ -164,7 +164,7 @@ pub(crate) async fn generate_calls(proposal_details: &ProposalDetails) -> Possib
NetworkTrack::PolkadotRoot => {
use polkadot_relay::runtime_types::frame_support::dispatch::RawOrigin;
polkadot_non_fellowship_referenda(
&proposal_details,
proposal_details,
PolkadotOriginCaller::system(RawOrigin::Root),
)
},
Expand All @@ -173,11 +173,11 @@ pub(crate) async fn generate_calls(proposal_details: &ProposalDetails) -> Possib
NetworkTrack::Polkadot(polkadot_track) => {
match polkadot_track {
PolkadotOpenGovOrigin::WhitelistedCaller =>
polkadot_fellowship_referenda(&proposal_details).await,
polkadot_fellowship_referenda(proposal_details).await,

// All other Polkadot origins.
_ => polkadot_non_fellowship_referenda(
&proposal_details,
proposal_details,
PolkadotOriginCaller::Origins(polkadot_track.clone()),
),
}
Expand Down Expand Up @@ -626,21 +626,21 @@ fn handle_batch_of_calls(output: &Output, batch: Vec<NetworkRuntimeCall>) {
_ => panic!("no other chains are needed for this"),
}
}
if kusama_relay_batch.len() > 0 {
if !kusama_relay_batch.is_empty() {
let batch = KusamaRuntimeCall::Utility(KusamaUtilityCall::force_batch {
calls: kusama_relay_batch,
});
println!("\nBatch to submit on Kusama Relay Chain:");
print_output(output, &NetworkRuntimeCall::Kusama(batch));
}
if polkadot_relay_batch.len() > 0 {
if !polkadot_relay_batch.is_empty() {
let batch = PolkadotRuntimeCall::Utility(PolkadotRelayUtilityCall::force_batch {
calls: polkadot_relay_batch,
});
println!("\nBatch to submit on Polkadot Relay Chain:");
print_output(output, &NetworkRuntimeCall::Polkadot(batch));
}
if polkadot_collectives_batch.len() > 0 {
if !polkadot_collectives_batch.is_empty() {
let batch = CollectivesRuntimeCall::Utility(CollectivesUtilityCall::force_batch {
calls: polkadot_collectives_batch,
});
Expand Down
Loading

0 comments on commit 218d437

Please sign in to comment.