Skip to content

Commit 89498c0

Browse files
authored
Fixup some wrong dependencies (paritytech#12899)
* Fixup some wrong dependencies Dev dependencies should not appear in the feature list. If features are required, they should be directly enabled for the `dev-dependency`. * More fixups * Fix fix * Remove deprecated feature * Make all work properly and nice!! * FMT * Fix formatting
1 parent 93fa104 commit 89498c0

File tree

17 files changed

+120
-78
lines changed

17 files changed

+120
-78
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frame/assets/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ frame-support = { version = "4.0.0-dev", default-features = false, path = "../su
2323
# `system` module provides us with all sorts of useful stuff and macros depend on it being around.
2424
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
2525
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
26+
sp-core = { version = "7.0.0", default-features = false, path = "../../primitives/core" }
2627

2728
[dev-dependencies]
28-
sp-core = { version = "7.0.0", path = "../../primitives/core" }
2929
sp-std = { version = "5.0.0", path = "../../primitives/std" }
3030
sp-io = { version = "7.0.0", path = "../../primitives/io" }
3131
pallet-balances = { version = "4.0.0-dev", path = "../balances" }
@@ -35,6 +35,7 @@ default = ["std"]
3535
std = [
3636
"codec/std",
3737
"scale-info/std",
38+
"sp-core/std",
3839
"sp-std/std",
3940
"sp-runtime/std",
4041
"frame-support/std",

frame/assets/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,3 +1487,5 @@ pub mod pallet {
14871487
}
14881488
}
14891489
}
1490+
1491+
sp_core::generate_feature_enabled_macro!(runtime_benchmarks_enabled, feature = "runtime-benchmarks", $);

frame/bags-list/src/lib.rs

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -359,25 +359,26 @@ impl<T: Config<I>, I: 'static> SortedListProvider<T::AccountId> for Pallet<T, I>
359359
List::<T, I>::unsafe_clear()
360360
}
361361

362-
#[cfg(feature = "runtime-benchmarks")]
363-
fn score_update_worst_case(who: &T::AccountId, is_increase: bool) -> Self::Score {
364-
use frame_support::traits::Get as _;
365-
let thresholds = T::BagThresholds::get();
366-
let node = list::Node::<T, I>::get(who).unwrap();
367-
let current_bag_idx = thresholds
368-
.iter()
369-
.chain(sp_std::iter::once(&T::Score::max_value()))
370-
.position(|w| w == &node.bag_upper())
371-
.unwrap();
372-
373-
if is_increase {
374-
let next_threshold_idx = current_bag_idx + 1;
375-
assert!(thresholds.len() > next_threshold_idx);
376-
thresholds[next_threshold_idx]
377-
} else {
378-
assert!(current_bag_idx != 0);
379-
let prev_threshold_idx = current_bag_idx - 1;
380-
thresholds[prev_threshold_idx]
362+
frame_election_provider_support::runtime_benchmarks_enabled! {
363+
fn score_update_worst_case(who: &T::AccountId, is_increase: bool) -> Self::Score {
364+
use frame_support::traits::Get as _;
365+
let thresholds = T::BagThresholds::get();
366+
let node = list::Node::<T, I>::get(who).unwrap();
367+
let current_bag_idx = thresholds
368+
.iter()
369+
.chain(sp_std::iter::once(&T::Score::max_value()))
370+
.position(|w| w == &node.bag_upper)
371+
.unwrap();
372+
373+
if is_increase {
374+
let next_threshold_idx = current_bag_idx + 1;
375+
assert!(thresholds.len() > next_threshold_idx);
376+
thresholds[next_threshold_idx]
377+
} else {
378+
assert!(current_bag_idx != 0);
379+
let prev_threshold_idx = current_bag_idx - 1;
380+
thresholds[prev_threshold_idx]
381+
}
381382
}
382383
}
383384
}
@@ -389,14 +390,15 @@ impl<T: Config<I>, I: 'static> ScoreProvider<T::AccountId> for Pallet<T, I> {
389390
Node::<T, I>::get(id).map(|node| node.score()).unwrap_or_default()
390391
}
391392

392-
#[cfg(any(feature = "runtime-benchmarks", feature = "fuzz", test))]
393-
fn set_score_of(id: &T::AccountId, new_score: T::Score) {
394-
ListNodes::<T, I>::mutate(id, |maybe_node| {
395-
if let Some(node) = maybe_node.as_mut() {
396-
node.set_score(new_score)
397-
} else {
398-
panic!("trying to mutate {:?} which does not exists", id);
399-
}
400-
})
393+
frame_election_provider_support::runtime_benchmarks_or_fuzz_enabled! {
394+
fn set_score_of(id: &T::AccountId, new_score: T::Score) {
395+
ListNodes::<T, I>::mutate(id, |maybe_node| {
396+
if let Some(node) = maybe_node.as_mut() {
397+
node.score = new_score;
398+
} else {
399+
panic!("trying to mutate {:?} which does not exists", id);
400+
}
401+
})
402+
}
401403
}
402404
}

frame/election-provider-support/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ sp-arithmetic = { version = "6.0.0", default-features = false, path = "../../pri
2121
sp-npos-elections = { version = "4.0.0-dev", default-features = false, path = "../../primitives/npos-elections" }
2222
sp-runtime = { version = "7.0.0", default-features = false, path = "../../primitives/runtime" }
2323
sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" }
24+
sp-core = { version = "7.0.0", default-features = false, path = "../../primitives/core" }
2425

2526
[dev-dependencies]
2627
rand = "0.7.3"
27-
sp-core = { version = "7.0.0", path = "../../primitives/core" }
2828
sp-io = { version = "7.0.0", path = "../../primitives/io" }
2929
sp-npos-elections = { version = "4.0.0-dev", path = "../../primitives/npos-elections" }
3030

@@ -38,6 +38,7 @@ std = [
3838
"scale-info/std",
3939
"sp-arithmetic/std",
4040
"sp-npos-elections/std",
41+
"sp-core/std",
4142
"sp-runtime/std",
4243
"sp-std/std",
4344
]

frame/election-provider-support/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,3 +671,6 @@ pub type BoundedSupportsOf<E> = BoundedSupports<
671671
<E as ElectionProviderBase>::AccountId,
672672
<E as ElectionProviderBase>::MaxWinners,
673673
>;
674+
675+
sp_core::generate_feature_enabled_macro!(runtime_benchmarks_enabled, feature = "runtime-benchmarks", $);
676+
sp_core::generate_feature_enabled_macro!(runtime_benchmarks_or_fuzz_enabled, any(feature = "runtime-benchmarks", feature = "fuzzing"), $);

frame/fast-unstake/Cargo.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ sp-std = { version = "5.0.0", default-features = false, path = "../../primitives
2525
sp-staking = { default-features = false, path = "../../primitives/staking" }
2626
frame-election-provider-support = { default-features = false, path = "../election-provider-support" }
2727

28-
# optional dependencies for cargo features
2928
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../benchmarking" }
30-
pallet-staking = { default-features = false, optional = true, path = "../staking" }
31-
pallet-assets = { default-features = false, optional = true, path = "../assets" }
3229

3330
[dev-dependencies]
3431
pallet-staking-reward-curve = { version = "4.0.0-dev", path = "../staking/reward-curve" }
@@ -38,8 +35,6 @@ sp-tracing = { version = "6.0.0", path = "../../primitives/tracing" }
3835
pallet-staking = { path = "../staking" }
3936
pallet-balances = { path = "../balances" }
4037
pallet-timestamp = { path = "../timestamp" }
41-
pallet-assets = { path = "../assets" }
42-
4338

4439
[features]
4540
default = ["std"]
@@ -64,6 +59,5 @@ runtime-benchmarks = [
6459
"frame-benchmarking/runtime-benchmarks",
6560
"frame-system/runtime-benchmarks",
6661
"sp-staking/runtime-benchmarks",
67-
"pallet-staking/runtime-benchmarks"
6862
]
6963
try-runtime = ["frame-support/try-runtime"]

frame/nomination-pools/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sp-core = { version = "7.0.0", default-features = false, path = "../../primitive
2626
sp-io = { version = "7.0.0", default-features = false, path = "../../primitives/io" }
2727
log = { version = "0.4.0", default-features = false }
2828

29-
# Optional: usef for testing and/or fuzzing
29+
# Optional: use for testing and/or fuzzing
3030
pallet-balances = { version = "4.0.0-dev", path = "../balances", optional = true }
3131
sp-tracing = { version = "6.0.0", path = "../../primitives/tracing", optional = true }
3232

frame/nomination-pools/benchmarking/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ sp-runtime = { version = "7.0.0", default-features = false, path = "../../../pri
3131
sp-runtime-interface = { version = "7.0.0", default-features = false, path = "../../../primitives/runtime-interface" }
3232
sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/staking" }
3333
sp-std = { version = "5.0.0", default-features = false, path = "../../../primitives/std" }
34-
sp-io = { optional = true, default-features = false, path = "../../../primitives/io" }
3534

3635
[dev-dependencies]
3736
pallet-balances = { version = "4.0.0-dev", default-features = false, path = "../../balances" }
@@ -53,7 +52,6 @@ std = [
5352
"pallet-nomination-pools/std",
5453
"sp-runtime/std",
5554
"sp-runtime-interface/std",
56-
"sp-io/std",
5755
"sp-staking/std",
5856
"sp-std/std",
5957
]

frame/staking/Cargo.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ sp-application-crypto = { version = "7.0.0", default-features = false, path = ".
3232
frame-election-provider-support = { version = "4.0.0-dev", default-features = false, path = "../election-provider-support" }
3333
log = { version = "0.4.17", default-features = false }
3434

35-
# optional dependencies for cargo features
35+
# Optional imports for benchmarking
3636
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
3737
rand_chacha = { version = "0.2", default-features = false, optional = true }
38-
pallet-bags-list = { default-features = false, optional = true, path = "../bags-list" }
3938

4039
[dev-dependencies]
4140
sp-tracing = { version = "6.0.0", path = "../../primitives/tracing" }
@@ -75,10 +74,5 @@ runtime-benchmarks = [
7574
"frame-election-provider-support/runtime-benchmarks",
7675
"rand_chacha",
7776
"sp-staking/runtime-benchmarks",
78-
"pallet-bags-list/runtime-benchmarks",
7977
]
8078
try-runtime = ["frame-support/try-runtime"]
81-
fuzz = [
82-
"pallet-bags-list/fuzz",
83-
"frame-election-provider-support/fuzz",
84-
]

0 commit comments

Comments
 (0)