diff --git a/Cargo.lock b/Cargo.lock index 28b06ba2b89f8279ade25506acfbe10ef54e3c82..085c7339e68cb32e2991f83b16a990021bd945f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -855,24 +855,34 @@ name = "common-runtime" version = "0.8.0-dev" dependencies = [ "duniter-primitives", + "frame-benchmarking", "frame-support", "frame-system", + "frame-system-benchmarking", "log", "pallet-authority-members", "pallet-babe", + "pallet-balances", "pallet-certification", "pallet-duniter-account", "pallet-duniter-wot", "pallet-grandpa", "pallet-identity", "pallet-membership", + "pallet-multisig", "pallet-provide-randomness", + "pallet-proxy", + "pallet-scheduler", "pallet-session", + "pallet-timestamp", "pallet-treasury", "pallet-ud-accounts-storage", + "pallet-universal-dividend", + "pallet-upgrade-origin", "parity-scale-codec", "scale-info", "serde", + "serde_derive", "smallvec", "sp-arithmetic", "sp-consensus-babe", @@ -2326,6 +2336,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", + "serde_derive", "sp-api", "sp-arithmetic", "sp-authority-discovery", @@ -5049,6 +5060,7 @@ name = "pallet-im-online" version = "4.0.0-dev" source = "git+https://github.com/librelois/substrate.git?branch=duniter-monthly-2022-02#80f060dfad0363af03dbecbe39c6fa9b99042acc" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "log", @@ -5086,6 +5098,7 @@ name = "pallet-multisig" version = "4.0.0-dev" source = "git+https://github.com/librelois/substrate.git?branch=duniter-monthly-2022-02#80f060dfad0363af03dbecbe39c6fa9b99042acc" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "parity-scale-codec", @@ -5106,6 +5119,7 @@ dependencies = [ "pallet-balances", "parity-scale-codec", "scale-info", + "serde", "sp-runtime", "sp-staking", "sp-std", @@ -5147,6 +5161,7 @@ name = "pallet-proxy" version = "4.0.0-dev" source = "git+https://github.com/librelois/substrate.git?branch=duniter-monthly-2022-02#80f060dfad0363af03dbecbe39c6fa9b99042acc" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "parity-scale-codec", @@ -5161,6 +5176,7 @@ name = "pallet-scheduler" version = "4.0.0-dev" source = "git+https://github.com/librelois/substrate.git?branch=duniter-monthly-2022-02#80f060dfad0363af03dbecbe39c6fa9b99042acc" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "log", @@ -5218,6 +5234,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-inherents", + "sp-io", "sp-runtime", "sp-std", "sp-timestamp", @@ -5339,6 +5356,7 @@ name = "pallet-utility" version = "4.0.0-dev" source = "git+https://github.com/librelois/substrate.git?branch=duniter-monthly-2022-02#80f060dfad0363af03dbecbe39c6fa9b99042acc" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "parity-scale-codec", diff --git a/Cargo.toml b/Cargo.toml index 8b6c7c4de7bb6f93bb7580bcd4aa448aff2be8c9..b054d2a4e0f999b1a4ecfa4b3ce8d4993e63001b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,12 +23,12 @@ g1 = ["g1-runtime"] gdev = ["gdev-runtime"] gtest = ["gtest-runtime"] runtime-benchmarks = [ - 'g1-runtime', - 'g1-runtime/runtime-benchmarks', + #'g1-runtime', + #'g1-runtime/runtime-benchmarks', 'gdev-runtime', 'gdev-runtime/runtime-benchmarks', - 'gtest-runtime', - 'gtest-runtime/runtime-benchmarks', + #'gtest-runtime', + #'gtest-runtime/runtime-benchmarks', ] try-runtime = [ "g1-runtime/try-runtime", diff --git a/docs/dev/weights-benchmarking.md b/docs/dev/weights-benchmarking.md new file mode 100644 index 0000000000000000000000000000000000000000..0b6e127c65d577d5de11907fae07da4de03865e8 --- /dev/null +++ b/docs/dev/weights-benchmarking.md @@ -0,0 +1,33 @@ +# How to benchmarks weights of a Call/Hook/Pallet + +1. Create the benchmarking tests, see commit 31057e37be471e3f27d18c63818d57cc907b4b4f for a +complete real example. +2. Run the benchmark test on your local machine: +`cargo test -p <pallet> --features runtime-benchmarks` +3. If the benchmark tests compiles and pass, compile the binary with benchmarks on your local +machine: `cargo build --release --features runtime-benchmarks` +4. Run the benchmarks on your local machine (to test if it work mith a real runtime). The command +is: `duniter benchmark --chain=CURRENCY-dev --steps=50 --repeat=20 --pallet=pallet_universal_dividend --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=.` +5. If it work, use the generated file content to create or update the `WeightInfo` trait and the `()` dummy implementation. Then use the `WeightInfo` tarit in the real code of the pallet. See 79e0fd4bf3b0579279fc957da5e2fdfc6d8a17fa for a +complete real example. +6. Redo steps `3.` and `4.` on the reference machine. +7. Put the generated file on `runtime/common/src/weights` and use it in the runtimes configuration. +See cee7c3b2763ba402e807f126534d9cd39a8bd025 for a complete real example. + +Note 1: You Must replace `CURRENCY` by the currency type, or for ĞDev use directly `--chain=dev`. + +Note2. If the reference machine not support wasmtime, you should replace `--wasm-execution=compiled` +by `--wasm-execution=interpreted-i-know-what-i-do`. + +## What the reference machine is? + +For now (06/2022), it's a `Raspberry Pi 4 Model B - 4GB` with an SSD connected via USB3. + +To cross-compile the benchmarks binary for armv7: + +``` +./scripts/cross-build-arm.sh --features runtime-benchmarks +``` + + +The cross compiled binary is generated here: `target/armv7-unknown-linux-gnueabihf/release/duniter` diff --git a/file_header.txt b/file_header.txt new file mode 100644 index 0000000000000000000000000000000000000000..33e7020366446ba1f28d2f8f37b35ada92ab2b15 --- /dev/null +++ b/file_header.txt @@ -0,0 +1,15 @@ +// Copyright 2021-2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. diff --git a/pallets/duniter-account/src/lib.rs b/pallets/duniter-account/src/lib.rs index 0615fbd99f8ddc6b5bb031a5616f8d84b6c77b41..be7fcaa59eeb4aecbf809d8152941fefb2cfe523 100644 --- a/pallets/duniter-account/src/lib.rs +++ b/pallets/duniter-account/src/lib.rs @@ -164,14 +164,12 @@ pub mod pallet { let price = T::NewAccountPrice::get(); if account_data.free >= T::ExistentialDeposit::get() + price { // The account can pay the new account price, we should: - // 1. Increment providers to create the account for frame_system point of view - // 2. Withdraw the "new account price" amount - // 3. Increment consumers to prevent the destruction of the account before + // 1. Withdraw the "new account price" amount + // 2. Increment consumers to prevent the destruction of the account before // the random id is assigned - // 4. Manage the funds collected - // 5. Submit random id generation request - // 6. Save the id of the random generation request. - frame_system::Pallet::<T>::inc_providers(&account_id); + // 3. Manage the funds collected + // 4. Submit random id generation request + // 5. Save the id of the random generation request. let res = <pallet_balances::Pallet<T> as Currency<T::AccountId>>::withdraw( &account_id, price, @@ -287,10 +285,9 @@ where if !frame_system::Pallet::<T>::account_exists(account_id) { // If the account does not exist, we should program its creation PendingNewAccounts::<T>::insert(account_id, ()); - } else { - // If the account already exists, we should register increment providers directly - frame_system::Pallet::<T>::inc_providers(account_id); } + // We should increment the "balances" provider + frame_system::Pallet::<T>::inc_providers(account_id); } else if was_providing && !is_providing { match frame_system::Pallet::<T>::dec_providers(account_id)? { frame_system::DecRefStatus::Reaped => return Ok(result), diff --git a/pallets/universal-dividend/Cargo.toml b/pallets/universal-dividend/Cargo.toml index fd100ced2f0bfdd7608b2666e2130e6dc46cd1ae..8b939e5f7a307b0f8886f82668e39dab38fea024 100644 --- a/pallets/universal-dividend/Cargo.toml +++ b/pallets/universal-dividend/Cargo.toml @@ -10,7 +10,10 @@ version = '3.0.0' [features] default = ['std'] -runtime-benchmarks = ['frame-benchmarking'] +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "pallet-balances" +] std = [ 'codec/std', 'frame-support/std', @@ -27,18 +30,16 @@ try-runtime = ['frame-support/try-runtime'] # substrate scale-info = { version = "1.0", default-features = false, features = ["derive"] } +# substrate bencharks +frame-benchmarking = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', optional = true, default-features = false } +pallet-balances = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', optional = true, default-features = false } + [dependencies.codec] default-features = false features = ['derive'] package = 'parity-scale-codec' version = '2.3.1' -[dependencies.frame-benchmarking] -default-features = false -git = 'https://github.com/librelois/substrate.git' -optional = true -branch = 'duniter-monthly-2022-02' - [dependencies.frame-support] default-features = false git = 'https://github.com/librelois/substrate.git' diff --git a/pallets/universal-dividend/src/benchmarking.rs b/pallets/universal-dividend/src/benchmarking.rs index 76a3c59057cf23694de850195766b854de9b5b47..530065d03650650b19268750a712ba53deb717a5 100644 --- a/pallets/universal-dividend/src/benchmarking.rs +++ b/pallets/universal-dividend/src/benchmarking.rs @@ -1,52 +1,100 @@ -// Copyright 2021 Axiom-Team +// Copyright 2021-2022 Axiom-Team // -// This file is part of Substrate-Libre-Currency. +// This file is part of Duniter-v2S. // -// Substrate-Libre-Currency is free software: you can redistribute it and/or modify +// Duniter-v2S is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, version 3 of the License. // -// Substrate-Libre-Currency is distributed in the hope that it will be useful, +// Duniter-v2S is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License -// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>. +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. -//! Benchmarking setup for pallet-universal-dividend +#![cfg(feature = "runtime-benchmarks")] use super::*; -#[allow(unused)] -use crate::Pallet as UniversalDividend; -use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_benchmarking::{account, benchmarks, whitelisted_caller}; +use frame_support::pallet_prelude::IsType; +use frame_support::traits::{Get, OnInitialize}; use frame_system::RawOrigin; +use pallet_balances::Pallet as Balances; +use sp_runtime::traits::Bounded; -// Create state for use in `on_initialize`. -fn create_state<T: Config>(n: u32) -> Result<(), &'static str> { - <LastReevalStorage<T>>::put(LastReeval { - members_count: T::MembersCount::get(), - monetary_mass: T::Currency::total_issuance(), - ud_amount: new_ud_amount, - }); +use crate::Pallet; + +const BLOCK_NUMBER: u32 = 2; +const ED_MULTIPLIER: u32 = 10; +const SEED: u32 = 0; + +/*fn fill_storage<T: Config>( + members_count: u32, +) -> Result<(), &'static str> { Ok(()) -} +}*/ benchmarks! { - create_ud { - run_to_block(2); - }: UniversalDividend::on_initialize() + // TODO add on_initialize_ud_created and on_initialize_ud_reevalued (after manual UD impl) + on_initialize { + //let n in 1 .. 10_000; + //fill_storage::<T>(n)?; + }: { Pallet::<T>::on_initialize(BLOCK_NUMBER.into()); } verify { - assert_eq!(System::events().len(), 7); } -} + // Benchmark `transfer_ud` extrinsic with the worst possible conditions: + // * Transfer will kill the sender account. + // * Transfer will create the recipient account. + where_clause { where T: pallet_balances::Config, T::Balance: From<u64>, <T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance> } + transfer_ud { + let existential_deposit = T::ExistentialDeposit::get(); + let caller = whitelisted_caller(); -impl_benchmark_test_suite!( - UniversalDividend, - crate::mock::new_test_ext(UniversalDividendConfig { - first_ud: 1_000, - initial_monetary_mass: 0, - }), - crate::mock::Test, -); + // Give some multiple of the existential deposit + let balance = existential_deposit.saturating_mul(ED_MULTIPLIER.into()); + let _ = T::Currency::make_free_balance_be(&caller, balance.into()); + + // Transfer `e - 1` existential deposits + 1 unit, which guarantees to create one account, + // and reap this user. + let recipient: T::AccountId = account("recipient", 0, SEED); + let recipient_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(recipient.clone()); + let transfer_amount = existential_deposit.saturating_mul((ED_MULTIPLIER - 1).into()) + 1u32.into(); + let transfer_amount_ud = transfer_amount.saturating_mul(1_000.into()) / Pallet::<T>::current_ud().into(); + }: _(RawOrigin::Signed(caller.clone()), recipient_lookup, transfer_amount_ud.into()) + verify { + assert_eq!(Balances::<T>::free_balance(&caller), Zero::zero()); + assert_eq!(Balances::<T>::free_balance(&recipient), transfer_amount); + } + + // Benchmark `transfer_ud_keep_alive` with the worst possible condition: + // * The recipient account is created. + where_clause { where T: pallet_balances::Config, T::Balance: From<u64>, <T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance> } + transfer_ud_keep_alive { + let caller = whitelisted_caller(); + let recipient: T::AccountId = account("recipient", 0, SEED); + let recipient_lookup: <T::Lookup as StaticLookup>::Source = T::Lookup::unlookup(recipient.clone()); + + // Give the sender account max funds, thus a transfer will not kill account. + let _ = T::Currency::make_free_balance_be(&caller, <T::Currency as Currency<T::AccountId>>::Balance::max_value()); + let existential_deposit = T::ExistentialDeposit::get(); + let transfer_amount = existential_deposit.saturating_mul(ED_MULTIPLIER.into()); + let transfer_amount_ud = transfer_amount.saturating_mul(1_000.into()) / Pallet::<T>::current_ud().into(); + }: _(RawOrigin::Signed(caller.clone()), recipient_lookup, transfer_amount_ud.into()) + verify { + assert!(!Balances::<T>::free_balance(&caller).is_zero()); + assert_eq!(Balances::<T>::free_balance(&recipient), transfer_amount); + } + + impl_benchmark_test_suite!( + Pallet, + crate::mock::new_test_ext(crate::mock::UniversalDividendConfig { + first_reeval: 8, + first_ud: 1_000, + initial_monetary_mass: 0, + }), + crate::mock::Test + ); +} diff --git a/pallets/universal-dividend/src/lib.rs b/pallets/universal-dividend/src/lib.rs index 9b57563bbfec4b2083911b48f103221e58b292be..ab6fa536122d0d04d2888e621dbe330fa69b2560 100644 --- a/pallets/universal-dividend/src/lib.rs +++ b/pallets/universal-dividend/src/lib.rs @@ -16,16 +16,15 @@ #![cfg_attr(not(feature = "std"), no_std)] -pub use pallet::*; - +mod benchmarking; #[cfg(test)] mod mock; - #[cfg(test)] mod tests; +mod weights; -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; +pub use pallet::*; +pub use weights::WeightInfo; use frame_support::traits::{tokens::ExistenceRequirement, Currency}; use sp_arithmetic::{ @@ -83,6 +82,8 @@ pub mod pallet { /// Example: If you wish to express the UD amounts with a maximum precision of the order /// of the milliUD, choose 1000 type UnitsPerUd: Get<BalanceOf<Self>>; + /// Pallet weights info + type WeightInfo: WeightInfo; } // STORAGE // @@ -139,20 +140,21 @@ pub mod pallet { #[pallet::hooks] impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> { fn on_initialize(n: T::BlockNumber) -> Weight { + let mut total_weight = T::WeightInfo::on_initialize(); if (n % T::UdCreationPeriod::get()).is_zero() { let current_members_count = T::MembersCount::get(); let next_reeval = NextReeval::<T>::get(); if n >= next_reeval { NextReeval::<T>::put(next_reeval.saturating_add(T::UdReevalPeriod::get())); - Self::reeval_ud(current_members_count) + total_weight += Self::reeval_ud(current_members_count) + Self::create_ud(current_members_count, n) - + T::DbWeight::get().reads_writes(2, 1) + + T::DbWeight::get().reads_writes(2, 1); } else { - Self::create_ud(current_members_count, n) + T::DbWeight::get().reads(2) + total_weight += + Self::create_ud(current_members_count, n) + T::DbWeight::get().reads(2); } - } else { - 0 } + total_weight } } @@ -277,7 +279,7 @@ pub mod pallet { #[pallet::call] impl<T: Config> Pallet<T> { /// Transfer some liquid free balance to another account, in milliUD. - #[pallet::weight(1_000_000_000)] + #[pallet::weight(T::WeightInfo::transfer_ud())] pub fn transfer_ud( origin: OriginFor<T>, dest: <T::Lookup as StaticLookup>::Source, @@ -287,7 +289,7 @@ pub mod pallet { } /// Transfer some liquid free balance to another account, in milliUD. - #[pallet::weight(1_000_000_000)] + #[pallet::weight(T::WeightInfo::transfer_ud_keep_alive())] pub fn transfer_ud_keep_alive( origin: OriginFor<T>, dest: <T::Lookup as StaticLookup>::Source, diff --git a/pallets/universal-dividend/src/mock.rs b/pallets/universal-dividend/src/mock.rs index 63738dcd57126b252752246dadd99e7746072418..6680691641647143374c19b207cb66ef26cadbfe 100644 --- a/pallets/universal-dividend/src/mock.rs +++ b/pallets/universal-dividend/src/mock.rs @@ -79,7 +79,7 @@ impl system::Config for Test { } parameter_types! { - pub const ExistentialDeposit: Balance = 1; + pub const ExistentialDeposit: Balance = 10; pub const MaxLocks: u32 = 50; } @@ -119,6 +119,7 @@ impl pallet_universal_dividend::Config for Test { type UdCreationPeriod = UdCreationPeriod; type UdReevalPeriod = UdReevalPeriod; type UnitsPerUd = frame_support::traits::ConstU64<1_000>; + type WeightInfo = (); } // Build genesis storage according to the mock runtime. diff --git a/pallets/universal-dividend/src/weights.rs b/pallets/universal-dividend/src/weights.rs new file mode 100644 index 0000000000000000000000000000000000000000..6dfab2bbdad40de8b7743230818d28bb81fbf1c4 --- /dev/null +++ b/pallets/universal-dividend/src/weights.rs @@ -0,0 +1,50 @@ +// Copyright 2021-2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +#![allow(clippy::unnecessary_cast)] + +use frame_support::weights::{constants::RocksDbWeight, Weight}; + +/// Weight functions needed for pallet_universal_dividend. +pub trait WeightInfo { + fn on_initialize() -> Weight; + fn transfer_ud() -> Weight; + fn transfer_ud_keep_alive() -> Weight; +} + +// Insecure weights implementation, use it for tests only! +impl WeightInfo for () { + // Storage: (r:0 w:0) + fn on_initialize() -> Weight { + 2_260_000 as Weight + } + // Storage: UniversalDividend CurrentUd (r:1 w:0) + // Storage: System Account (r:1 w:1) + // Storage: Account PendingNewAccounts (r:0 w:1) + fn transfer_ud() -> Weight { + (53_401_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + } + // Storage: UniversalDividend CurrentUd (r:1 w:0) + // Storage: System Account (r:1 w:1) + // Storage: Account PendingNewAccounts (r:0 w:1) + fn transfer_ud_keep_alive() -> Weight { + (33_420_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + } +} diff --git a/pallets/upgrade-origin/Cargo.toml b/pallets/upgrade-origin/Cargo.toml index 52065c3f66c71af0daa106803a1e53cc4426ccc0..441c906e54d97239c8be2440f18c27452d981e8c 100644 --- a/pallets/upgrade-origin/Cargo.toml +++ b/pallets/upgrade-origin/Cargo.toml @@ -10,7 +10,7 @@ version = '3.0.0' [features] default = ['std'] -runtime-benchmarks = ['frame-benchmarking'] +runtime-benchmarks = ['frame-benchmarking/runtime-benchmarks'] std = [ 'codec/std', 'frame-support/std', diff --git a/pallets/upgrade-origin/src/benchmarking.rs b/pallets/upgrade-origin/src/benchmarking.rs new file mode 100644 index 0000000000000000000000000000000000000000..78a92c9206a694fb872dca143fac465a2acb260f --- /dev/null +++ b/pallets/upgrade-origin/src/benchmarking.rs @@ -0,0 +1,30 @@ +// Copyright 2021-2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +#![cfg(feature = "runtime-benchmarks")] + +use super::*; + +use crate::Pallet; +use frame_benchmarking::benchmarks; +use frame_support::traits::Get; + +benchmarks! { + dispatch_as_root { + let call = Box::new(frame_system::Call::remark { remark: vec![] }.into()); + let origin: T::WorstCaseOriginType = T::WorstCaseOrigin::get(); + }: dispatch_as_root (origin, call) +} diff --git a/pallets/upgrade-origin/src/lib.rs b/pallets/upgrade-origin/src/lib.rs index 2a84f8caccc32545ec665576584a30ebe3025a06..8636c6fa51acd2c14962c5adccf3f8c328d12393 100644 --- a/pallets/upgrade-origin/src/lib.rs +++ b/pallets/upgrade-origin/src/lib.rs @@ -17,6 +17,12 @@ #![cfg_attr(not(feature = "std"), no_std)] #![allow(clippy::boxed_local)] +mod benchmarking; +mod weights; + +pub use pallet::*; +pub use weights::WeightInfo; + use frame_support::{ dispatch::PostDispatchInfo, traits::{IsSubType, UnfilteredDispatchable}, @@ -25,7 +31,6 @@ use frame_support::{ use sp_runtime::traits::Dispatchable; use sp_std::prelude::*; -pub use pallet::*; #[frame_support::pallet] pub mod pallet { use super::*; @@ -53,6 +58,17 @@ pub mod pallet { /// The upgradable origin type UpgradableOrigin: EnsureOrigin<Self::Origin>; + + /// Pallet weights info + type WeightInfo: WeightInfo; + + #[cfg(feature = "runtime-benchmarks")] + /// The worst case origin type to use in ŵeights benchmarking + type WorstCaseOriginType: Into<Self::Origin>; + + #[cfg(feature = "runtime-benchmarks")] + /// The worst case origin to use in weights benchmarking + type WorstCaseOrigin: Get<Self::WorstCaseOriginType>; } #[pallet::event] @@ -67,10 +83,36 @@ pub mod pallet { /// Dispatches a function call from root origin. /// /// The weight of this call is defined by the caller. - #[pallet::weight(*_weight)] + #[pallet::weight({ + let dispatch_info = call.get_dispatch_info(); + ( + T::WeightInfo::dispatch_as_root() + .saturating_add(dispatch_info.weight), + dispatch_info.class, + ) + })] pub fn dispatch_as_root( origin: OriginFor<T>, call: Box<<T as Config>::Call>, + ) -> DispatchResultWithPostInfo { + T::UpgradableOrigin::ensure_origin(origin)?; + + let res = call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into()); + + Self::deposit_event(Event::DispatchedAsRoot { + result: res.map(|_| ()).map_err(|e| e.error), + }); + Ok(Pays::No.into()) + } + /// Dispatches a function call from root origin. + /// This function does not check the weight of the call, and instead allows the + /// caller to specify the weight of the call. + /// + /// The weight of this call is defined by the caller. + #[pallet::weight((*_weight, call.get_dispatch_info().class))] + pub fn dispatch_as_root_unchecked_weight( + origin: OriginFor<T>, + call: Box<<T as Config>::Call>, _weight: Weight, ) -> DispatchResultWithPostInfo { T::UpgradableOrigin::ensure_origin(origin)?; diff --git a/pallets/upgrade-origin/src/weights.rs b/pallets/upgrade-origin/src/weights.rs new file mode 100644 index 0000000000000000000000000000000000000000..765e8554d843ee17e4a8c8ce9bb0a62b39c2ff5a --- /dev/null +++ b/pallets/upgrade-origin/src/weights.rs @@ -0,0 +1,31 @@ +// Copyright 2021-2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +#![allow(clippy::unnecessary_cast)] + +use frame_support::weights::Weight; + +/// Weight functions needed for pallet_upgrade_origin. +pub trait WeightInfo { + fn dispatch_as_root() -> Weight; +} + +// Insecure weights implementation, use it for tests only! +impl WeightInfo for () { + fn dispatch_as_root() -> Weight { + 8_000 as Weight + } +} diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index e26cc3c979c3b8aefb0ba718904e66513071469b..9c2f22584d145f364b7ac8053a4878905d96e786 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -8,13 +8,19 @@ edition = '2018' [features] runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", 'frame-support/runtime-benchmarks', + 'frame-system-benchmarking', 'frame-system/runtime-benchmarks', + "pallet-babe/runtime-benchmarks", + 'pallet-balances/runtime-benchmarks', 'pallet-certification/runtime-benchmarks', 'pallet-duniter-wot/runtime-benchmarks', 'pallet-identity/runtime-benchmarks', 'pallet-membership/runtime-benchmarks', - 'pallet-treasury/std', + 'pallet-multisig/runtime-benchmarks', + 'pallet-proxy/runtime-benchmarks', + 'pallet-treasury/runtime-benchmarks', 'pallet-ud-accounts-storage/runtime-benchmarks', 'sp-runtime/runtime-benchmarks', ] @@ -26,21 +32,28 @@ std = [ 'log/std', 'pallet-authority-members/std', 'pallet-babe/std', + 'pallet-balances/std', 'pallet-certification/std', 'pallet-duniter-account/std', 'pallet-duniter-wot/std', 'pallet-grandpa/std', 'pallet-identity/std', 'pallet-membership/std', + 'pallet-multisig/std', 'pallet-provide-randomness/std', + 'pallet-proxy/std', + 'pallet-scheduler/std', + 'pallet-timestamp/std', 'pallet-treasury/std', + 'pallet-universal-dividend/std', 'pallet-ud-accounts-storage/std', - 'serde', + "serde/std", + "serde_derive", 'sp-arithmetic/std', 'sp-core/std', 'sp-membership/std', 'sp-runtime/std', - 'sp-std/std' + 'sp-std/std', ] try-runtime = [ "frame-support/try-runtime", @@ -49,7 +62,6 @@ try-runtime = [ "pallet-grandpa/try-runtime", ] - [dependencies] duniter-primitives = { path = '../../primitives/duniter', default-features = false } pallet-authority-members = { path = '../../pallets/authority-members', default-features = false } @@ -60,83 +72,40 @@ pallet-identity = { path = '../../pallets/identity', default-features = false } pallet-membership = { path = '../../pallets/membership', default-features = false } pallet-provide-randomness = { path = '../../pallets/provide-randomness', default-features = false } pallet-ud-accounts-storage = { path = '../../pallets/ud-accounts-storage', default-features = false } +pallet-upgrade-origin = { path = '../../pallets/upgrade-origin', default-features = false } +pallet-universal-dividend = { path = '../../pallets/universal-dividend', default-features = false } sp-membership = { path = '../../primitives/membership', default-features = false } # Crates.io +codec = { package = "parity-scale-codec", version = "2.3.1", features = ["derive"], default-features = false } log = { version = "0.4.14", default-features = false } +scale-info = { version = "1.0", default-features = false, features = ["derive"] } +serde = { version = "1.0.101", default-features = false } +serde_derive = { version = "1.0.101", optional = true } smallvec = "1.6.1" # Substrate -scale-info = { version = "1.0", default-features = false, features = ["derive"] } - -[dependencies.codec] -default-features = false -features = ['derive'] -package = 'parity-scale-codec' -version = '2.3.1' - -[dependencies.frame-support] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-02' - -[dependencies.frame-system] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-02' - -[dependencies.pallet-babe] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-02' - -[dependencies.pallet-grandpa] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-02' - -[dependencies.pallet-session] -default-features = false -features = ["historical"] -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-02' - -[dependencies.pallet-treasury] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-02' - -[dependencies.serde] -version = "1.0.101" -optional = true -features = ["derive"] - -[dependencies.sp-arithmetic] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-02' - -[dependencies.sp-consensus-babe] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-02' - -[dependencies.sp-core] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-02' - -[dependencies.sp-runtime] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-02' - -[dependencies.sp-staking] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-02' - -[dependencies.sp-std] -default-features = false -git = 'https://github.com/librelois/substrate.git' -branch = 'duniter-monthly-2022-02' +frame-support = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +frame-system = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +pallet-babe = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +pallet-balances = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +pallet-grandpa = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +pallet-multisig = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +pallet-proxy = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +pallet-scheduler = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +pallet-session = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +pallet-timestamp = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +pallet-treasury = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +sp-arithmetic = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +sp-consensus-babe = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +sp-core = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +sp-runtime = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } +sp-std = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } + + +# substrate benchmarks +frame-benchmarking = { git = "https://github.com/librelois/substrate", branch = 'duniter-monthly-2022-02', default-features = false, optional = true } +frame-system-benchmarking = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false, optional = true } + +# TODO: there is a bad coupling in substrate that force to add this dependency +sp-staking = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs index cb1321f87dc1814353f914d4782c4bd4eac951e0..e6002a5d1756c2d494750e70af8d08074f3e13d5 100644 --- a/runtime/common/src/apis.rs +++ b/runtime/common/src/apis.rs @@ -223,51 +223,78 @@ macro_rules! runtime_apis { } #[cfg(feature = "runtime-benchmarks")] - impl frame_benchmarking::Benchmark<Block> for Runtime { - fn dispatch_benchmark( - config: frame_benchmarking::BenchmarkConfig, - ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> { - use frame_benchmarking::{ - add_benchmark, BenchmarkBatch, Benchmarking, TrackedStorageKey, - }; - - use frame_system_benchmarking::Pallet as SystemBench; - impl frame_system_benchmarking::Config for Runtime {} - - use pallet_crowdloan_rewards::Pallet as PalletCrowdloanRewardsBench; - use parachain_staking::Pallet as ParachainStakingBench; - use pallet_author_mapping::Pallet as PalletAuthorMappingBench; - let whitelist: Vec<TrackedStorageKey> = vec![]; - - let mut batches = Vec::<BenchmarkBatch>::new(); - let params = (&config, &whitelist); - - add_benchmark!( - params, - batches, - parachain_staking, - ParachainStakingBench::<Runtime> - ); - // add_benchmark!( - // params, - // batches, - // pallet_crowdloan_rewards, - // PalletCrowdloanRewardsBench::<Runtime> - // ); - add_benchmark!( - params, - batches, - pallet_author_mapping, - PalletAuthorMappingBench::<Runtime> - ); - add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>); - - if batches.is_empty() { - return Err("Benchmark not found for this pallet.".into()); - } - Ok(batches) - } - } + impl frame_benchmarking::Benchmark<Block> for Runtime { + fn benchmark_metadata(extra: bool) -> ( + Vec<frame_benchmarking::BenchmarkList>, + Vec<frame_support::traits::StorageInfo>, + ) { + use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList}; + use frame_support::traits::StorageInfoTrait; + + use frame_system_benchmarking::Pallet as SystemBench; + use frame_benchmarking::baseline::Pallet as Baseline; + + let mut list = Vec::<BenchmarkList>::new(); + list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>); + list_benchmark!(list, extra, pallet_balances, Balances); + 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_timestamp, Timestamp); + list_benchmark!(list, extra, pallet_universal_dividend, UniversalDividend); + list_benchmark!(list, extra, pallet_upgrade_origin, UpgradeOrigin); + list_benchmark!(list, extra, pallet_utility, Utility); + + let storage_info = AllPalletsWithSystem::storage_info(); + return (list, storage_info) + } + + fn dispatch_benchmark( + config: frame_benchmarking::BenchmarkConfig + ) -> Result< + Vec<frame_benchmarking::BenchmarkBatch>, + sp_runtime::RuntimeString, + > { + use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey}; + // Trying to add benchmarks directly to some pallets caused cyclic dependency issues. + // To get around that, we separated the benchmarks into its own crate. + use frame_system_benchmarking::Pallet as SystemBench; + use frame_benchmarking::baseline::Pallet as Baseline; + + impl frame_system_benchmarking::Config for Runtime {} + impl frame_benchmarking::baseline::Config for Runtime {} + + let whitelist: Vec<TrackedStorageKey> = vec![ + // Block Number + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), + // Total Issuance + hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), + // Execution Phase + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), + // Event Count + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), + // System Events + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), + // Treasury Account + hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da95ecffd7b6c0f78751baa9d281e0bfa3a6d6f646c70792f74727372790000000000000000000000000000000000000000").to_vec().into(), + ]; + + let mut batches = Vec::<BenchmarkBatch>::new(); + let params = (&config, &whitelist); + add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>); + add_benchmark!(params, batches, pallet_balances, Balances); + add_benchmark!(params, batches, pallet_multisig, Multisig); + add_benchmark!(params, batches, pallet_proxy, Proxy); + add_benchmark!(params, batches, pallet_scheduler, Scheduler); + add_benchmark!(params, batches, pallet_timestamp, Timestamp); + add_benchmark!(params, batches, pallet_universal_dividend, UniversalDividend); + add_benchmark!(params, batches, pallet_upgrade_origin, UpgradeOrigin); + add_benchmark!(params, batches, pallet_utility, Utility); + + if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } + Ok(batches) + } + } } }; } diff --git a/runtime/common/src/constants.rs b/runtime/common/src/constants.rs index 6b8d00591a83819589a4d34739bc5673dcf11472..b3c5e22fce5f2391198cc57be257111fd784b57e 100644 --- a/runtime/common/src/constants.rs +++ b/runtime/common/src/constants.rs @@ -38,15 +38,6 @@ const SECS_PER_YEAR: u64 = 31_557_600; // (365.25 * 24 * 60 * 60) pub const MONTHS: BlockNumber = (SECS_PER_YEAR / (12 * SECS_PER_BLOCK)) as BlockNumber; pub const YEARS: BlockNumber = (SECS_PER_YEAR / SECS_PER_BLOCK) as BlockNumber; -pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); - -frame_support::parameter_types! { - pub const DbWeight: frame_support::weights::RuntimeDbWeight = frame_support::weights::RuntimeDbWeight { - read: 250 * frame_support::weights::constants::WEIGHT_PER_MICROS, // ~25 µs - write: 1_000 * frame_support::weights::constants::WEIGHT_PER_MICROS, // ~100 µs - }; -} - // 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks. pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4); @@ -64,3 +55,44 @@ pub const DEPOSIT_PER_ITEM: Balance = 100; pub const fn deposit(items: u32, bytes: u32) -> Balance { items as Balance * DEPOSIT_PER_ITEM + (bytes as Balance * DEPOSIT_PER_BYTE) } + +// WEIGHTS COMSTANTS // + +// Execution cost of everything outside of the call itself: +// signature verification, pre_dispatch and post_dispatch +pub const EXTRINSIC_BASE_WEIGHTS: frame_support::weights::Weight = 1_000_000_000; + +// Maximal weight proportion of normal extrinsics per block +pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); + +// DB weights +frame_support::parameter_types! { + pub const DbWeight: frame_support::weights::RuntimeDbWeight = frame_support::weights::RuntimeDbWeight { + read: 250 * frame_support::weights::constants::WEIGHT_PER_MICROS, // ~25 µs + write: 1_000 * frame_support::weights::constants::WEIGHT_PER_MICROS, // ~100 µs + }; +} + +// Block weights limits +pub fn block_weights( + expected_block_weight: frame_support::weights::Weight, + normal_ratio: sp_arithmetic::Perbill, +) -> frame_system::limits::BlockWeights { + let normal_weight = normal_ratio * expected_block_weight; + frame_system::limits::BlockWeights::builder() + .for_class(frame_support::weights::DispatchClass::Normal, |weights| { + weights.base_extrinsic = EXTRINSIC_BASE_WEIGHTS; + weights.max_total = normal_weight.into(); + }) + .for_class( + frame_support::weights::DispatchClass::Operational, + |weights| { + weights.base_extrinsic = EXTRINSIC_BASE_WEIGHTS; + weights.max_total = expected_block_weight.into(); + weights.reserved = (expected_block_weight - normal_weight).into(); + }, + ) + .avg_block_initialization(sp_arithmetic::Perbill::from_percent(10)) + .build() + .expect("Fatal error: invalid BlockWeights configuration") +} diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index 86c59efa0a10115da6f9690e0ef36abe28c10a11..e7b880f1f6c7c92cbedfb16be886f1780ae68f82 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -69,7 +69,7 @@ macro_rules! pallets_config { /// The data to be stored in an account. type AccountData = pallet_duniter_account::AccountData<Balance>; /// Weight information for the extrinsics of this pallet. - type SystemWeightInfo = frame_system::weights::SubstrateWeight<Runtime>; + type SystemWeightInfo = common_runtime::weights::frame_system::WeightInfo<Runtime>; /// This is used as an identifier of the chain. 42 is the generic substrate prefix. type SS58Prefix = SS58Prefix; /// The set code logic, just the default since we're not a parachain. @@ -94,7 +94,7 @@ macro_rules! pallets_config { type ScheduleOrigin = EnsureRoot<AccountId>; type OriginPrivilegeCmp = EqualPrivilegeOnly; type MaxScheduledPerBlock = MaxScheduledPerBlock; - type WeightInfo = pallet_scheduler::weights::SubstrateWeight<Runtime>; + type WeightInfo = common_runtime::weights::pallet_scheduler::WeightInfo<Runtime>; type PreimageProvider = Preimage; type NoPreimagePostponement = (); } @@ -143,7 +143,7 @@ macro_rules! pallets_config { type Moment = u64; type OnTimestampSet = Babe; type MinimumPeriod = MinimumPeriod; - type WeightInfo = pallet_timestamp::weights::SubstrateWeight<Runtime>; + type WeightInfo = common_runtime::weights::pallet_timestamp::WeightInfo<Runtime>; } // MONEY MANAGEMENT // @@ -159,7 +159,7 @@ macro_rules! pallets_config { type DustRemoval = Treasury; type ExistentialDeposit = ExistentialDeposit; type AccountStore = Account; - type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>; + type WeightInfo = common_runtime::weights::pallet_balances::WeightInfo<Runtime>; } pub struct HandleFees; @@ -260,11 +260,22 @@ macro_rules! pallets_config { // ONCHAIN GOVERNANCE // - impl pallet_upgrade_origin::Config for Runtime { - type Event = Event; - type Call = Call; - type UpgradableOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, SmithsInstance>; - } + #[cfg(feature = "runtime-benchmarks")] + parameter_types! { + pub const WorstCaseOrigin: pallet_collective::RawOrigin<AccountId, SmithsInstance> = + pallet_collective::RawOrigin::<AccountId, SmithsInstance>::Members(2, 3); + } + + impl pallet_upgrade_origin::Config for Runtime { + type Event = Event; + type Call = Call; + type UpgradableOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, SmithsInstance>; + type WeightInfo = common_runtime::weights::pallet_upgrade_origin::WeightInfo<Runtime>; + #[cfg(feature = "runtime-benchmarks")] + type WorstCaseOriginType = pallet_collective::RawOrigin<AccountId, SmithsInstance>; + #[cfg(feature = "runtime-benchmarks")] + type WorstCaseOrigin = WorstCaseOrigin; + } parameter_types! { pub const PreimageMaxSize: u32 = 4096 * 1024; @@ -322,7 +333,7 @@ macro_rules! pallets_config { type CallHasher = BlakeTwo256; type AnnouncementDepositBase = AnnouncementDepositBase; type AnnouncementDepositFactor = AnnouncementDepositFactor; - type WeightInfo = pallet_proxy::weights::SubstrateWeight<Self>; + type WeightInfo = common_runtime::weights::pallet_proxy::WeightInfo<Self>; } parameter_types! { @@ -336,7 +347,7 @@ macro_rules! pallets_config { type DepositBase = DepositBase; type DepositFactor = DepositFactor; type MaxSignatories = MaxSignatories; - type WeightInfo = pallet_multisig::weights::SubstrateWeight<Self>; + type WeightInfo = common_runtime::weights::pallet_multisig::WeightInfo<Self>; } impl pallet_utility::Config for Runtime { @@ -385,6 +396,7 @@ macro_rules! pallets_config { type UdCreationPeriod = UdCreationPeriod; type UdReevalPeriod = UdReevalPeriod; type UnitsPerUd = frame_support::traits::ConstU64<1_000>; + type WeightInfo = common_runtime::weights::pallet_universal_dividend::WeightInfo<Runtime>; } impl pallet_ud_accounts_storage::Config for Runtime {} diff --git a/runtime/common/src/weights.rs b/runtime/common/src/weights.rs index 664b681d730640915f519e4fd9d1f4661daaa931..f4e6ad7b61ce40e0cb769a41bab575ffb429ff42 100644 --- a/runtime/common/src/weights.rs +++ b/runtime/common/src/weights.rs @@ -14,5 +14,13 @@ // You should have received a copy of the GNU Affero General Public License // along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>. +pub mod frame_system; pub mod pallet_babe; +pub mod pallet_balances; pub mod pallet_grandpa; +pub mod pallet_multisig; +pub mod pallet_proxy; +pub mod pallet_scheduler; +pub mod pallet_timestamp; +pub mod pallet_universal_dividend; +pub mod pallet_upgrade_origin; diff --git a/runtime/common/src/weights/frame_system.rs b/runtime/common/src/weights/frame_system.rs new file mode 100644 index 0000000000000000000000000000000000000000..a5a26e394cd7f05797002d90ebe23433baef4f64 --- /dev/null +++ b/runtime/common/src/weights/frame_system.rs @@ -0,0 +1,85 @@ +// Copyright 2021-2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +//! Autogenerated weights for `frame_system` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-06-11, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./duniter +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=frame_system +// --extrinsic=* +// --execution=wasm +// --wasm-execution=interpreted-i-know-what-i-do +// --heap-pages=4096 +// --output=. + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `frame_system`. +pub struct WeightInfo<T>(PhantomData<T>); +impl<T: frame_system::Config> frame_system::WeightInfo for WeightInfo<T> { + fn remark(b: u32, ) -> Weight { + (56_698_000 as Weight) + // Standard Error: 0 + .saturating_add((238_000 as Weight).saturating_mul(b as Weight)) + } + fn remark_with_event(b: u32, ) -> Weight { + (1_830_806_000 as Weight) + // Standard Error: 0 + .saturating_add((254_000 as Weight).saturating_mul(b as Weight)) + } + // Storage: System Digest (r:1 w:1) + // Storage: unknown [0x3a686561707061676573] (r:0 w:1) + fn set_heap_pages() -> Weight { + (74_351_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: Skipped Metadata (r:0 w:0) + fn set_storage(i: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 26_000 + .saturating_add((38_883_000 as Weight).saturating_mul(i as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) + } + // Storage: Skipped Metadata (r:0 w:0) + fn kill_storage(i: u32, ) -> Weight { + (14_386_000 as Weight) + // Standard Error: 16_000 + .saturating_add((18_658_000 as Weight).saturating_mul(i as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) + } + // Storage: Skipped Metadata (r:0 w:0) + fn kill_prefix(p: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 8_000 + .saturating_add((6_532_000 as Weight).saturating_mul(p as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight))) + } +} diff --git a/runtime/common/src/weights/pallet_balances.rs b/runtime/common/src/weights/pallet_balances.rs new file mode 100644 index 0000000000000000000000000000000000000000..d2157390f83f016ee7606f28a8f44924d4775b29 --- /dev/null +++ b/runtime/common/src/weights/pallet_balances.rs @@ -0,0 +1,93 @@ +// Copyright 2021-2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +//! Autogenerated weights for `pallet_balances` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-06-11, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./duniter +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_balances +// --extrinsic=* +// --execution=wasm +// --wasm-execution=interpreted-i-know-what-i-do +// --heap-pages=4096 +// --output=. + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_balances`. +pub struct WeightInfo<T>(PhantomData<T>); +impl<T: frame_system::Config> pallet_balances::WeightInfo for WeightInfo<T> { + // Storage: System Account (r:1 w:1) + // Storage: Account PendingNewAccounts (r:0 w:1) + fn transfer() -> Weight { + (2_412_993_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: System Account (r:1 w:1) + // Storage: Account PendingNewAccounts (r:0 w:1) + fn transfer_keep_alive() -> Weight { + (1_414_318_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: System Account (r:1 w:1) + fn set_balance_creating() -> Weight { + (594_104_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: System Account (r:1 w:1) + fn set_balance_killing() -> Weight { + (704_715_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: System Account (r:2 w:2) + // Storage: Account PendingNewAccounts (r:0 w:1) + fn force_transfer() -> Weight { + (2_427_122_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + // Storage: System Account (r:1 w:1) + // Storage: Account PendingNewAccounts (r:0 w:1) + fn transfer_all() -> Weight { + (1_769_185_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: System Account (r:1 w:1) + fn force_unreserve() -> Weight { + (619_549_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } +} diff --git a/runtime/common/src/weights/pallet_multisig.rs b/runtime/common/src/weights/pallet_multisig.rs new file mode 100644 index 0000000000000000000000000000000000000000..d2099e694a71e7ebde2ac2c21612f0cdfac8aef9 --- /dev/null +++ b/runtime/common/src/weights/pallet_multisig.rs @@ -0,0 +1,146 @@ +// Copyright 2021-2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +//! Autogenerated weights for `pallet_multisig` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-06-13, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./duniter +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_multisig +// --extrinsic=* +// --execution=wasm +// --wasm-execution=interpreted-i-know-what-i-do +// --heap-pages=4096 +// --header=./file_header.txt +// --output=. + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_multisig`. +pub struct WeightInfo<T>(PhantomData<T>); +impl<T: frame_system::Config> pallet_multisig::WeightInfo for WeightInfo<T> { + fn as_multi_threshold_1(z: u32, ) -> Weight { + (694_175_000 as Weight) + // Standard Error: 0 + .saturating_add((405_000 as Weight).saturating_mul(z as Weight)) + } + // Storage: Multisig Multisigs (r:1 w:1) + // Storage: unknown [0x3a65787472696e7369635f696e646578] (r:1 w:0) + fn as_multi_create(s: u32, z: u32, ) -> Weight { + (1_258_408_000 as Weight) + // Standard Error: 752_000 + .saturating_add((34_672_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 0 + .saturating_add((249_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Multisig Multisigs (r:1 w:1) + // Storage: Multisig Calls (r:1 w:1) + // Storage: unknown [0x3a65787472696e7369635f696e646578] (r:1 w:0) + fn as_multi_create_store(s: u32, z: u32, ) -> Weight { + (1_397_026_000 as Weight) + // Standard Error: 754_000 + .saturating_add((29_235_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 0 + .saturating_add((574_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: Multisig Multisigs (r:1 w:1) + fn as_multi_approve(s: u32, z: u32, ) -> Weight { + (865_034_000 as Weight) + // Standard Error: 878_000 + .saturating_add((36_962_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 0 + .saturating_add((250_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Multisig Multisigs (r:1 w:1) + // Storage: Multisig Calls (r:1 w:1) + fn as_multi_approve_store(s: u32, z: u32, ) -> Weight { + (1_470_691_000 as Weight) + // Standard Error: 1_012_000 + .saturating_add((36_087_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 0 + .saturating_add((573_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: Multisig Multisigs (r:1 w:1) + // Storage: Multisig Calls (r:1 w:1) + // Storage: System Account (r:1 w:1) + fn as_multi_complete(s: u32, z: u32, ) -> Weight { + (1_884_292_000 as Weight) + // Standard Error: 1_339_000 + .saturating_add((80_505_000 as Weight).saturating_mul(s as Weight)) + // Standard Error: 0 + .saturating_add((980_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + // Storage: Multisig Multisigs (r:1 w:1) + // Storage: unknown [0x3a65787472696e7369635f696e646578] (r:1 w:0) + fn approve_as_multi_create(s: u32, ) -> Weight { + (1_267_276_000 as Weight) + // Standard Error: 243_000 + .saturating_add((33_108_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Multisig Multisigs (r:1 w:1) + // Storage: Multisig Calls (r:1 w:0) + fn approve_as_multi_approve(s: u32, ) -> Weight { + (865_683_000 as Weight) + // Standard Error: 403_000 + .saturating_add((35_735_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Multisig Multisigs (r:1 w:1) + // Storage: Multisig Calls (r:1 w:1) + // Storage: System Account (r:1 w:1) + fn approve_as_multi_complete(s: u32, ) -> Weight { + (14_065_198_000 as Weight) + // Standard Error: 3_270_000 + .saturating_add((72_838_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + // Storage: Multisig Multisigs (r:1 w:1) + // Storage: Multisig Calls (r:1 w:1) + fn cancel_as_multi(s: u32, ) -> Weight { + (6_654_037_000 as Weight) + // Standard Error: 300_000 + .saturating_add((33_665_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } +} diff --git a/runtime/common/src/weights/pallet_proxy.rs b/runtime/common/src/weights/pallet_proxy.rs new file mode 100644 index 0000000000000000000000000000000000000000..7fa6892cf20356a383f8439ccdcbb2d38bb52330 --- /dev/null +++ b/runtime/common/src/weights/pallet_proxy.rs @@ -0,0 +1,138 @@ +// Copyright 2021-2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +//! Autogenerated weights for `pallet_proxy` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-06-13, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./duniter +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_proxy +// --extrinsic=* +// --execution=wasm +// --wasm-execution=interpreted-i-know-what-i-do +// --heap-pages=4096 +// --header=./file_header.txt +// --output=. + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_proxy`. +pub struct WeightInfo<T>(PhantomData<T>); +impl<T: frame_system::Config> pallet_proxy::WeightInfo for WeightInfo<T> { + // Storage: Proxy Proxies (r:1 w:0) + fn proxy(p: u32, ) -> Weight { + (580_976_000 as Weight) + // Standard Error: 66_000 + .saturating_add((43_246_000 as Weight).saturating_mul(p as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + } + // Storage: Proxy Proxies (r:1 w:0) + // Storage: Proxy Announcements (r:1 w:1) + // Storage: System Account (r:1 w:1) + fn proxy_announced(a: u32, p: u32, ) -> Weight { + (1_543_060_000 as Weight) + // Standard Error: 372_000 + .saturating_add((106_336_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 387_000 + .saturating_add((37_661_000 as Weight).saturating_mul(p as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: Proxy Announcements (r:1 w:1) + // Storage: System Account (r:1 w:1) + fn remove_announcement(a: u32, _p: u32, ) -> Weight { + (1_028_018_000 as Weight) + // Standard Error: 359_000 + .saturating_add((105_964_000 as Weight).saturating_mul(a as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: Proxy Announcements (r:1 w:1) + // Storage: System Account (r:1 w:1) + fn reject_announcement(a: u32, _p: u32, ) -> Weight { + (1_044_098_000 as Weight) + // Standard Error: 349_000 + .saturating_add((106_076_000 as Weight).saturating_mul(a as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: Proxy Proxies (r:1 w:0) + // Storage: Proxy Announcements (r:1 w:1) + // Storage: System Account (r:1 w:1) + fn announce(a: u32, p: u32, ) -> Weight { + (1_262_407_000 as Weight) + // Standard Error: 350_000 + .saturating_add((104_255_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 364_000 + .saturating_add((38_980_000 as Weight).saturating_mul(p as Weight)) + .saturating_add(T::DbWeight::get().reads(3 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: Proxy Proxies (r:1 w:1) + fn add_proxy(p: u32, ) -> Weight { + (964_226_000 as Weight) + // Standard Error: 288_000 + .saturating_add((55_018_000 as Weight).saturating_mul(p as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Proxy Proxies (r:1 w:1) + fn remove_proxy(p: u32, ) -> Weight { + (761_347_000 as Weight) + // Standard Error: 240_000 + .saturating_add((58_595_000 as Weight).saturating_mul(p as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Proxy Proxies (r:1 w:1) + fn remove_proxies(p: u32, ) -> Weight { + (706_599_000 as Weight) + // Standard Error: 55_000 + .saturating_add((41_943_000 as Weight).saturating_mul(p as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: unknown [0x3a65787472696e7369635f696e646578] (r:1 w:0) + // Storage: Proxy Proxies (r:1 w:1) + fn anonymous(p: u32, ) -> Weight { + (1_162_882_000 as Weight) + // Standard Error: 25_000 + .saturating_add((105_000 as Weight).saturating_mul(p as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Proxy Proxies (r:1 w:1) + fn kill_anonymous(p: u32, ) -> Weight { + (952_412_000 as Weight) + // Standard Error: 58_000 + .saturating_add((41_903_000 as Weight).saturating_mul(p as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } +} diff --git a/runtime/common/src/weights/pallet_scheduler.rs b/runtime/common/src/weights/pallet_scheduler.rs new file mode 100644 index 0000000000000000000000000000000000000000..4e3bb4df9ef251e0305aaf6c58eb48371cbf6ce3 --- /dev/null +++ b/runtime/common/src/weights/pallet_scheduler.rs @@ -0,0 +1,194 @@ +// Copyright 2021-2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +//! Autogenerated weights for `pallet_scheduler` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-06-13, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./duniter +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_scheduler +// --extrinsic=* +// --execution=wasm +// --wasm-execution=interpreted-i-know-what-i-do +// --heap-pages=4096 +// --header=./file_header.txt +// --output=. + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_scheduler`. +pub struct WeightInfo<T>(PhantomData<T>); +impl<T: frame_system::Config> pallet_scheduler::WeightInfo for WeightInfo<T> { + // Storage: Scheduler Agenda (r:2 w:2) + // Storage: Preimage PreimageFor (r:1 w:1) + // Storage: Preimage StatusFor (r:1 w:1) + // Storage: Scheduler Lookup (r:0 w:1) + fn on_initialize_periodic_named_resolved(s: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 4_241_000 + .saturating_add((1_897_662_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(s as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(s as Weight))) + } + // Storage: Scheduler Agenda (r:1 w:1) + // Storage: Preimage PreimageFor (r:1 w:1) + // Storage: Preimage StatusFor (r:1 w:1) + // Storage: Scheduler Lookup (r:0 w:1) + fn on_initialize_named_resolved(s: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 3_139_000 + .saturating_add((1_581_261_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(s as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(s as Weight))) + } + // Storage: Scheduler Agenda (r:2 w:2) + // Storage: Preimage PreimageFor (r:1 w:1) + // Storage: Preimage StatusFor (r:1 w:1) + fn on_initialize_periodic_resolved(s: u32, ) -> Weight { + (332_908_000 as Weight) + // Standard Error: 2_905_000 + .saturating_add((1_623_424_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(s as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(s as Weight))) + } + // Storage: Scheduler Agenda (r:1 w:1) + // Storage: Preimage PreimageFor (r:1 w:1) + // Storage: Preimage StatusFor (r:1 w:1) + fn on_initialize_resolved(s: u32, ) -> Weight { + (327_285_000 as Weight) + // Standard Error: 4_837_000 + .saturating_add((1_511_863_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(s as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(s as Weight))) + } + // Storage: Scheduler Agenda (r:1 w:1) + // Storage: Preimage PreimageFor (r:1 w:0) + // Storage: Scheduler Lookup (r:0 w:1) + fn on_initialize_named_aborted(s: u32, ) -> Weight { + (576_015_000 as Weight) + // Standard Error: 3_247_000 + .saturating_add((834_088_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(s as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } + // Storage: Scheduler Agenda (r:1 w:1) + // Storage: Preimage PreimageFor (r:1 w:0) + fn on_initialize_aborted(s: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 3_109_000 + .saturating_add((794_152_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(s as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Scheduler Agenda (r:2 w:2) + // Storage: Scheduler Lookup (r:0 w:1) + fn on_initialize_periodic_named(s: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 4_608_000 + .saturating_add((1_580_912_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(s as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(s as Weight))) + } + // Storage: Scheduler Agenda (r:2 w:2) + fn on_initialize_periodic(s: u32, ) -> Weight { + (405_993_000 as Weight) + // Standard Error: 5_129_000 + .saturating_add((1_400_748_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(s as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } + // Storage: Scheduler Agenda (r:1 w:1) + // Storage: Scheduler Lookup (r:0 w:1) + fn on_initialize_named(s: u32, ) -> Weight { + (149_824_000 as Weight) + // Standard Error: 2_930_000 + .saturating_add((1_272_241_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight))) + } + // Storage: Scheduler Agenda (r:1 w:1) + fn on_initialize(s: u32, ) -> Weight { + (103_696_000 as Weight) + // Standard Error: 2_588_000 + .saturating_add((1_194_963_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Scheduler Agenda (r:1 w:1) + fn schedule(s: u32, ) -> Weight { + (655_442_000 as Weight) + // Standard Error: 23_000 + .saturating_add((1_352_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Scheduler Agenda (r:1 w:1) + // Storage: Scheduler Lookup (r:0 w:1) + fn cancel(s: u32, ) -> Weight { + (431_975_000 as Weight) + // Standard Error: 606_000 + .saturating_add((422_692_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: Scheduler Lookup (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn schedule_named(s: u32, ) -> Weight { + (820_828_000 as Weight) + // Standard Error: 12_000 + .saturating_add((795_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: Scheduler Lookup (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn cancel_named(s: u32, ) -> Weight { + (197_177_000 as Weight) + // Standard Error: 672_000 + .saturating_add((425_783_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } +} diff --git a/runtime/common/src/weights/pallet_timestamp.rs b/runtime/common/src/weights/pallet_timestamp.rs new file mode 100644 index 0000000000000000000000000000000000000000..f85c2aba0dd20256a98c99c39f58c9b33d8415d1 --- /dev/null +++ b/runtime/common/src/weights/pallet_timestamp.rs @@ -0,0 +1,58 @@ +// Copyright 2021-2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +//! Autogenerated weights for `pallet_timestamp` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-06-13, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./duniter +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_timestamp +// --extrinsic=* +// --execution=wasm +// --wasm-execution=interpreted-i-know-what-i-do +// --heap-pages=4096 +// --header=./file_header.txt +// --output=. + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_timestamp`. +pub struct WeightInfo<T>(PhantomData<T>); +impl<T: frame_system::Config> pallet_timestamp::WeightInfo for WeightInfo<T> { + // Storage: Timestamp Now (r:1 w:1) + // Storage: Babe CurrentSlot (r:1 w:0) + fn set() -> Weight { + (126_036_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn on_finalize() -> Weight { + (53_611_000 as Weight) + } +} diff --git a/runtime/common/src/weights/pallet_universal_dividend.rs b/runtime/common/src/weights/pallet_universal_dividend.rs new file mode 100644 index 0000000000000000000000000000000000000000..1aab206a07fa68b944d2fbd40ca43ba6e4850525 --- /dev/null +++ b/runtime/common/src/weights/pallet_universal_dividend.rs @@ -0,0 +1,69 @@ +// Copyright 2021-2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +//! Autogenerated weights for `pallet_universal_dividend` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-06-12, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./duniter +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_universal_dividend +// --extrinsic=* +// --execution=wasm +// --wasm-execution=interpreted-i-know-what-i-do +// --heap-pages=4096 +// --header=./file_header.txt +// --output=. + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_universal_dividend`. +pub struct WeightInfo<T>(PhantomData<T>); +impl<T: frame_system::Config> pallet_universal_dividend::WeightInfo for WeightInfo<T> { + // Storage: Parameters ParametersStorage (r:1 w:0) + fn on_initialize() -> Weight { + (104_055_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + } + // Storage: UniversalDividend CurrentUd (r:1 w:0) + // Storage: System Account (r:1 w:1) + // Storage: Account PendingNewAccounts (r:0 w:1) + fn transfer_ud() -> Weight { + (2_468_842_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + // Storage: UniversalDividend CurrentUd (r:1 w:0) + // Storage: System Account (r:1 w:1) + // Storage: Account PendingNewAccounts (r:0 w:1) + fn transfer_ud_keep_alive() -> Weight { + (1_442_150_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } +} diff --git a/runtime/common/src/weights/pallet_upgrade_origin.rs b/runtime/common/src/weights/pallet_upgrade_origin.rs new file mode 100644 index 0000000000000000000000000000000000000000..8e0fa34d708a047a4dad6dcfec7860dd379db7b8 --- /dev/null +++ b/runtime/common/src/weights/pallet_upgrade_origin.rs @@ -0,0 +1,51 @@ +// Copyright 2021-2022 Axiom-Team +// +// This file is part of Duniter-v2S. +// +// Duniter-v2S is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// Duniter-v2S is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>. + +//! Autogenerated weights for `pallet_upgrade_origin` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-06-13, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./duniter2 +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_upgrade_origin +// --extrinsic=* +// --execution=wasm +// --wasm-execution=interpreted-i-know-what-i-do +// --heap-pages=4096 +// --header=./file_header.txt +// --output=. + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_upgrade_origin`. +pub struct WeightInfo<T>(PhantomData<T>); +impl<T: frame_system::Config> pallet_upgrade_origin::WeightInfo for WeightInfo<T> { + fn dispatch_as_root() -> Weight { + (324_716_000 as Weight) + } +} diff --git a/runtime/g1/src/parameters.rs b/runtime/g1/src/parameters.rs index 4275a5ef17fcdae9038002d361f9873d8dce0ace..9c4db0ceb75071ffe556ef77a1516216ef128972 100644 --- a/runtime/g1/src/parameters.rs +++ b/runtime/g1/src/parameters.rs @@ -26,8 +26,7 @@ use sp_runtime::transaction_validity::TransactionPriority; parameter_types! { pub const BlockHashCount: BlockNumber = 2400; /// We allow for 2 seconds of compute with a 6 second average block time. - pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights - ::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO); + pub BlockWeights: frame_system::limits::BlockWeights = block_weights(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO); pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); pub const SS58Prefix: u16 = 3682; diff --git a/runtime/gdev/Cargo.toml b/runtime/gdev/Cargo.toml index 570b53d0a447b18d4ffd7dd298731fa5e60d74dd..d400bdf3d09c791947d3f2525c251a878d6b029d 100644 --- a/runtime/gdev/Cargo.toml +++ b/runtime/gdev/Cargo.toml @@ -16,27 +16,46 @@ targets = ['x86_64-unknown-linux-gnu'] [features] default = ['std'] runtime-benchmarks = [ - 'frame-benchmarking', + 'common-runtime/runtime-benchmarks', + 'frame-benchmarking/runtime-benchmarks', 'frame-support/runtime-benchmarks', 'frame-system-benchmarking', 'frame-system/runtime-benchmarks', 'hex-literal', + 'pallet-authority-members/runtime-benchmarks', + 'pallet-babe/runtime-benchmarks', 'pallet-balances/runtime-benchmarks', + 'pallet-certification/runtime-benchmarks', + 'pallet-collective/runtime-benchmarks', + 'pallet-duniter-test-parameters/runtime-benchmarks', + 'pallet-duniter-account/runtime-benchmarks', + 'pallet-duniter-wot/runtime-benchmarks', + 'pallet-grandpa/runtime-benchmarks', 'pallet-identity/runtime-benchmarks', + 'pallet-membership/runtime-benchmarks', + 'pallet-provide-randomness/runtime-benchmarks', + 'pallet-im-online/runtime-benchmarks', + 'pallet-multisig/runtime-benchmarks', + 'pallet-preimage/runtime-benchmarks', + 'pallet-proxy/runtime-benchmarks', + 'pallet-scheduler/runtime-benchmarks', + 'pallet-timestamp/runtime-benchmarks', 'pallet-treasury/runtime-benchmarks', 'pallet-universal-dividend/runtime-benchmarks', - 'common-runtime/runtime-benchmarks', + 'pallet-upgrade-origin/runtime-benchmarks', + 'pallet-utility/runtime-benchmarks', 'sp-runtime/runtime-benchmarks', ] std = [ 'codec/std', + 'common-runtime/std', 'frame-executive/std', 'frame-support/std', 'frame-system-rpc-runtime-api/std', 'frame-system/std', "frame-try-runtime/std", - 'pallet-atomic-swap/std', 'log/std', + 'pallet-atomic-swap/std', 'pallet-authority-discovery/std', 'pallet-authority-members/std', 'pallet-babe/std', @@ -52,8 +71,10 @@ std = [ 'pallet-provide-randomness/std', 'pallet-im-online/std', 'pallet-multisig/std', + "pallet-offences/std", 'pallet-preimage/std', 'pallet-proxy/std', + "pallet-scheduler/std", 'pallet-session/std', 'pallet-sudo/std', 'pallet-universal-dividend/std', @@ -62,8 +83,9 @@ std = [ 'pallet-transaction-payment-rpc-runtime-api/std', 'pallet-transaction-payment/std', 'pallet-treasury/std', - 'common-runtime/std', - 'serde', + 'pallet-utility/std', + "serde/std", + "serde_derive", 'sp-api/std', 'sp-arithmetic/std', 'sp-authority-discovery/std', @@ -128,15 +150,14 @@ codec = { package = "parity-scale-codec", version = "2.3.1", features = ["derive log = { version = "0.4.17", default-features = false } hex-literal = { version = '0.3.1', optional = true } scale-info = { version = "1.0", default-features = false, features = ["derive"] } -serde = { version = "1.0.101", optional = true, features = ["derive"] } +serde = { version = "1.0.101", default-features = false } +serde_derive = { version = "1.0.101", optional = true } # substrate -frame-benchmarking = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', optional = true } frame-try-runtime = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false, optional = true } frame-executive = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } frame-support = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } frame-system = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } -frame-system-benchmarking = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', optional = true } frame-system-rpc-runtime-api = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false} pallet-atomic-swap = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } pallet-authority-discovery = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } @@ -171,3 +192,7 @@ sp-session = { git = 'https://github.com/librelois/substrate.git', branch = 'dun sp-std = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } sp-transaction-pool = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } sp-version = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false } + +# substrate benchmarking +frame-benchmarking = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false, optional = true } +frame-system-benchmarking = { git = 'https://github.com/librelois/substrate.git', branch = 'duniter-monthly-2022-02', default-features = false, optional = true } diff --git a/runtime/gdev/src/lib.rs b/runtime/gdev/src/lib.rs index 08b0f9dde26f28fb71f012523732b4cc3d0e40fc..594091a2a995be3a79f67266ca674b125151d39f 100644 --- a/runtime/gdev/src/lib.rs +++ b/runtime/gdev/src/lib.rs @@ -22,6 +22,10 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +#[cfg(feature = "runtime-benchmarks")] +#[macro_use] +extern crate frame_benchmarking; + pub mod parameters; pub use self::parameters::*; @@ -128,6 +132,7 @@ pub type Executive = frame_executive::Executive< pub type SmithsInstance = Instance2; pub struct BaseCallFilter; +#[cfg(not(feature = "runtime-benchmarks"))] impl Contains<Call> for BaseCallFilter { fn contains(call: &Call) -> bool { !matches!( @@ -144,6 +149,20 @@ impl Contains<Call> for BaseCallFilter { ) } } +#[cfg(feature = "runtime-benchmarks")] +impl Contains<Call> for BaseCallFilter { + fn contains(call: &Call) -> bool { + !matches!( + call, + Call::Membership( + pallet_membership::Call::request_membership { .. } + | pallet_membership::Call::claim_membership { .. } + | pallet_membership::Call::revoke_membership { .. } + ) | Call::Session(_) + | Call::SmithsMembership(pallet_membership::Call::claim_membership { .. }) + ) + } +} /// The type used to represent the kinds of proxying allowed. #[derive( diff --git a/runtime/gdev/src/parameters.rs b/runtime/gdev/src/parameters.rs index 024568027d5c619abd49a5a5c3d8dfc2972de310..274f9ce76ff72693864d4fdcede20921590be57c 100644 --- a/runtime/gdev/src/parameters.rs +++ b/runtime/gdev/src/parameters.rs @@ -26,8 +26,7 @@ use sp_runtime::transaction_validity::TransactionPriority; parameter_types! { pub const BlockHashCount: BlockNumber = 2400; /// We allow for 2 seconds of compute with a 6 second average block time. - pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights - ::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO); + pub BlockWeights: frame_system::limits::BlockWeights = block_weights(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO); pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); pub const SS58Prefix: u16 = 42; diff --git a/runtime/gdev/tests/integration_tests.rs b/runtime/gdev/tests/integration_tests.rs index 9647ceb01149e985592f82f6c46e6e0d71a7a792..5505560b420a9a3cd3a396e0a9debe5d26059b9a 100644 --- a/runtime/gdev/tests/integration_tests.rs +++ b/runtime/gdev/tests/integration_tests.rs @@ -169,16 +169,22 @@ fn test_create_new_account_with_insufficient_balance() { )); let events = System::events(); //println!("{:#?}", events); - assert_eq!(events.len(), 2); + assert_eq!(events.len(), 3); assert_eq!( System::events()[0].event, + Event::System(frame_system::Event::NewAccount { + account: AccountKeyring::Eve.to_account_id(), + }) + ); + assert_eq!( + System::events()[1].event, Event::Balances(pallet_balances::Event::Endowed { account: AccountKeyring::Eve.to_account_id(), free_balance: 400, }) ); assert_eq!( - System::events()[1].event, + System::events()[2].event, Event::Balances(pallet_balances::Event::Transfer { from: AccountKeyring::Alice.to_account_id(), to: AccountKeyring::Eve.to_account_id(), @@ -234,16 +240,22 @@ fn test_create_new_account() { )); let events = System::events(); //println!("{:#?}", events); - assert_eq!(events.len(), 2); + assert_eq!(events.len(), 3); assert_eq!( System::events()[0].event, + Event::System(frame_system::Event::NewAccount { + account: AccountKeyring::Eve.to_account_id(), + }) + ); + assert_eq!( + System::events()[1].event, Event::Balances(pallet_balances::Event::Endowed { account: AccountKeyring::Eve.to_account_id(), free_balance: 500, }) ); assert_eq!( - System::events()[1].event, + System::events()[2].event, Event::Balances(pallet_balances::Event::Transfer { from: AccountKeyring::Alice.to_account_id(), to: AccountKeyring::Eve.to_account_id(), @@ -256,29 +268,23 @@ fn test_create_new_account() { run_to_block(3); let events = System::events(); println!("{:#?}", events); - assert_eq!(events.len(), 4); + assert_eq!(events.len(), 3); assert_eq!( System::events()[0].event, - Event::System(frame_system::Event::NewAccount { - account: AccountKeyring::Eve.to_account_id(), - }) - ); - assert_eq!( - System::events()[1].event, Event::Balances(pallet_balances::Event::Withdraw { who: AccountKeyring::Eve.to_account_id(), amount: 300, }) ); assert_eq!( - System::events()[2].event, + System::events()[1].event, Event::Balances(pallet_balances::Event::Deposit { who: Treasury::account_id(), amount: 300, }) ); assert_eq!( - System::events()[3].event, + System::events()[2].event, Event::Treasury(pallet_treasury::Event::Deposit { value: 300 }) ); assert_eq!( diff --git a/runtime/gtest/src/parameters.rs b/runtime/gtest/src/parameters.rs index df70c7bf699294dda5938e286629f3ffdf9865e2..fb0c3c801ce9b559e50d05320bda3971f9bdf978 100644 --- a/runtime/gtest/src/parameters.rs +++ b/runtime/gtest/src/parameters.rs @@ -26,8 +26,7 @@ use sp_runtime::transaction_validity::TransactionPriority; parameter_types! { pub const BlockHashCount: BlockNumber = 2400; /// We allow for 2 seconds of compute with a 6 second average block time. - pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights - ::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO); + pub BlockWeights: frame_system::limits::BlockWeights = block_weights(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO); pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); pub const SS58Prefix: u16 = 42; diff --git a/scripts/cross-build-arm.sh b/scripts/cross-build-arm.sh index 23119cc9def7d2ff94a89702fe1576756be4255e..a33c3921d1b0224f220d3232d625808b5c44ade1 100755 --- a/scripts/cross-build-arm.sh +++ b/scripts/cross-build-arm.sh @@ -4,4 +4,4 @@ docker run --rm -it \ --env BINDGEN_EXTRA_CLANG_ARGS="--sysroot=/usr/arm-linux-gnueabihf -D__ARM_PCS_VFP -mfpu=vfp -mfloat-abi=hard" \ --env CARGO_HOME=/home/rust/src/arm-build \ -v "$(pwd)":/home/rust/src duniter-v2s-arm-builder \ - cargo build --target=armv7-unknown-linux-gnueabihf --release + cargo build --target=armv7-unknown-linux-gnueabihf --release "$@"