diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index 3fb7dadb1..e62538859 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -20,9 +20,10 @@ jobs: - name: Install toolchain run: ./scripts/init.sh - name: Build Project - if: github.event_name == 'push' - run: cargo build - - run: cargo clean + run: | + cargo clean + cargo build --release --features runtime-benchmarks + cargo build - name: Test Project run: cargo test - name: Run Cargo Trampulin diff --git a/Cargo.lock b/Cargo.lock index eec178bd9..4d1f96e6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3672,6 +3672,7 @@ dependencies = [ "pallet-recovery", "pallet-scheduler", "pallet-session", + "pallet-society", "pallet-staking", "pallet-staking-reward-curve", "pallet-sudo", @@ -4050,6 +4051,7 @@ name = "pallet-bounties" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=master#88c64e06471cc12aa9b25290f24d5566bcb5dd82" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "pallet-treasury", @@ -4063,6 +4065,7 @@ name = "pallet-collective" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=master#88c64e06471cc12aa9b25290f24d5566bcb5dd82" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "log", @@ -4172,11 +4175,13 @@ name = "pallet-election-provider-multi-phase" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=master#88c64e06471cc12aa9b25290f24d5566bcb5dd82" dependencies = [ + "frame-benchmarking", "frame-election-provider-support", "frame-support", "frame-system", "log", "parity-scale-codec", + "rand 0.7.3", "sp-arithmetic", "sp-core", "sp-io", @@ -4184,6 +4189,8 @@ dependencies = [ "sp-runtime", "sp-std", "static_assertions", + "strum 0.21.0", + "strum_macros 0.21.1", ] [[package]] @@ -4191,6 +4198,7 @@ name = "pallet-elections-phragmen" version = "5.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=master#88c64e06471cc12aa9b25290f24d5566bcb5dd82" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "log", @@ -4258,6 +4266,7 @@ name = "pallet-im-online" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=master#88c64e06471cc12aa9b25290f24d5566bcb5dd82" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "log", @@ -4276,6 +4285,7 @@ name = "pallet-indices" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=master#88c64e06471cc12aa9b25290f24d5566bcb5dd82" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "parity-scale-codec", @@ -4352,6 +4362,7 @@ name = "pallet-multisig" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=master#88c64e06471cc12aa9b25290f24d5566bcb5dd82" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "parity-scale-codec", @@ -4381,6 +4392,7 @@ name = "pallet-proxy" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=master#88c64e06471cc12aa9b25290f24d5566bcb5dd82" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "parity-scale-codec", @@ -4468,6 +4480,7 @@ name = "pallet-staking" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=master#88c64e06471cc12aa9b25290f24d5566bcb5dd82" dependencies = [ + "frame-benchmarking", "frame-election-provider-support", "frame-support", "frame-system", @@ -4475,6 +4488,7 @@ dependencies = [ "pallet-authorship", "pallet-session", "parity-scale-codec", + "rand_chacha 0.2.2", "serde", "sp-application-crypto", "sp-io", @@ -4529,6 +4543,7 @@ name = "pallet-tips" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=master#88c64e06471cc12aa9b25290f24d5566bcb5dd82" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "pallet-treasury", @@ -4604,6 +4619,7 @@ name = "pallet-treasury" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=master#88c64e06471cc12aa9b25290f24d5566bcb5dd82" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "impl-trait-for-tuples", @@ -4632,6 +4648,7 @@ name = "pallet-utility" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=master#88c64e06471cc12aa9b25290f24d5566bcb5dd82" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "parity-scale-codec", @@ -4868,6 +4885,7 @@ dependencies = [ "pallet-balances", "pallet-sudo", "parity-scale-codec", + "rand 0.7.3", "sp-core", "sp-io", "sp-runtime", @@ -7485,7 +7503,7 @@ dependencies = [ "lazy_static", "sp-core", "sp-runtime", - "strum", + "strum 0.20.0", ] [[package]] @@ -7891,9 +7909,15 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7318c509b5ba57f18533982607f24070a55d353e90d4cae30c467cdb2ad5ac5c" dependencies = [ - "strum_macros", + "strum_macros 0.20.1", ] +[[package]] +name = "strum" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaf86bbcfd1fa9670b7a129f64fc0c9fcbbfe4f1bc4210e9e98fe71ffc12cde2" + [[package]] name = "strum_macros" version = "0.20.1" @@ -7906,6 +7930,18 @@ dependencies = [ "syn", ] +[[package]] +name = "strum_macros" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d06aaeeee809dbc59eb4556183dd927df67db1540de5be8d3ec0b6636358a5ec" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "substrate-bip39" version = "0.4.4" @@ -8468,7 +8504,7 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f559b464de2e2bdabcac6a210d12e9b5a5973c251e102c44c585c71d51bd78e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if 0.1.10", "rand 0.8.4", "static_assertions", ] diff --git a/pallets/pdex-migration/Cargo.toml b/pallets/pdex-migration/Cargo.toml index a99ac8df7..fcd8b338d 100644 --- a/pallets/pdex-migration/Cargo.toml +++ b/pallets/pdex-migration/Cargo.toml @@ -18,10 +18,12 @@ sp-std = { default-features = false, git = "https://github.com/paritytech/substr frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } pallet-sudo = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master", optional = true } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } +sp-core = { default-features= false, git = "https://github.com/paritytech/substrate", branch = "master" } +rand = { version = "0.7.2", default-features = false } [dev-dependencies] -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } -sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "master"} [features] default = ['std'] @@ -31,6 +33,14 @@ std = [ 'frame-system/std', 'sp-runtime/std', 'pallet-balances/std', - 'pallet-sudo/std' + 'pallet-sudo/std', +] +runtime-benchmarks = [ + "frame-benchmarking", + 'frame-support/runtime-benchmarks', + 'frame-system/runtime-benchmarks', + 'sp-runtime/runtime-benchmarks', + 'pallet-balances/runtime-benchmarks', + # 'sp-io/std', ] -runtime-benchmarks = ["frame-benchmarking"] \ No newline at end of file +try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/pdex-migration/src/benchmarking.rs b/pallets/pdex-migration/src/benchmarking.rs index d8b825dc3..502a6e735 100644 --- a/pallets/pdex-migration/src/benchmarking.rs +++ b/pallets/pdex-migration/src/benchmarking.rs @@ -1,83 +1,124 @@ //! Benchmarking setup for pallet-template -use super::*; - +use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_support::assert_ok; +use frame_support::pallet_prelude::*; +use frame_support::traits::Get; +use frame_system::pallet_prelude::*; use frame_system::RawOrigin; -use frame_benchmarking::{benchmarks, whitelisted_caller, impl_benchmark_test_suite}; -#[allow(unused)] -use crate::Pallet as Template; +use rand::RngCore; +use rand::SeedableRng; +// use frame_system::Origin; +use sp_core::H256; +use sp_runtime::SaturatedConversion; +use sp_runtime::traits::BlockNumberProvider; + +use crate::pallet::{Call, Config, Pallet}; +use crate::pallet::*; +use crate::pallet::Pallet as PDEXMigration; +use super::*; + +// use crate::pallet::Call as PDEXMigration; +// use crate::mock::{ +// // PDEXMigration, +// PDEX +// }; +pub const PDEX: u128 = 1000_000_000_000; benchmarks! { set_migration_operational_status { }: _(RawOrigin::Root, true) set_relayer_status { - let relayer = account("relayer",0,0); + let relayer : T::AccountId = account("relayer",0,0); }: _ (RawOrigin::Root, relayer, true) mint { - let relayer1 = account("relayer1",0,0); - let relayer2 = account("relayer2",0,0); - let relayer3 = account("relayer3",0,0); - let beneficiary = whitelisted_caller(); - assert_ok!(PDEXMigration::set_migration_operational_status(Origin::root(),true)); - // Register relayers - assert_ok!(PDEXMigration::set_relayer_status(Origin::root(),relayer1,true)); - assert_ok!(PDEXMigration::set_relayer_status(Origin::root(),relayer2,true)); - assert_ok!(PDEXMigration::set_relayer_status(Origin::root(),relayer3,true)); - - assert_ok!(PDEXMigration::mint(Origin::signed(relayer1), beneficiary,100*PDEX,H256::zero())); - assert_ok!(PDEXMigration::mint(Origin::signed(relayer2), beneficiary,100*PDEX,H256::zero())); - - let beneficiary: T::AccountId = whitelisted_caller(); - let eth_hash: T::Hash = T::Hash::default(); + let relayer1: T::AccountId = account("relayer1",0,0); + let relayer2: T::AccountId = account("relayer2",0,0); let relayer3: T::AccountId = account("relayer3",0,0); - let amount: T::Balance = ::ExistentialDeposit::get().saturating_mul(100u32.into()); - }: _(RawOrigin::Signed(relayer3),beneficiary,amount,eth_hash) + let beneficiary: T::AccountId = whitelisted_caller(); + let amount: T::Balance = 100u128.saturating_mul(PDEX).saturated_into(); + let mut random_slice = [0u8; 32]; + let mut rng = rand::rngs::StdRng::seed_from_u64(5 as u64); + rng.fill_bytes(&mut random_slice); + let mut eth_hash: T::Hash = T::Hash::default(); + eth_hash.as_mut().copy_from_slice(&random_slice); + + + assert_ok!(PDEXMigration::::set_migration_operational_status(RawOrigin::Root.into(),true)); + // Register relayers + assert_ok!(PDEXMigration::::set_relayer_status(RawOrigin::Root.into(),relayer1.clone(),true)); + assert_ok!(PDEXMigration::::set_relayer_status(RawOrigin::Root.into(),relayer2.clone(),true)); + assert_ok!(PDEXMigration::::set_relayer_status(RawOrigin::Root.into(),relayer3.clone(),true)); + + assert_ok!(PDEXMigration::::mint(RawOrigin::Signed(relayer1).into(), beneficiary.clone(),amount,eth_hash)); + assert_ok!(PDEXMigration::::mint(RawOrigin::Signed(relayer2).into(), beneficiary.clone(),amount,eth_hash)); + + }: _(RawOrigin::Signed(relayer3),beneficiary,amount,eth_hash.into()) unlock { - let relayer1 = account("relayer1",0,0); - let relayer2 = account("relayer2",0,0); - let relayer3 = account("relayer3",0,0); - let beneficiary = whitelisted_caller(); - assert_ok!(PDEXMigration::set_migration_operational_status(Origin::root(),true)); - // Register relayers - assert_ok!(PDEXMigration::set_relayer_status(Origin::root(),relayer1,true)); - assert_ok!(PDEXMigration::set_relayer_status(Origin::root(),relayer2,true)); - assert_ok!(PDEXMigration::set_relayer_status(Origin::root(),relayer3,true)); - - assert_ok!(PDEXMigration::mint(Origin::signed(relayer1), beneficiary,100*PDEX,H256::zero())); - assert_ok!(PDEXMigration::mint(Origin::signed(relayer2), beneficiary,100*PDEX,H256::zero())); - assert_ok!(PDEXMigration::mint(Origin::signed(relayer3), beneficiary,100*PDEX,H256::zero())); + let relayer1 : T::AccountId = account("relayer1",0,0); + let relayer2 : T::AccountId = account("relayer2",0,0); + let relayer3 : T::AccountId = account("relayer3",0,0); + let beneficiary : T::AccountId = whitelisted_caller(); + + let amount: T::Balance = 100u128.saturating_mul(PDEX).saturated_into(); + let mut random_slice = [0u8; 32]; + let mut rng = rand::rngs::StdRng::seed_from_u64(5 as u64); + rng.fill_bytes(&mut random_slice); + let mut eth_hash: T::Hash = T::Hash::default(); + eth_hash.as_mut().copy_from_slice(&random_slice); + + assert_ok!(PDEXMigration::::set_migration_operational_status(RawOrigin::Root.into(),true)); + // Register relayers + assert_ok!(PDEXMigration::::set_relayer_status(RawOrigin::Root.into(),relayer1.clone(),true)); + assert_ok!(PDEXMigration::::set_relayer_status(RawOrigin::Root.into(),relayer2.clone(),true)); + assert_ok!(PDEXMigration::::set_relayer_status(RawOrigin::Root.into(),relayer3.clone(),true)); + + assert_ok!(PDEXMigration::::mint(RawOrigin::Signed(relayer1).into(), beneficiary.clone(),amount,eth_hash)); + assert_ok!(PDEXMigration::::mint(RawOrigin::Signed(relayer2).into(), beneficiary.clone(),amount,eth_hash)); + assert_ok!(PDEXMigration::::mint(RawOrigin::Signed(relayer3).into(), beneficiary.clone(),amount,eth_hash)); frame_system::Pallet::::set_block_number(frame_system::Pallet::::current_block_number()+T::LockPeriod::get()); - let beneficiary: T::AccountId = whitelisted_caller(); }: _(RawOrigin::Signed(beneficiary)) remove_minted_tokens { - let relayer1 = account("relayer1",0,0); - let relayer2 = account("relayer2",0,0); - let relayer3 = account("relayer3",0,0); - let beneficiary = whitelisted_caller(); - assert_ok!(PDEXMigration::set_migration_operational_status(Origin::root(),true)); - // Register relayers - assert_ok!(PDEXMigration::set_relayer_status(Origin::root(),relayer1,true)); - assert_ok!(PDEXMigration::set_relayer_status(Origin::root(),relayer2,true)); - assert_ok!(PDEXMigration::set_relayer_status(Origin::root(),relayer3,true)); - - assert_ok!(PDEXMigration::mint(Origin::signed(relayer1), beneficiary,100*PDEX,H256::zero())); - assert_ok!(PDEXMigration::mint(Origin::signed(relayer2), beneficiary,100*PDEX,H256::zero())); - assert_ok!(PDEXMigration::mint(Origin::signed(relayer3), beneficiary,100*PDEX,H256::zero())); - - let beneficiary: T::AccountId = whitelisted_caller(); + let relayer1: T::AccountId = account("relayer1",0,0); + let relayer2 : T::AccountId = account("relayer2",0,0); + let relayer3 : T::AccountId = account("relayer3",0,0); + let beneficiary: T::AccountId = whitelisted_caller(); + let amount: T::Balance = 100u128.saturating_mul(PDEX).saturated_into(); + let mut random_slice = [0u8; 32]; + let mut rng = rand::rngs::StdRng::seed_from_u64(5 as u64); + rng.fill_bytes(&mut random_slice); + let mut eth_hash: T::Hash = T::Hash::default(); + eth_hash.as_mut().copy_from_slice(&random_slice); + + assert_ok!(PDEXMigration::::set_migration_operational_status(RawOrigin::Root.into(),true)); + // Register relayers + assert_ok!(PDEXMigration::::set_relayer_status(RawOrigin::Root.into(),relayer1.clone(),true)); + assert_ok!(PDEXMigration::::set_relayer_status(RawOrigin::Root.into(),relayer2.clone(),true)); + assert_ok!(PDEXMigration::::set_relayer_status(RawOrigin::Root.into(),relayer3.clone(),true)); + + assert_ok!(PDEXMigration::::mint(RawOrigin::Signed(relayer1).into(), beneficiary.clone(),amount,eth_hash)); + assert_ok!(PDEXMigration::::mint(RawOrigin::Signed(relayer2).into(), beneficiary.clone(),amount,eth_hash)); + assert_ok!(PDEXMigration::::mint(RawOrigin::Signed(relayer3).into(), beneficiary.clone(),amount,eth_hash)); + }: _(RawOrigin::Root,beneficiary) } - -impl_benchmark_test_suite!( - Template, - crate::mock::new_test_ext(), - crate::mock::Test, -); +#[cfg(test)] +mod tests { + use crate::mock::*; + + use super::*; + + impl_benchmark_test_suite!( + Template, + crate::mock::new_test_ext(), + crate::mock::Test, + ); +} \ No newline at end of file diff --git a/pallets/pdex-migration/src/lib.rs b/pallets/pdex-migration/src/lib.rs index 0d33c9cb4..9ce0fd09e 100644 --- a/pallets/pdex-migration/src/lib.rs +++ b/pallets/pdex-migration/src/lib.rs @@ -1,8 +1,20 @@ #![cfg_attr(not(feature = "std"), no_std)] +#![allow(clippy::unused_unit)] + +use crate::pallet as pdex_migration; +use frame_support::weights::Weight; + +pub mod weights; + +/// Weight functions needed for pdex_migration. +pub trait WeightInfo { + fn set_migration_operational_status() -> Weight; + fn set_relayer_status() -> Weight; + fn mint() -> Weight; + fn unlock() -> Weight; + fn remove_minted_tokens() -> Weight; +} -/// Edit this file to define custom logic or remove it if it is not needed. -/// Learn more about FRAME and the core library of Substrate FRAME pallets: -/// #[cfg(test)] mod mock; @@ -12,7 +24,6 @@ mod tests; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; - #[frame_support::pallet] pub mod pallet { use codec::{Decode, Encode}; @@ -24,6 +35,8 @@ pub mod pallet { use sp_runtime::traits::{BlockNumberProvider, Zero}; use sp_std::vec::Vec; use sp_std::vec; + use sp_core::H256; + use crate::WeightInfo; const MIGRATION_LOCK: frame_support::traits::LockIdentifier = *b"pdexlock"; @@ -49,7 +62,7 @@ pub mod pallet { #[pallet::constant] type LockPeriod: Get<::BlockNumber>; /// Weight Info for PDEX migration - type WeightInfo; + type WeightInfo: WeightInfo; } #[pallet::pallet] @@ -142,14 +155,14 @@ pub mod pallet { // Dispatchable functions must be annotated with a weight and must return a DispatchResult. #[pallet::call] impl Pallet { - #[pallet::weight(10000)] + #[pallet::weight(::WeightInfo::set_migration_operational_status())] pub fn set_migration_operational_status(origin: OriginFor, status: bool) -> DispatchResultWithPostInfo { ensure_root(origin)?; Operational::::put(status); Ok(Pays::No.into()) } - #[pallet::weight(10000)] + #[pallet::weight(::WeightInfo::set_relayer_status())] pub fn set_relayer_status(origin: OriginFor, relayer: T::AccountId, status: bool) -> DispatchResultWithPostInfo { ensure_root(origin)?; Relayers::::insert(&relayer, status); @@ -157,7 +170,7 @@ pub mod pallet { Ok(Pays::No.into()) } - #[pallet::weight(10000)] + #[pallet::weight(::WeightInfo::mint())] pub fn mint(origin: OriginFor, beneficiary: T::AccountId, amount: T::Balance, eth_tx: T::Hash) -> DispatchResultWithPostInfo { let relayer = ensure_signed(origin)?; ensure!(eth_tx != T::Hash::default(), Error::::InvalidTxHash); @@ -171,7 +184,7 @@ pub mod pallet { } } - #[pallet::weight(10000)] + #[pallet::weight(::WeightInfo::unlock())] pub fn unlock(origin: OriginFor) -> DispatchResultWithPostInfo { let beneficiary = ensure_signed(origin)?; if Self::operational() { @@ -181,8 +194,7 @@ pub mod pallet { Err(Error::::NotOperational)? } } - - #[pallet::weight(10000)] + #[pallet::weight(::WeightInfo::remove_minted_tokens())] pub fn remove_minted_tokens(origin: OriginFor, beneficiary: T::AccountId) -> DispatchResultWithPostInfo { ensure_root(origin)?; Self::remove_fradulent_tokens(beneficiary)?; @@ -273,3 +285,4 @@ pub mod pallet { } } } + diff --git a/pallets/pdex-migration/src/mock.rs b/pallets/pdex-migration/src/mock.rs index a15b9d7e9..b7ffdb8c8 100644 --- a/pallets/pdex-migration/src/mock.rs +++ b/pallets/pdex-migration/src/mock.rs @@ -1,6 +1,8 @@ use frame_support::parameter_types; use frame_system as system; use sp_core::H256; +// use sp_runtime::testing::H256; +// use crate::benchmarking::H256; use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, @@ -9,11 +11,9 @@ use sp_runtime::{ use crate::pallet as pdex_migration; use frame_support::traits::GenesisBuild; - type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; type Balance = u128; - // Configure a mock runtime to test the pallet. frame_support::construct_runtime!( pub enum Test where @@ -27,12 +27,10 @@ frame_support::construct_runtime!( PDEXMigration: pdex_migration::{Pallet, Call, Config, Storage, Event}, } ); - parameter_types! { pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 42; } - impl system::Config for Test { type BaseCallFilter = frame_support::traits::Everything; type BlockWeights = (); @@ -59,12 +57,12 @@ impl system::Config for Test { type OnSetCode = (); } pub const PDEX: Balance = 1000_000_000_000; + parameter_types! { pub const ExistentialDeposit: Balance = 1 * PDEX; pub const MaxLocks: u32 = 50; pub const MaxReserves: u32 = 50; } - impl pallet_balances::Config for Test { type Balance = Balance; type DustRemoval = (); @@ -76,17 +74,15 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type WeightInfo = (); } - parameter_types! { pub const LockPeriod: u64 = 201600; } - impl pdex_migration::Config for Test { type Event = Event; type LockPeriod = LockPeriod; - type WeightInfo = (); -} + type WeightInfo = crate::weights::WeightInfo; +} impl pallet_sudo::Config for Test { type Event = Event; type Call = Call; diff --git a/pallets/pdex-migration/src/weights.rs b/pallets/pdex-migration/src/weights.rs new file mode 100644 index 000000000..777cd8b9b --- /dev/null +++ b/pallets/pdex-migration/src/weights.rs @@ -0,0 +1,73 @@ + +//! Autogenerated weights for `pdex_migration` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-09-26, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 + +// Executed Command: +// ./target/release/polkadex-node +// benchmark +// --chain +// dev +// --execution +// wasm +// --wasm-execution +// compiled +// --pallet=pdex_migration +// --extrinsic=* +// --steps +// 50 +// --repeat +// 20 +// --output=benchout/pdex_migration.rs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for pdex_migration. +pub struct WeightInfo(PhantomData); +impl crate::WeightInfo for WeightInfo { + // Storage: PDEXMigration Operational (r:0 w:1) + fn set_migration_operational_status() -> Weight { + (1_000_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: PDEXMigration Relayers (r:0 w:1) + fn set_relayer_status() -> Weight { + (14_000_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: PDEXMigration Operational (r:1 w:0) + // Storage: PDEXMigration EthTxns (r:1 w:1) + // Storage: PDEXMigration Relayers (r:1 w:0) + // Storage: PDEXMigration MintableTokens (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: PDEXMigration LockedTokenHolders (r:0 w:1) + fn mint() -> Weight { + (70_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + // Storage: PDEXMigration Operational (r:1 w:0) + // Storage: PDEXMigration LockedTokenHolders (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + fn unlock() -> Weight { + (30_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: PDEXMigration LockedTokenHolders (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: PDEXMigration MintableTokens (r:1 w:1) + fn remove_minted_tokens() -> Weight { + (56_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } +} diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 64d8027d2..2196fd8c2 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -60,6 +60,8 @@ sp-session = { default-features = false, git = "https://github.com/paritytech/su sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } sp-transaction-pool = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features =false} + #added sp-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" } @@ -78,6 +80,7 @@ frame-system-rpc-runtime-api = { default-features = false, git = "https://github # Used for runtime benchmarking frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master", optional = true } frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master", optional = true } +pallet-society = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master", optional = true } # ORML Pallets @@ -91,7 +94,10 @@ pdex-migration = { path = "../pallets/pdex-migration", default-features = false substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "master" } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" } +# sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } +# pallet-society = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master", optional = true } +pallet-society = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master"} [features] @@ -154,10 +160,30 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system-benchmarking", "frame-system/runtime-benchmarks", - "hex-literal", + "pallet-election-provider-multi-phase/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "pallet-babe/runtime-benchmarks", "pallet-balances/runtime-benchmarks", + "pallet-bounties/runtime-benchmarks", + "pallet-collective/runtime-benchmarks", + "pallet-elections-phragmen/runtime-benchmarks", + "pallet-grandpa/runtime-benchmarks", + "pallet-identity/runtime-benchmarks", + "pallet-im-online/runtime-benchmarks", + "pallet-indices/runtime-benchmarks", + "pallet-membership/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", + 'pallet-society/runtime-benchmarks', + "pallet-staking/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", + "pallet-tips/runtime-benchmarks", + "pallet-treasury/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", + "frame-system-benchmarking", + "orml-vesting/runtime-benchmarks", + "hex-literal", "frame-election-provider-support/runtime-benchmarks", "pdex-migration/runtime-benchmarks" ] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a90e92662..b4e8b2afb 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -972,7 +972,7 @@ parameter_types! { impl pdex_migration::pallet::Config for Runtime { type Event = Event; type LockPeriod = LockPeriod; - type WeightInfo = (); + type WeightInfo = weights::pdex_migration::WeightInfo; } construct_runtime!( @@ -1003,15 +1003,15 @@ construct_runtime!( AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config} = 19, Offences: pallet_offences::{Pallet, Storage, Event} = 20, Historical: pallet_session_historical::{Pallet} = 21, - Identity: pallet_identity::{Pallet, Call, Storage, Event} = 23, - Recovery: pallet_recovery::{Pallet, Call, Storage, Event} = 24, - Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event} = 25, - Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 26, - Multisig: pallet_multisig::{Pallet, Call, Storage, Event} = 27, - Bounties: pallet_bounties::{Pallet, Call, Storage, Event} = 28, + Identity: pallet_identity::{Pallet, Call, Storage, Event} = 22, + Recovery: pallet_recovery::{Pallet, Call, Storage, Event} = 23, + Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event} = 24, + Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 25, + Multisig: pallet_multisig::{Pallet, Call, Storage, Event} = 26, + Bounties: pallet_bounties::{Pallet, Call, Storage, Event} = 27, // Pallets - OrmlVesting: orml_vesting::{Pallet, Storage, Call, Event, Config} = 29, - PDEXMigration: pdex_migration::pallet::{Pallet, Storage, Call, Event, Config} = 30, + OrmlVesting: orml_vesting::{Pallet, Storage, Call, Event, Config} = 28, + PDEXMigration: pdex_migration::pallet::{Pallet, Storage, Call, Event, Config} = 29, } ); /// Digest item type. @@ -1247,6 +1247,43 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { + fn benchmark_metadata(extra: bool) -> ( + Vec, + Vec) { + use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList}; + use frame_support::traits::StorageInfoTrait; + + // Trying to add benchmarks directly to the Session Pallet caused cyclic dependency + // issues. To get around that, we separated the Session benchmarks into its own crate, + // which is why we need these two lines below. + + let mut list = Vec::::new(); + + list_benchmark!(list,extra, pallet_babe, Babe); + list_benchmark!(list,extra, pallet_balances, Balances); + list_benchmark!(list,extra, pallet_bounties, Bounties); + list_benchmark!(list,extra, pallet_collective, Council); + list_benchmark!(list,extra, pallet_elections_phragmen, Elections); + list_benchmark!(list,extra, pallet_grandpa, Grandpa); + list_benchmark!(list,extra, pallet_identity, Identity); + list_benchmark!(list,extra, pallet_im_online, ImOnline); + list_benchmark!(list,extra, pallet_indices, Indices); + list_benchmark!(list,extra, pallet_membership, TechnicalMembership); + list_benchmark!(list,extra, pallet_multisig, Multisig); + list_benchmark!(list,extra, pallet_proxy, Proxy); + list_benchmark!(list,extra, pallet_scheduler, Scheduler); + list_benchmark!(list, extra, pallet_staking, Staking); + list_benchmark!(list,extra, pallet_timestamp, Timestamp); + list_benchmark!(list,extra, pallet_treasury, Treasury); + list_benchmark!(list,extra, pallet_utility, Utility); + + list_benchmark!(list,extra, pallet_election_provider_multi_phase, ElectionProviderMultiPhase); + list_benchmark!(list,extra, pdex_migration, PDEXMigration); + + let storage_info = AllPalletsWithSystem::storage_info(); + + return (list, storage_info) + } fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig ) -> Result, sp_runtime::RuntimeString> { @@ -1254,12 +1291,12 @@ impl_runtime_apis! { // Trying to add benchmarks directly to the Session Pallet caused cyclic dependency // issues. To get around that, we separated the Session benchmarks into its own crate, // which is why we need these two lines below. - use pallet_session_benchmarking::Pallet as SessionBench; - use pallet_offences_benchmarking::Pallet as OffencesBench; + // use pallet_session_benchmarking::Pallet as SessionBench; + // use pallet_offences_benchmarking::Pallet as OffencesBench; use frame_system_benchmarking::Pallet as SystemBench; - impl pallet_session_benchmarking::Config for Runtime {} - impl pallet_offences_benchmarking::Config for Runtime {} + // impl pallet_session_benchmarking::Config for Runtime {} + // impl pallet_offences_benchmarking::Config for Runtime {} impl frame_system_benchmarking::Config for Runtime {} let whitelist: Vec = vec![ @@ -1292,10 +1329,10 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_indices, Indices); add_benchmark!(params, batches, pallet_membership, TechnicalMembership); add_benchmark!(params, batches, pallet_multisig, Multisig); - add_benchmark!(params, batches, pallet_offences, OffencesBench::); + // add_benchmark!(params, batches, pallet_offences, OffencesBench::); add_benchmark!(params, batches, pallet_proxy, Proxy); add_benchmark!(params, batches, pallet_scheduler, Scheduler); - add_benchmark!(params, batches, pallet_session, SessionBench::); + // add_benchmark!(params, batches, pallet_session, SessionBench::); add_benchmark!(params, batches, pallet_staking, Staking); add_benchmark!(params, batches, frame_system, SystemBench::); add_benchmark!(params, batches, pallet_timestamp, Timestamp); diff --git a/runtime/src/weights/mod.rs b/runtime/src/weights/mod.rs index b6030c675..2527c7a59 100644 --- a/runtime/src/weights/mod.rs +++ b/runtime/src/weights/mod.rs @@ -34,4 +34,5 @@ pub mod pallet_staking; pub mod pallet_timestamp; pub mod pallet_treasury; pub mod pallet_utility; -pub mod pallet_election_provider_multi_phase; \ No newline at end of file +pub mod pallet_election_provider_multi_phase; +pub mod pdex_migration; \ No newline at end of file diff --git a/runtime/src/weights/pdex_migration.rs b/runtime/src/weights/pdex_migration.rs new file mode 100644 index 000000000..34c62583d --- /dev/null +++ b/runtime/src/weights/pdex_migration.rs @@ -0,0 +1,73 @@ + +//! Autogenerated weights for `pdex_migration` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-09-26, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 + +// Executed Command: +// ./target/release/polkadex-node +// benchmark +// --chain +// dev +// --execution +// wasm +// --wasm-execution +// compiled +// --pallet=pdex_migration +// --extrinsic=* +// --steps +// 50 +// --repeat +// 20 +// --output=benchout/pdex_migration.rs + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for pdex_migration. +pub struct WeightInfo(PhantomData); +impl pdex_migration::WeightInfo for WeightInfo { + // Storage: PDEXMigration Operational (r:0 w:1) + fn set_migration_operational_status() -> Weight { + (1_727_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: PDEXMigration Relayers (r:0 w:1) + fn set_relayer_status() -> Weight { + (13_231_000 as Weight) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: PDEXMigration Operational (r:1 w:0) + // Storage: PDEXMigration EthTxns (r:1 w:1) + // Storage: PDEXMigration Relayers (r:1 w:0) + // Storage: PDEXMigration MintableTokens (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: PDEXMigration LockedTokenHolders (r:0 w:1) + fn mint() -> Weight { + (69_169_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + // Storage: PDEXMigration Operational (r:1 w:0) + // Storage: PDEXMigration LockedTokenHolders (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + fn unlock() -> Weight { + (28_553_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: PDEXMigration LockedTokenHolders (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: PDEXMigration MintableTokens (r:1 w:1) + fn remove_minted_tokens() -> Weight { + (54_981_000 as Weight) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } +} diff --git a/scripts/benchmark.sh b/scripts/benchmark.sh new file mode 100755 index 000000000..c220c4162 --- /dev/null +++ b/scripts/benchmark.sh @@ -0,0 +1,19 @@ +#!/bin/bash -e +cargo build --release --features runtime-benchmarks +./target/release/polkadex-node benchmark --chain dev --list + + +install -d benchout +for i in `./target/release/polkadex-node benchmark --chain dev --list | sed s/,.*// |sort |uniq` ; do + echo Try $i + echo ./target/release/polkadex-node benchmark \ + --chain dev \ + --execution wasm \ + --wasm-execution compiled \ + --pallet=$i \ + --extrinsic="*" \ + --steps 50 \ + --repeat 20 \ + --output=benchout/$i.rs +done +# --template=templates/orml-weight-template.hbs \