diff --git a/Cargo.lock b/Cargo.lock index 97f877f894414a3ded87e00d6d00d9204b31a5c0..2bdafcac47f4c98d334970549ac0f53612045b57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -832,10 +832,10 @@ dependencies = [ "log", "pallet-authority-members", "pallet-babe", - "pallet-balances", "pallet-certification", "pallet-duniter-account", "pallet-duniter-wot", + "pallet-grandpa", "pallet-identity", "pallet-membership", "pallet-provide-randomness", diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 490178cf7a009985e55b2bda325401e6c4cd0f72..9d4a1b324c6e917ee7e5508f23ffdc3977904af2 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -24,10 +24,10 @@ 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-provide-randomness/std', @@ -79,7 +79,7 @@ default-features = false git = 'https://github.com/librelois/substrate.git' branch = 'duniter-monthly-2022-02' -[dependencies.pallet-balances] +[dependencies.pallet-grandpa] default-features = false git = 'https://github.com/librelois/substrate.git' branch = 'duniter-monthly-2022-02' diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index 9cabef4bcba95ed1a0be40c2c92186a4b587f60c..9ae9bbbd2ff604460df330dfdba0af2f917bc238 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -133,7 +133,7 @@ macro_rules! pallets_config { type HandleEquivocation = pallet_babe::EquivocationHandler<Self::KeyOwnerIdentification, Offences, ReportLongevity>; - type WeightInfo = (); + type WeightInfo = common_runtime::weights::pallet_babe::WeightInfo<Runtime>; type MaxAuthorities = MaxAuthorities; } @@ -252,7 +252,7 @@ macro_rules! pallets_config { type HandleEquivocation = (); - type WeightInfo = (); + type WeightInfo = common_runtime::weights::pallet_grandpa::WeightInfo<Runtime>; type MaxAuthorities = MaxAuthorities; } diff --git a/runtime/common/src/weights.rs b/runtime/common/src/weights.rs index 300344c39de2a5db6e6fa817494cd3a2e89a3d3f..664b681d730640915f519e4fd9d1f4661daaa931 100644 --- a/runtime/common/src/weights.rs +++ b/runtime/common/src/weights.rs @@ -14,4 +14,5 @@ // 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; +pub mod pallet_babe; +pub mod pallet_grandpa; diff --git a/runtime/common/src/weights/pallet_babe.rs b/runtime/common/src/weights/pallet_babe.rs new file mode 100644 index 0000000000000000000000000000000000000000..ecea61a645894ae6b789a6ff0ae22dbdcdf52cc3 --- /dev/null +++ b/runtime/common/src/weights/pallet_babe.rs @@ -0,0 +1,51 @@ +// 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/>. + +//! Manual weights for the GRANDPA Pallet in duniter runtimes +//! This file was not auto-generated. + +use frame_support::{ + traits::Get, + weights::{ + constants::{WEIGHT_PER_MICROS, WEIGHT_PER_NANOS}, + Weight, + }, +}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_babe`. +pub struct WeightInfo<T>(PhantomData<T>); +impl<T: frame_system::Config> pallet_babe::WeightInfo for WeightInfo<T> { + fn plan_config_change() -> Weight { + T::DbWeight::get().writes(1) + } + + fn report_equivocation(validator_count: u32) -> Weight { + // we take the validator set count from the membership proof to + // calculate the weight but we set a floor of 100 validators. + let validator_count = validator_count.max(100) as u64; + + // checking membership proof + (35 * WEIGHT_PER_MICROS) + .saturating_add((175 * WEIGHT_PER_NANOS).saturating_mul(validator_count)) + .saturating_add(T::DbWeight::get().reads(5)) + // check equivocation proof + .saturating_add(110 * WEIGHT_PER_MICROS) + // report offence + .saturating_add(110 * WEIGHT_PER_MICROS) + .saturating_add(T::DbWeight::get().writes(3)) + } +} diff --git a/runtime/common/src/weights/pallet_balances.rs b/runtime/common/src/weights/pallet_balances.rs deleted file mode 100644 index 00733f0ca4d171605604242821cd858466a80a08..0000000000000000000000000000000000000000 --- a/runtime/common/src/weights/pallet_balances.rs +++ /dev/null @@ -1,81 +0,0 @@ -// 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)) - } -} diff --git a/runtime/common/src/weights/pallet_grandpa.rs b/runtime/common/src/weights/pallet_grandpa.rs new file mode 100644 index 0000000000000000000000000000000000000000..06200adc13de36ba51f762417f5f85e392ac360a --- /dev/null +++ b/runtime/common/src/weights/pallet_grandpa.rs @@ -0,0 +1,53 @@ +// 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/>. + +//! Manual weights for the GRANDPA Pallet in duniter runtimes +//! This file was not auto-generated. + +use frame_support::{ + traits::Get, + weights::{ + constants::{WEIGHT_PER_MICROS, WEIGHT_PER_NANOS}, + Weight, + }, +}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_grandpa`. +pub struct WeightInfo<T>(PhantomData<T>); +impl<T: frame_system::Config> pallet_grandpa::WeightInfo for WeightInfo<T> { + fn report_equivocation(validator_count: u32) -> Weight { + // we take the validator set count from the membership proof to + // calculate the weight but we set a floor of 100 validators. + let validator_count = validator_count.max(100) as u64; + + // checking membership proof + (35 * WEIGHT_PER_MICROS) + .saturating_add((175 * WEIGHT_PER_NANOS).saturating_mul(validator_count)) + .saturating_add(T::DbWeight::get().reads(5)) + // check equivocation proof + .saturating_add(95 * WEIGHT_PER_MICROS) + // report offence + .saturating_add(110 * WEIGHT_PER_MICROS) + .saturating_add(T::DbWeight::get().writes(3)) + // fetching set id -> session index mappings + .saturating_add(T::DbWeight::get().reads(2)) + } + + fn note_stalled() -> Weight { + (3 * WEIGHT_PER_MICROS).saturating_add(T::DbWeight::get().writes(1)) + } +}