diff --git a/Cargo.lock b/Cargo.lock index c7d6a348fbb5252a66e25980262d3e402ef0c48e..418ddf85cd8d4b02bd8bfcbd928347d6d97c8fad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -845,6 +845,7 @@ dependencies = [ "frame-support", "frame-system", "pallet-authority-members", + "pallet-balances", "pallet-certification", "pallet-duniter-wot", "pallet-identity", diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 2d94dcaf24215b13325fae6096c77d9cd559f938..65099cd38bed685572a4fc1b6fc29c185a843a12 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -22,6 +22,7 @@ std = [ 'frame-support/std', 'frame-system/std', 'pallet-authority-members/std', + 'pallet-balances/std', 'pallet-certification/std', 'pallet-duniter-wot/std', 'pallet-identity/std', @@ -66,6 +67,11 @@ default-features = false git = 'https://github.com/librelois/substrate.git' branch = 'duniter-monthly-2022-01' +[dependencies.pallet-balances] +default-features = false +git = 'https://github.com/librelois/substrate.git' +branch = 'duniter-monthly-2022-01' + [dependencies.pallet-session] default-features = false features = ["historical"] diff --git a/runtime/common/src/constants.rs b/runtime/common/src/constants.rs index dfa64dee2c9bee7a8970b7748a307ce12cf57f0e..d7f1c058cbec221ea1d4d96fdf66a267abc0040e 100644 --- a/runtime/common/src/constants.rs +++ b/runtime/common/src/constants.rs @@ -40,6 +40,13 @@ 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: 25 * frame_support::weights::constants::WEIGHT_PER_MICROS, // ~25 µs + write: 100 * 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); diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 63917b98fd54d6877a3d1cd711336a6ba80a8b0c..3bf42004d0161d8284ae1135d72549a19371ab7d 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -23,6 +23,7 @@ pub mod fees; pub mod handlers; mod pallets_config; pub mod providers; +pub mod weights; pub use pallet_identity::{GenesisIdty, IdtyName, IdtyStatus, IdtyValue}; pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index 79c92c3eb6cf26ca77c0a920009d0dd188748192..f8c9f43eaa15267cbe257d7654daca2ee834736a 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -55,7 +55,7 @@ macro_rules! pallets_config { /// Maximum number of block number to block hash mappings to keep (oldest pruned first). type BlockHashCount = BlockHashCount; /// The weight of database operations that the runtime can invoke. - type DbWeight = RocksDbWeight; + type DbWeight = DbWeight; /// Version of the runtime. type Version = Version; /// Converts a module to the index of the module in `construct_runtime!`. @@ -160,7 +160,7 @@ macro_rules! pallets_config { type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; - type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>; + type WeightInfo = common_runtime::weights::pallet_balances::WeightInfo<Runtime>; } impl pallet_transaction_payment::Config for Runtime { diff --git a/runtime/common/src/weights.rs b/runtime/common/src/weights.rs new file mode 100644 index 0000000000000000000000000000000000000000..300344c39de2a5db6e6fa817494cd3a2e89a3d3f --- /dev/null +++ b/runtime/common/src/weights.rs @@ -0,0 +1,17 @@ +// Copyright 2021 Axiom-Team +// +// This file is part of Substrate-Libre-Currency. +// +// Substrate-Libre-Currency 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, +// 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/>. + +pub mod pallet_balances; diff --git a/runtime/common/src/weights/pallet_balances.rs b/runtime/common/src/weights/pallet_balances.rs new file mode 100644 index 0000000000000000000000000000000000000000..00733f0ca4d171605604242821cd858466a80a08 --- /dev/null +++ b/runtime/common/src/weights/pallet_balances.rs @@ -0,0 +1,81 @@ +// Copyright 2021 Axiom-Team +// +// This file is part of Substrate-Libre-Currency. +// +// Substrate-Libre-Currency 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, +// 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/>. + +//! Manually written file for temporary weights (polkadot x 10) + +// TODO regenerate thi file with benchmarks: +// +// Executed Command: +// target/release/duniter +// benchmark +// --chain=dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_balances +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./file_header.txt +// --output=./runtime/gdev/src/weights/ + +#![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> { + fn transfer() -> Weight { + (688_850_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn transfer_keep_alive() -> Weight { + (514_410_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn set_balance_creating() -> Weight { + (277_360_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn set_balance_killing() -> Weight { + (329_990_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn force_transfer() -> Weight { + (674_510_000 as Weight) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn transfer_all() -> Weight { + (633_590_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 force_unreserve() -> Weight { + (277_660_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } +}