Skip to content

Commit

Permalink
Fix Rust features (paritytech#11976)
Browse files Browse the repository at this point in the history
* Add std feature

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix features

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix features

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix features

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Cleanup

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Impl function also in tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make compile

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix sp-trie feature

Something makes the bench regression guard fail, maybe this?

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add runtime-benchmarks feature to sc-service

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert "Fix sp-trie feature"

This reverts commit f2cddfe.
Was already fixed, only needed a CI retry.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
ggwpez authored and ark0f committed Feb 27, 2023
1 parent 288206d commit 008719e
Show file tree
Hide file tree
Showing 84 changed files with 250 additions and 110 deletions.
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 @@ -159,7 +159,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 @@ -117,6 +117,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",
"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 @@ -148,6 +155,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 @@ -159,6 +167,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 @@ -167,7 +176,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 @@ -188,7 +197,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 @@ -221,16 +230,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 @@ -242,7 +251,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 @@ -387,7 +387,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

0 comments on commit 008719e

Please sign in to comment.