Skip to content
Snippets Groups Projects
Unverified Commit a010e531 authored by bgallois's avatar bgallois
Browse files

feat(pallet_provide_randomness): add weights info

parent 10dd4b86
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
mod benchmarking; mod benchmarking;
mod types; mod types;
pub mod weights;
use frame_support::pallet_prelude::Weight; use frame_support::pallet_prelude::Weight;
use sp_core::H256; use sp_core::H256;
...@@ -28,6 +29,7 @@ use sp_std::prelude::*; ...@@ -28,6 +29,7 @@ use sp_std::prelude::*;
pub use pallet::*; pub use pallet::*;
pub use types::*; pub use types::*;
pub use weights::WeightInfo;
pub type RequestId = u64; pub type RequestId = u64;
...@@ -88,6 +90,8 @@ pub mod pallet { ...@@ -88,6 +90,8 @@ pub mod pallet {
type RandomnessFromOneEpochAgo: Randomness<H256, Self::BlockNumber>; type RandomnessFromOneEpochAgo: Randomness<H256, Self::BlockNumber>;
/// The overarching event type. /// The overarching event type.
type RuntimeEvent: From<Event> + IsType<<Self as frame_system::Config>::RuntimeEvent>; type RuntimeEvent: From<Event> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Type representing the weight of this pallet
type WeightInfo: WeightInfo;
} }
// STORAGE // // STORAGE //
...@@ -143,7 +147,7 @@ pub mod pallet { ...@@ -143,7 +147,7 @@ pub mod pallet {
#[pallet::call] #[pallet::call]
impl<T: Config> Pallet<T> { impl<T: Config> Pallet<T> {
/// Request a randomness /// Request a randomness
#[pallet::weight(500_000_000)] #[pallet::weight(T::WeightInfo::request())]
pub fn request( pub fn request(
origin: OriginFor<T>, origin: OriginFor<T>,
randomness_type: RandomnessType, randomness_type: RandomnessType,
...@@ -168,7 +172,7 @@ pub mod pallet { ...@@ -168,7 +172,7 @@ pub mod pallet {
#[pallet::hooks] #[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> { impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: T::BlockNumber) -> Weight { fn on_initialize(_: T::BlockNumber) -> Weight {
let request_weight = Weight::from_ref_time(100_000); let request_weight = T::WeightInfo::on_initialize(T::MaxRequests::get());
let mut total_weight = Weight::zero(); let mut total_weight = Weight::zero();
......
// Copyright 2021-2023 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(i: u32) -> Weight;
fn request() -> Weight;
}
// Insecure weights implementation, use it for tests only!
impl WeightInfo for () {
// Storage: ProvideRandomness CounterForRequestsIds (r:1 w:1)
// Storage: ProvideRandomness RequestIdProvider (r:1 w:1)
// Storage: ProvideRandomness RequestsIds (r:1 w:1)
// Storage: Babe EpochIndex (r:1 w:0)
// Storage: ProvideRandomness NexEpochHookIn (r:1 w:0)
// Storage: ProvideRandomness RequestsReadyAtEpoch (r:1 w:1)
fn request() -> Weight {
// Minimum execution time: 321_822 nanoseconds.
Weight::from_ref_time(338_919_000 as u64)
.saturating_add(RocksDbWeight::get().reads(6 as u64))
.saturating_add(RocksDbWeight::get().writes(4 as u64))
}
// Storage: ProvideRandomness RequestsReadyAtNextBlock (r:1 w:1)
// Storage: Babe AuthorVrfRandomness (r:1 w:0)
// Storage: ProvideRandomness RequestsIds (r:1 w:1)
// Storage: ProvideRandomness CounterForRequestsIds (r:1 w:1)
// Storage: Account PendingRandomIdAssignments (r:1 w:0)
// Storage: ProvideRandomness NexEpochHookIn (r:1 w:1)
/// The range of component `i` is `[1, 100]`.
fn on_initialize(i: u32) -> Weight {
// Minimum execution time: 175_645 nanoseconds.
Weight::from_ref_time(461_442_906 as u64)
// Standard Error: 1_523_561
.saturating_add(Weight::from_ref_time(43_315_015 as u64).saturating_mul(i as u64))
.saturating_add(RocksDbWeight::get().reads(4 as u64))
.saturating_add(RocksDbWeight::get().reads((2 as u64).saturating_mul(i as u64)))
.saturating_add(RocksDbWeight::get().writes(3 as u64))
.saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(i as u64)))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment