Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
1 change: 1 addition & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@ runtime-benchmarks = [
"pallet-timestamp/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
]
42 changes: 34 additions & 8 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 233,
impl_version: 0,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
};

Expand Down Expand Up @@ -842,13 +842,39 @@ impl_runtime_apis! {
) -> Result<Vec<frame_benchmarking::BenchmarkResults>, sp_runtime::RuntimeString> {
use frame_benchmarking::Benchmarking;

match module.as_slice() {
b"pallet-balances" | b"balances" => Balances::run_benchmark(extrinsic, steps, repeat).ok(),
b"pallet-identity" | b"identity" => Identity::run_benchmark(extrinsic, steps, repeat).ok(),
b"pallet-timestamp" | b"timestamp" => Timestamp::run_benchmark(extrinsic, steps, repeat).ok(),
b"pallet-vesting" | b"vesting" => Vesting::run_benchmark(extrinsic, steps, repeat).ok(),
_ => None,
}
let result = match module.as_slice() {
b"pallet-balances" | b"balances" => Balances::run_benchmark(
extrinsic,
lowest_range_values,
highest_range_values,
steps,
repeat,
),
b"pallet-identity" | b"identity" => Identity::run_benchmark(
extrinsic,
lowest_range_values,
highest_range_values,
steps,
repeat,
),
b"pallet-timestamp" | b"timestamp" => Timestamp::run_benchmark(
extrinsic,
lowest_range_values,
highest_range_values,
steps,
repeat,
),
b"pallet-vesting" | b"vesting" => Vesting::run_benchmark(
extrinsic,
lowest_range_values,
highest_range_values,
steps,
repeat,
),
_ => Err("Benchmark not found for this pallet."),
};

result.map_err(|e| e.into())
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,8 +893,7 @@ impl<T: Trait> Module<T> {

/// Set the block number to something in particular. Can be used as an alternative to
/// `initialize` for tests that don't need to bother with the other environment entries.
// TODO: feature guard this once #4873 is closed.
// #[cfg(any(feature = "std", test))]
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
pub fn set_block_number(n: T::BlockNumber) {
<Number<T>>::put(n);
}
Expand Down
13 changes: 7 additions & 6 deletions frame/vesting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ description = "FRAME pallet for manage vesting"
serde = { version = "1.0.101", optional = true }
codec = { package = "parity-scale-codec", version = "1.2.0", default-features = false, features = ["derive"] }
enumflags2 = { version = "0.6.2" }
sp-std = { version = "2.0.0-dev", default-features = false, path = "../../primitives/std" }
sp-io = { version = "2.0.0-dev", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "2.0.0-dev", default-features = false, path = "../../primitives/runtime" }
frame-benchmarking = { version = "2.0.0-dev", default-features = false, path = "../benchmarking" }
frame-support = { version = "2.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "2.0.0-dev", default-features = false, path = "../system" }
sp-std = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/std" }
sp-io = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/runtime" }
frame-support = { version = "2.0.0-alpha.2", default-features = false, path = "../support" }
frame-system = { version = "2.0.0-alpha.2", default-features = false, path = "../system" }
frame-benchmarking = { version = "2.0.0-alpha.2", default-features = false, path = "../benchmarking", optional = true }

[dev-dependencies]
sp-core = { version = "2.0.0-alpha.2", path = "../../primitives/core" }
Expand All @@ -36,3 +36,4 @@ std = [
"frame-support/std",
"frame-system/std",
]
runtime-benchmarks = ["frame-benchmarking", "frame-system/runtime-benchmarks"]
21 changes: 17 additions & 4 deletions frame/vesting/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use super::*;
use frame_system::{RawOrigin, Module as System};
use sp_io::hashing::blake2_256;
use frame_benchmarking::{benchmarks, account};
use sp_runtime::traits::Dispatchable;

use crate::Module as Vesting;

Expand Down Expand Up @@ -84,10 +83,24 @@ benchmarks! {
let b in ...;
let l in ...;

let other: T::AccountId = account("other", 0, SEED);
let other: T::AccountId = setup::<T>(b);
let other_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(other.clone());

let caller = setup::<T>(b);

let caller = account("caller", 0, SEED);
}: _(RawOrigin::Signed(caller), other_lookup)

vested_transfer{
let u in 0 .. 1000;
let from = account("from", u, SEED);
let to = account("to", u, SEED);
let to_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(to);
let transfer_amt = T::MinVestedTransfer::get();
let vesting_schedule = VestingInfo {
locked: transfer_amt,
per_block: 1.into(),
starting_block: 0.into(),
};
let _ = T::Currency::make_free_balance_be(&from, transfer_amt * 10.into());

}: _(RawOrigin::Signed(from), to_lookup, vesting_schedule)
}
3 changes: 2 additions & 1 deletion frame/vesting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ use frame_support::traits::{
use frame_support::weights::SimpleDispatchInfo;
use frame_system::{self as system, ensure_signed};

pub mod benchmarking;
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;

Expand Down