Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix Rust features #11976

Merged
merged 17 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from 14 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
29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion bin/node-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ substrate-build-script-utils = { version = "3.0.0", path = "../../../utils/build

[features]
default = []
runtime-benchmarks = ["node-template-runtime/runtime-benchmarks"]
# Dependencies that are only required if runtime benchmarking should be build.
runtime-benchmarks = [
"node-template-runtime/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-benchmarking-cli/runtime-benchmarks",
]
# Enable features that allow the runtime to be tried and debugged. Name might be subject to change
# in the near future.
try-runtime = ["node-template-runtime/try-runtime", "try-runtime-cli"]
6 changes: 6 additions & 0 deletions bin/node-template/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ pub fn run() -> sc_cli::Result<()> {
let PartialComponents { client, .. } = service::new_partial(&config)?;
cmd.run(client)
},
#[cfg(not(feature = "runtime-benchmarks"))]
BenchmarkCmd::Storage(_) => Err(
"Storage benchmarking can be enabled with `--features runtime-benchmarks`."
.into(),
),
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(cmd) => {
let PartialComponents { client, backend, .. } =
service::new_partial(&config)?;
Expand Down
2 changes: 1 addition & 1 deletion bin/node-template/pallets/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sp-runtime = { version = "6.0.0", default-features = false, path = "../../../../
default = ["std"]
std = [
"codec/std",
"frame-benchmarking/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
Expand Down
5 changes: 4 additions & 1 deletion bin/node-template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-bu
[features]
default = ["std"]
std = [
"frame-try-runtime?/std",
"frame-system-benchmarking?/std",
"frame-benchmarking?/std",
"codec/std",
"scale-info/std",
"frame-executive/std",
Expand Down Expand Up @@ -88,7 +91,7 @@ std = [
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system-benchmarking",
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"pallet-balances/runtime-benchmarks",
Expand Down
5 changes: 4 additions & 1 deletion bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ cli = [
"substrate-build-script-utils",
"try-runtime-cli",
]
runtime-benchmarks = ["kitchensink-runtime/runtime-benchmarks", "frame-benchmarking-cli"]
runtime-benchmarks = [
"kitchensink-runtime/runtime-benchmarks",
"frame-benchmarking-cli/runtime-benchmarks"
]
# Enable features that allow the runtime to be tried and debugged. Name might be subject to change
# in the near future.
try-runtime = ["kitchensink-runtime/try-runtime", "try-runtime-cli"]
Expand Down
6 changes: 6 additions & 0 deletions bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ pub fn run() -> Result<()> {
let partial = new_partial(&config)?;
cmd.run(partial.client)
},
#[cfg(not(feature = "runtime-benchmarks"))]
BenchmarkCmd::Storage(_) => Err(
"Storage benchmarking can be enabled with `--features runtime-benchmarks`."
.into(),
),
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(cmd) => {
// ensure that we keep the task manager alive
let partial = new_partial(&config)?;
Expand Down
21 changes: 15 additions & 6 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ substrate-wasm-builder = { version = "5.0.0-dev", path = "../../../utils/wasm-bu
default = ["std"]
with-tracing = ["frame-executive/with-tracing"]
std = [
"sp-sandbox/std",
Copy link
Member

Choose a reason for hiding this comment

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

You can just remove the unused depedency, then we don't need to add it here :P

Copy link
Member Author

Choose a reason for hiding this comment

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

There also is cargo udeps which claims to find unused crates.
I will give it a try later.

"pallet-whitelist/std",
"pallet-offences-benchmarking?/std",
"pallet-election-provider-support-benchmarking?/std",
"pallet-asset-tx-payment/std",
"frame-system-benchmarking?/std",
"frame-election-provider-support/std",
"sp-authority-discovery/std",
"pallet-assets/std",
"pallet-authority-discovery/std",
Expand Down Expand Up @@ -147,6 +154,7 @@ std = [
"pallet-multisig/std",
"pallet-nomination-pools/std",
"pallet-nomination-pools-runtime-api/std",
"pallet-nomination-pools-benchmarking?/std",
"pallet-identity/std",
"pallet-scheduler/std",
"node-primitives/std",
Expand All @@ -158,6 +166,7 @@ std = [
"pallet-randomness-collective-flip/std",
"sp-std/std",
"pallet-session/std",
"pallet-session-benchmarking?/std",
"sp-api/std",
"sp-runtime/std",
"sp-staking/std",
Expand All @@ -166,7 +175,7 @@ std = [
"sp-session/std",
"pallet-sudo/std",
"frame-support/std",
"frame-benchmarking/std",
"frame-benchmarking?/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"pallet-election-provider-multi-phase/std",
Expand All @@ -187,7 +196,7 @@ std = [
"pallet-uniques/std",
"pallet-vesting/std",
"log/std",
"frame-try-runtime/std",
"frame-try-runtime?/std",
"sp-io/std",
"pallet-child-bounties/std",
"pallet-alliance/std",
Expand Down Expand Up @@ -220,16 +229,16 @@ runtime-benchmarks = [
"pallet-membership/runtime-benchmarks",
"pallet-mmr/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-nomination-pools-benchmarking",
"pallet-offences-benchmarking",
"pallet-nomination-pools-benchmarking/runtime-benchmarks",
"pallet-offences-benchmarking/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-ranked-collective/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
"pallet-recovery/runtime-benchmarks",
"pallet-remark/runtime-benchmarks",
"pallet-session-benchmarking",
"pallet-session-benchmarking/runtime-benchmarks",
"pallet-society/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-state-trie-migration/runtime-benchmarks",
Expand All @@ -241,7 +250,7 @@ runtime-benchmarks = [
"pallet-uniques/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
"pallet-whitelist/runtime-benchmarks",
"frame-system-benchmarking",
"frame-system-benchmarking/runtime-benchmarks",
"hex-literal",
]
try-runtime = [
Expand Down
1 change: 1 addition & 0 deletions client/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ rocksdb = ["sc-client-db/rocksdb"]
wasmtime = ["sc-executor/wasmtime"]
# exposes the client type
test-helpers = []
runtime-benchmarks = ["sc-client-db/runtime-benchmarks"]

[dependencies]
jsonrpsee = { version = "0.15.1", features = ["server"] }
Expand Down
4 changes: 3 additions & 1 deletion frame/alliance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pallet-collective = { version = "4.0.0-dev", path = "../collective" }
[features]
default = ["std"]
std = [
"pallet-collective?/std",
"frame-benchmarking?/std",
"log/std",
"codec/std",
"scale-info/std",
Expand All @@ -55,7 +57,7 @@ std = [
runtime-benchmarks = [
"hex",
"sha2",
"frame-benchmarking",
"frame-benchmarking/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
Expand Down
2 changes: 1 addition & 1 deletion frame/assets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ std = [
"sp-runtime/std",
"frame-support/std",
"frame-system/std",
"frame-benchmarking/std",
"frame-benchmarking?/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
2 changes: 1 addition & 1 deletion frame/babe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sp-core = { version = "6.0.0", path = "../../primitives/core" }
default = ["std"]
std = [
"codec/std",
"frame-benchmarking/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
Expand Down
29 changes: 2 additions & 27 deletions frame/babe/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

//! Benchmarks for the BABE Pallet.

#![cfg(feature = "runtime-benchmarks")]

use super::*;
use frame_benchmarking::benchmarks;

Expand Down Expand Up @@ -70,30 +72,3 @@ benchmarks! {
crate::mock::Test,
)
}

#[cfg(test)]
mod tests {
use super::*;
use crate::mock::*;

#[test]
fn test_generate_equivocation_report_blob() {
let (pairs, mut ext) = new_test_ext_with_pairs(3);

let offending_authority_index = 0;
let offending_authority_pair = &pairs[0];

ext.execute_with(|| {
start_era(1);

let equivocation_proof = generate_equivocation_proof(
offending_authority_index,
offending_authority_pair,
CurrentSlot::<Test>::get() + 1,
);

println!("equivocation_proof: {:?}", equivocation_proof);
println!("equivocation_proof.encode(): {:?}", equivocation_proof.encode());
});
}
}
21 changes: 21 additions & 0 deletions frame/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,3 +926,24 @@ fn add_epoch_configurations_migration_works() {
assert_eq!(PendingEpochConfigChange::<Test>::get(), Some(next_config_descriptor));
});
}

#[test]
fn generate_equivocation_report_blob() {
let (pairs, mut ext) = new_test_ext_with_pairs(3);

let offending_authority_index = 0;
let offending_authority_pair = &pairs[0];

ext.execute_with(|| {
start_era(1);

let equivocation_proof = generate_equivocation_proof(
offending_authority_index,
offending_authority_pair,
CurrentSlot::<Test>::get() + 1,
);

println!("equivocation_proof: {:?}", equivocation_proof);
println!("equivocation_proof.encode(): {:?}", equivocation_proof.encode());
});
}
9 changes: 8 additions & 1 deletion frame/bags-list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ sp-core = { version = "6.0.0", path = "../../primitives/core"}
sp-io = { version = "6.0.0", path = "../../primitives/io"}
sp-tracing = { version = "5.0.0", path = "../../primitives/tracing" }
pallet-balances = { version = "4.0.0-dev", path = "../balances" }
frame-election-provider-support = { version = "4.0.0-dev", path = "../election-provider-support", features = ["runtime-benchmarks"] }
frame-election-provider-support = { version = "4.0.0-dev", path = "../election-provider-support" }
frame-benchmarking = { version = "4.0.0-dev", path = "../benchmarking" }

[features]
default = ["std"]
std = [
"sp-tracing?/std",
"sp-io?/std",
"sp-core?/std",
"pallet-balances?/std",
"frame-benchmarking?/std",
"scale-info/std",
"codec/std",
"sp-runtime/std",
"sp-std/std",
Expand All @@ -68,5 +74,6 @@ fuzz = [
"sp-io",
"pallet-balances",
"sp-tracing",
"frame-election-provider-support/fuzz",
]
try-runtime = [ "frame-support/try-runtime" ]
2 changes: 1 addition & 1 deletion frame/bags-list/fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ publish = false
[dependencies]
honggfuzz = "0.5"
rand = { version = "0.8", features = ["std", "small_rng"] }
frame-election-provider-support = { version = "4.0.0-dev", features = ["runtime-benchmarks"], path = "../../election-provider-support" }
frame-election-provider-support = { version = "4.0.0-dev", features = ["fuzz"], path = "../../election-provider-support" }
pallet-bags-list = { version = "4.0.0-dev", features = ["fuzz"], path = ".." }

[[bin]]
Expand Down
2 changes: 1 addition & 1 deletion frame/bags-list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ impl<T: Config<I>, I: 'static> ScoreProvider<T::AccountId> for Pallet<T, I> {
Node::<T, I>::get(id).map(|node| node.score()).unwrap_or_default()
}

#[cfg(any(feature = "runtime-benchmarks", test))]
#[cfg(any(feature = "runtime-benchmarks", feature = "fuzz", test))]
fn set_score_of(id: &T::AccountId, new_score: T::Score) {
ListNodes::<T, I>::mutate(id, |maybe_node| {
if let Some(node) = maybe_node.as_mut() {
Expand Down
2 changes: 1 addition & 1 deletion frame/bags-list/src/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ impl<T: Config<I>, I: 'static> Node<T, I> {
&self.id
}

#[cfg(any(feature = "runtime-benchmarks", test))]
#[cfg(any(feature = "runtime-benchmarks", feature = "fuzz", test))]
pub fn set_score(&mut self, s: T::Score) {
self.score = s
}
Expand Down
Loading