Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polkadot v1.12.0 #1003

Merged
merged 8 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
54 changes: 27 additions & 27 deletions Cargo.dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,35 @@ scale-info = { version = "2.10.0", default-features = false, features = ["derive
serde = { version = "1.0.189" }
parity-scale-codec = { version = "3.6.5", default-features = false, features = ["max-encoded-len"] }

cumulus-pallet-xcm = { version = "0.11.0", default-features = false }
cumulus-primitives-core = { version = "0.11.0", default-features = false }
frame-benchmarking = { version = "32.0.0", default-features = false }
frame-support = { version = "32.0.0", default-features = false }
frame-system = { version = "32.0.0", default-features = false }
pallet-balances = { version = "33.0.0", default-features = false }
pallet-elections-phragmen = { version = "33.0.0", default-features = false }
pallet-message-queue = { version = "35.0.0", default-features = false }
pallet-preimage = { version = "32.0.0", default-features = false }
pallet-root-testing = { version = "8.0.0", default-features = false }
pallet-scheduler = { version = "33.0.0", default-features = false }
pallet-timestamp = { version = "31.0.0", default-features = false }
pallet-treasury = { version = "31.0.0", default-features = false }
pallet-xcm = { version = "11.0.0", default-features = false }
polkadot-parachain-primitives = { version = "10.0.0", default-features = false }
polkadot-runtime-common = { version = "11.0.0", default-features = false }
polkadot-runtime-parachains = { version = "11.0.0", default-features = false }
sp-api = { version = "30.0.0", default-features = false }
sp-application-crypto = { version = "34.0.0", default-features = false }
cumulus-pallet-xcm = { version = "0.13.0", default-features = false }
cumulus-primitives-core = { version = "0.13.0", default-features = false }
frame-benchmarking = { version = "34.0.0", default-features = false }
frame-support = { version = "34.0.0", default-features = false }
frame-system = { version = "34.0.1", default-features = false }
pallet-balances = { version = "35.0.0", default-features = false }
pallet-elections-phragmen = { version = "35.0.0", default-features = false }
pallet-message-queue = { version = "37.0.0", default-features = false }
pallet-preimage = { version = "34.0.0", default-features = false }
pallet-root-testing = { version = "10.0.0", default-features = false }
pallet-scheduler = { version = "35.0.0", default-features = false }
pallet-timestamp = { version = "33.0.0", default-features = false }
pallet-treasury = { version = "33.0.0", default-features = false }
pallet-xcm = { version = "13.0.0", default-features = false }
polkadot-parachain-primitives = { version = "12.0.0", default-features = false }
polkadot-runtime-common = { version = "13.0.0", default-features = false }
polkadot-runtime-parachains = { version = "13.0.0", default-features = false }
sp-api = { version = "32.0.0", default-features = false }
sp-application-crypto = { version = "36.0.0", default-features = false }
sp-arithmetic = { version = "26.0.0", default-features = false }
sp-core = { version = "32.0.0", default-features = false }
sp-io = { version = "34.0.0", default-features = false }
sp-runtime = { version = "35.0.0", default-features = false }
sp-core = { version = "33.0.1", default-features = false }
sp-io = { version = "36.0.0", default-features = false }
sp-runtime = { version = "37.0.0", default-features = false }
sp-runtime-interface = { version = "27.0.0", default-features = false }
sp-staking = { version = "30.0.0", default-features = false }
sp-staking = { version = "32.0.0", default-features = false }
sp-std = { version = "14.0.0", default-features = false }
sp-storage = { version = "21.0.0", default-features = false }
xcm = { version = "11.0.0", package = "staging-xcm", default-features = false }
xcm-builder = { version = "11.0.0", package = "staging-xcm-builder", default-features = false }
xcm-executor = { version = "11.0.0", package = "staging-xcm-executor", default-features = false }
xcm = { version = "13.0.1", package = "staging-xcm", default-features = false }
xcm-builder = { version = "13.0.0", package = "staging-xcm-builder", default-features = false }
xcm-executor = { version = "13.0.0", package = "staging-xcm-executor", default-features = false }

xcm-simulator = { version = "11.0.0" }
xcm-simulator = { version = "13.0.0" }
1 change: 1 addition & 0 deletions asset-registry/src/mock/para.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ impl Config for XcmConfig {
type HrmpNewChannelOpenRequestHandler = ();
type HrmpChannelAcceptedHandler = ();
type HrmpChannelClosingHandler = ();
type XcmRecorder = ();
}

impl cumulus_pallet_xcm::Config for Runtime {
Expand Down
1 change: 1 addition & 0 deletions asset-registry/src/mock/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl Config for XcmConfig {
type HrmpNewChannelOpenRequestHandler = ();
type HrmpChannelAcceptedHandler = ();
type HrmpChannelClosingHandler = ();
type XcmRecorder = ();
}

pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, KusamaNetwork>;
Expand Down
2 changes: 2 additions & 0 deletions benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ serde = { workspace = true, optional = true }
frame-benchmarking = { workspace = true }
frame-support = { workspace = true }
sp-api = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-runtime-interface = { workspace = true }
Expand All @@ -38,6 +39,7 @@ std = [
"scale-info/std",
"serde",
"sp-api/std",
"sp-core/std",
"sp-io/std",
"sp-runtime-interface/std",
"sp-runtime/std",
Expand Down
78 changes: 36 additions & 42 deletions benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ mod tests;

pub use frame_benchmarking::{
benchmarking, whitelisted_caller, BenchmarkBatch, BenchmarkConfig, BenchmarkError, BenchmarkList,
BenchmarkMetadata, BenchmarkParameter, BenchmarkResult, Benchmarking, BenchmarkingSetup,
BenchmarkMetadata, BenchmarkParameter, BenchmarkRecording, BenchmarkResult, Benchmarking, BenchmarkingSetup,
Recording,
};

#[cfg(feature = "std")]
pub use frame_benchmarking::{Analysis, BenchmarkSelector};
#[doc(hidden)]
Expand All @@ -20,6 +22,8 @@ pub use parity_scale_codec;
#[doc(hidden)]
pub use paste;
#[doc(hidden)]
pub use sp_core::defer;
#[doc(hidden)]
pub use sp_io::storage::root as storage_root;
#[doc(hidden)]
pub use sp_runtime::traits::Zero;
Expand Down Expand Up @@ -176,7 +180,6 @@ macro_rules! whitelist_account {
/// });
/// }
/// ```

#[macro_export]
macro_rules! runtime_benchmarks {
(
Expand Down Expand Up @@ -626,9 +629,10 @@ macro_rules! benchmark_backend {

fn instance(
&self,
recording: &mut impl $crate::Recording,
components: &[($crate::BenchmarkParameter, u32)],
verify: bool
) -> Result<$crate::Box<dyn FnOnce() -> Result<(), $crate::BenchmarkError>>, $crate::BenchmarkError> {
) -> Result<(), $crate::BenchmarkError> {
$(
// Prepare instance
let $param = components.iter()
Expand All @@ -642,13 +646,14 @@ macro_rules! benchmark_backend {
$( $param_instancer ; )*
$( $post )*

Ok($crate::Box::new(move || -> Result<(), $crate::BenchmarkError> {
$eval;
if verify {
$postcode;
}
Ok(())
}))
recording.start();
$eval;
recording.stop();

if verify {
$postcode;
}
Ok(())
}
}
};
Expand Down Expand Up @@ -696,14 +701,15 @@ macro_rules! selected_benchmark {

fn instance(
&self,
recording: &mut impl $crate::Recording,
components: &[($crate::BenchmarkParameter, u32)],
verify: bool
) -> Result<$crate::Box<dyn FnOnce() -> Result<(), $crate::BenchmarkError>>, $crate::BenchmarkError> {
) -> Result<(), $crate::BenchmarkError> {
match self {
$(
Self::$bench => <
$bench as $crate::BenchmarkingSetup<$runtime $(, $bench_inst)? >
>::instance(&$bench, components, verify),
>::instance(&$bench, recording, components, verify),
)*
}
}
Expand Down Expand Up @@ -781,14 +787,7 @@ macro_rules! impl_benchmark {

let mut results: $crate::Vec<$crate::BenchmarkResult> = $crate::Vec::new();

// Always do at least one internal repeat...
for _ in 0 .. internal_repeats.max(1) {
// Set up the externalities environment for the setup we want to
// benchmark.
let closure_to_benchmark = <
SelectedBenchmark as $crate::BenchmarkingSetup<$runtime $(, $instance)?>
>::instance(&selected_benchmark, c, verify)?;

let on_before_start = || {
// Set the block number to at least 1 so events are deposited.
if $crate::Zero::is_zero(&frame_system::Pallet::<$runtime>::block_number()) {
frame_system::Pallet::<$runtime>::set_block_number(1u32.into());
Expand All @@ -800,27 +799,25 @@ macro_rules! impl_benchmark {

// Reset the read/write counter so we don't count operations in the setup process.
$crate::benchmarking::reset_read_write_count();
};

// Always do at least one internal repeat...
for _ in 0 .. internal_repeats.max(1) {
// Always reset the state after the benchmark.
$crate::defer!($crate::benchmarking::wipe_db());

// Time the extrinsic logic.
$crate::log::trace!(
target: "benchmark",
"Start Benchmark: {:?}", c
);

let start_pov = $crate::benchmarking::proof_size();
let start_extrinsic = $crate::benchmarking::current_time();

closure_to_benchmark()?;

let finish_extrinsic = $crate::benchmarking::current_time();
let end_pov = $crate::benchmarking::proof_size();
let mut recording = $crate::BenchmarkRecording::new(&on_before_start);
<SelectedBenchmark as $crate::BenchmarkingSetup<$runtime>>::instance(&selected_benchmark, &mut recording, c, verify)?;

// Calculate the diff caused by the benchmark.
let elapsed_extrinsic = finish_extrinsic.saturating_sub(start_extrinsic);
let diff_pov = match (start_pov, end_pov) {
(Some(start), Some(end)) => end.saturating_sub(start),
_ => Default::default(),
};
let elapsed_extrinsic = recording.elapsed_extrinsic().expect("elapsed time should be recorded");
let diff_pov = recording.diff_pov().unwrap_or_default();

// Commit the changes to get proper write count
$crate::benchmarking::commit_db();
Expand Down Expand Up @@ -917,18 +914,16 @@ macro_rules! impl_benchmark_test {
let execute_benchmark = |
c: $crate::Vec<($crate::BenchmarkParameter, u32)>
| -> Result<(), $crate::BenchmarkError> {
// Set up the benchmark, return execution + verification function.
let closure_to_verify = <
SelectedBenchmark as $crate::BenchmarkingSetup<$runtime, _>
>::instance(&selected_benchmark, &c, true)?;

// Set the block number to at least 1 so events are deposited.
if $crate::Zero::is_zero(&frame_system::Pallet::<$runtime>::block_number()) {
frame_system::Pallet::<$runtime>::set_block_number(1u32.into());
}
let on_before_start = || {
// Set the block number to at least 1 so events are deposited.
if $crate::Zero::is_zero(&frame_system::Pallet::<$runtime>::block_number()) {
frame_system::Pallet::<$runtime>::set_block_number(1u32.into());
}
};

// Run execution + verification
closure_to_verify()?;
<SelectedBenchmark as $crate::BenchmarkingSetup<$runtime, _>>::test_instance(&selected_benchmark, &c, &on_before_start)?;

// Reset the state
$crate::benchmarking::wipe_db();
Expand Down Expand Up @@ -1386,7 +1381,6 @@ macro_rules! cb_add_benchmarks {
/// ```
///
/// This should match what exists with the `add_benchmark!` macro.

#[macro_export]
macro_rules! list_benchmark {
( $list:ident, $extra:ident, $name:path, $( $location:tt )* ) => (
Expand Down
72 changes: 30 additions & 42 deletions benchmarking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,79 +127,67 @@ fn benchmarks_macro_works() {
let components = <SelectedBenchmark as BenchmarkingSetup<Test>>::components(&selected_benchmark);
assert_eq!(components, vec![(BenchmarkParameter::b, 1, 1000)]);

let closure = <SelectedBenchmark as BenchmarkingSetup<Test>>::instance(
&selected_benchmark,
&[(BenchmarkParameter::b, 1)],
true,
)
.expect("failed to create closure");

new_test_ext().execute_with(|| {
assert_eq!(closure(), Ok(()));
assert_ok!(<SelectedBenchmark as BenchmarkingSetup<Test>>::unit_test_instance(
&selected_benchmark,
&[(BenchmarkParameter::b, 1)],
));
});
}

#[test]
fn benchmarks_macro_rename_works() {
// Check benchmark creation for `other_dummy`.
let selected_benchmark = SelectedBenchmark::other_name;
let components = <SelectedBenchmark as BenchmarkingSetup<Test>>::components(&selected_benchmark);
let selected = SelectedBenchmark::other_name;
let components = <SelectedBenchmark as BenchmarkingSetup<Test>>::components(&selected);
assert_eq!(components, vec![(BenchmarkParameter::b, 1, 1000)]);

let closure = <SelectedBenchmark as BenchmarkingSetup<Test>>::instance(
&selected_benchmark,
&[(BenchmarkParameter::b, 1)],
true,
)
.expect("failed to create closure");

new_test_ext().execute_with(|| {
assert_ok!(closure());
assert_ok!(<SelectedBenchmark as BenchmarkingSetup<Test>>::unit_test_instance(
&selected,
&[(BenchmarkParameter::b, 1)],
));
});
}

#[test]
fn benchmarks_macro_works_for_non_dispatchable() {
let selected_benchmark = SelectedBenchmark::sort_vector;
let selected = SelectedBenchmark::sort_vector;

let components = <SelectedBenchmark as BenchmarkingSetup<Test>>::components(&selected_benchmark);
let components = <SelectedBenchmark as BenchmarkingSetup<Test>>::components(&selected);
assert_eq!(components, vec![(BenchmarkParameter::x, 1, 10000)]);

let closure = <SelectedBenchmark as BenchmarkingSetup<Test>>::instance(
&selected_benchmark,
&[(BenchmarkParameter::x, 1)],
true,
)
.expect("failed to create closure");

assert_eq!(closure(), Ok(()));
new_test_ext().execute_with(|| {
assert_ok!(<SelectedBenchmark as BenchmarkingSetup<Test>>::unit_test_instance(
&selected,
&[(BenchmarkParameter::x, 1)],
));
});
}

#[test]
fn benchmarks_macro_verify_works() {
// Check postcondition for benchmark `set_value` is valid.
let selected_benchmark = SelectedBenchmark::set_value;

let closure = <SelectedBenchmark as BenchmarkingSetup<Test>>::instance(
&selected_benchmark,
&[(BenchmarkParameter::b, 1)],
true,
)
.expect("failed to create closure");
let selected = SelectedBenchmark::set_value;

new_test_ext().execute_with(|| {
assert_ok!(closure());
assert_ok!(<SelectedBenchmark as BenchmarkingSetup<Test>>::unit_test_instance(
&selected,
&[(BenchmarkParameter::b, 1)],
));
});

// Check postcondition for benchmark `bad_verify` is invalid.
let selected = SelectedBenchmark::bad_verify;

let closure =
<SelectedBenchmark as BenchmarkingSetup<Test>>::instance(&selected, &[(BenchmarkParameter::x, 10000)], true)
.expect("failed to create closure");

new_test_ext().execute_with(|| {
assert_err!(closure(), "You forgot to sort!");
assert_err!(
<SelectedBenchmark as BenchmarkingSetup<Test>>::unit_test_instance(
&selected,
&[(BenchmarkParameter::x, 10000)],
),
"You forgot to sort!"
);
});
}

Expand Down
Loading
Loading