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

Migrate pallet-benchmarking and pallet-benchmarking-pov to use umbrella crate #7196

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 1 addition & 4 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions substrate/frame/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ sp-session = { optional = true, workspace = true }
sp-storage = { optional = true, workspace = true }
sp-transaction-pool = { optional = true, workspace = true }
sp-version = { optional = true, workspace = true }
sp-application-crypto = { optional = true, workspace = true }


frame-executive = { optional = true, workspace = true }
frame-system-rpc-runtime-api = { optional = true, workspace = true }
Expand Down Expand Up @@ -83,6 +85,7 @@ runtime = [
"sp-storage",
"sp-transaction-pool",
"sp-version",
"sp-application-crypto",
]
std = [
"codec/std",
Expand Down Expand Up @@ -111,6 +114,7 @@ std = [
"sp-storage/std",
"sp-transaction-pool?/std",
"sp-version?/std",
"sp-application-crypto/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
23 changes: 4 additions & 19 deletions substrate/frame/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,16 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { workspace = true }
frame-support = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"]}
# frame-support = { workspace = true }
frame-support-procedural = { workspace = true }
frame-system = { workspace = true }
# frame-system = { workspace = true }
linregress = { optional = true, workspace = true }
log = { workspace = true }
paste = { workspace = true, default-features = true }
scale-info = { features = ["derive"], workspace = true }
serde = { optional = true, workspace = true, default-features = true }
sp-api = { workspace = true }
sp-application-crypto = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-runtime-interface = { workspace = true }
sp-storage = { workspace = true }
static_assertions = { workspace = true, default-features = true }

[dev-dependencies]
Expand All @@ -46,27 +41,17 @@ sp-state-machine = { workspace = true }
default = ["std"]
std = [
"codec/std",
"frame/std",
"frame-support-procedural/std",
"frame-support/std",
"frame-system/std",
"linregress",
"log/std",
"scale-info/std",
"serde",
"sp-api/std",
"sp-application-crypto/std",
"sp-core/std",
"sp-externalities/std",
"sp-io/std",
"sp-keystore/std",
"sp-runtime-interface/std",
"sp-runtime/std",
"sp-state-machine/std",
"sp-storage/std",
]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sc-client-db/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
17 changes: 3 additions & 14 deletions substrate/frame/benchmarking/pov/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,20 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { workspace = true }
frame-benchmarking = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"]}
scale-info = { features = ["derive"], workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-io/std",
"sp-runtime/std",
"frame/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
"frame/try-runtime",
]
13 changes: 5 additions & 8 deletions substrate/frame/benchmarking/pov/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@

use super::*;

use frame_benchmarking::v2::*;
use frame_support::traits::UnfilteredDispatchable;
use frame_system::{Pallet as System, RawOrigin};
use sp_runtime::traits::Hash;
use frame::benchmarking::prelude::*;

#[cfg(feature = "std")]
frame_support::parameter_types! {
parameter_types! {
pub static StorageRootHash: Option<alloc::vec::Vec<u8>> = None;
}

Expand Down Expand Up @@ -113,7 +110,7 @@ mod benchmarks {
// Assume there are 16-256 other storage items.
(0..(1u32 << 4)).for_each(|i| {
let k = T::Hashing::hash(&i.to_be_bytes());
frame_support::storage::unhashed::put(k.as_ref(), &i);
unhashed::put(k.as_ref(), &i);
});

#[block]
Expand All @@ -128,7 +125,7 @@ mod benchmarks {
// Assume there are 256-4096 other storage items.
(0..(1u32 << 8)).for_each(|i| {
let k = T::Hashing::hash(&i.to_be_bytes());
frame_support::storage::unhashed::put(k.as_ref(), &i);
unhashed::put(k.as_ref(), &i);
});

#[block]
Expand All @@ -143,7 +140,7 @@ mod benchmarks {
// Assume there are 4096-65536 other storage items.
(0..(1u32 << 12)).for_each(|i| {
let k = T::Hashing::hash(&i.to_be_bytes());
frame_support::storage::unhashed::put(k.as_ref(), &i);
unhashed::put(k.as_ref(), &i);
});

#[block]
Expand Down
5 changes: 2 additions & 3 deletions substrate/frame/benchmarking/pov/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ mod tests;
mod weights;

extern crate alloc;
use frame::prelude::*;

pub use pallet::*;

#[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use alloc::vec::Vec;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

#[pallet::pallet]
pub struct Pallet<T>(_);
Expand Down
9 changes: 5 additions & 4 deletions substrate/frame/benchmarking/pov/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#![cfg(test)]

use super::weights::WeightInfo;
use frame::testing_prelude::*;

use mock::Test as T;
type W = crate::weights::SubstrateWeight<T>;

Expand Down Expand Up @@ -162,12 +164,11 @@ fn noop_is_free() {
}

mod mock {
use frame_support::derive_impl;
use sp_runtime::testing::H256;
// use sp_runtime::testing::H256;

type Block = frame_system::mocking::MockBlock<Test>;
type Block = MockBlock<Test>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/benchmarking/pov/src/weights.rs

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

17 changes: 6 additions & 11 deletions substrate/frame/benchmarking/src/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@

use crate::benchmarks;
use alloc::{vec, vec::Vec};
use frame_system::Pallet as System;
use sp_runtime::{
traits::{AppVerify, Hash},
RuntimeAppPublic,
};
use frame::testing_prelude::*;

mod crypto {
use sp_application_crypto::{app_crypto, sr25519, KeyTypeId};
use frame::deps::sp_application_crypto::{app_crypto, sr25519, KeyTypeId};

pub const TEST_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"test");
app_crypto!(sr25519, TEST_KEY_TYPE_ID);
Expand Down Expand Up @@ -110,15 +106,14 @@ benchmarks! {

#[cfg(test)]
pub mod mock {
use frame_support::derive_impl;
use sp_runtime::{testing::H256, BuildStorage};

type AccountId = u64;
type Nonce = u32;

type Block = frame_system::mocking::MockBlock<Test>;
type Block = MockBlock<Test>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down Expand Up @@ -149,12 +144,12 @@ pub mod mock {
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type MaxConsumers = ConstU32<16>;
}

impl super::Config for Test {}

pub fn new_test_ext() -> sp_io::TestExternalities {
pub fn new_test_ext() -> TestState {
use sp_keystore::{testing::MemoryKeystore, KeystoreExt};

let t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
Expand Down
13 changes: 5 additions & 8 deletions substrate/frame/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@ pub mod v1;
pub mod __private {
pub use alloc::{boxed::Box, str, vec, vec::Vec};
pub use codec;
pub use frame_support::{storage, traits};
pub use frame::deps::{sp_core::defer, sp_io::storage::root as storage_root};
pub use log;
pub use paste;
pub use sp_core::defer;
pub use sp_io::storage::root as storage_root;
pub use sp_runtime::{traits::Zero, StateVersion};
pub use sp_storage::{well_known_keys, TrackedStorageKey};
pub use frame::deps::sp_storage::{well_known_keys, TrackedStorageKey};
}

#[cfg(feature = "std")]
Expand All @@ -72,7 +69,7 @@ pub use v1::*;
/// #![cfg(feature = "runtime-benchmarks")]
///
/// use super::{mock_helpers::*, Pallet as MyPallet};
/// use frame_benchmarking::v2::*;
/// use frame::benchmarking::prelude::*;
///
/// #[benchmarks]
/// mod benchmarks {
Expand Down Expand Up @@ -283,7 +280,7 @@ pub use v1::*;
/// #![cfg(feature = "runtime-benchmarks")]
///
/// use super::{mock_helpers::*, Pallet as MyPallet};
/// use frame_benchmarking::v2::*;
/// use frame::benchmarking::prelude::*;
///
/// #[benchmarks]
/// mod benchmarks {
Expand Down Expand Up @@ -344,7 +341,7 @@ pub use v1::*;
/// ```ignore
/// #![cfg(feature = "runtime-benchmarks")]
///
/// use frame_benchmarking::v1::*;
/// use frame::benchmarking::prelude::*;
///
/// benchmarks! {
///
Expand Down
19 changes: 5 additions & 14 deletions substrate/frame/benchmarking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,11 @@

#![cfg(test)]

use frame_support::{derive_impl, parameter_types, traits::ConstU32};
use sp_runtime::{
testing::H256,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
use frame::testing_prelude::*;
use std::cell::RefCell;

#[frame_support::pallet(dev_mode)]
#[frame::pallet(dev_mode)]
mod pallet_test {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

#[pallet::pallet]
pub struct Pallet<T>(_);
Expand Down Expand Up @@ -64,9 +57,9 @@ mod pallet_test {
}
}

type Block = frame_system::mocking::MockBlock<Test>;
type Block = MockBlock<Test>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down Expand Up @@ -111,7 +104,7 @@ impl pallet_test::Config for Test {
type MaybeItem = MaybeItem;
}

fn new_test_ext() -> sp_io::TestExternalities {
fn new_test_ext() -> TestState {
RuntimeGenesisConfig::default().build_storage().unwrap().into()
}

Expand All @@ -126,8 +119,6 @@ thread_local! {
mod benchmarks {
use super::{new_test_ext, pallet_test::Value, Test, VALUES_PER_COMPONENT};
use crate::{account, BenchmarkError, BenchmarkParameter, BenchmarkResult, BenchmarkingSetup};
use frame_support::{assert_err, assert_ok, ensure, traits::Get};
use frame_system::RawOrigin;
use rusty_fork::rusty_fork_test;

// Additional used internally by the benchmark macro.
Expand Down
13 changes: 3 additions & 10 deletions substrate/frame/benchmarking/src/tests_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,10 @@

#![cfg(test)]

use frame_support::{derive_impl, traits::ConstU32};
use sp_runtime::{
testing::H256,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};

#[frame_support::pallet]
use frame::testing_prelude::*;

#[frame::pallet]
mod pallet_test {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

#[pallet::pallet]
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
Expand Down
Loading
Loading