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

feat(pallet_duniter_account): add weights info

parent 483a1570
No related branches found
No related tags found
1 merge request!140Duniter-account pallet benchmark
...@@ -20,9 +20,11 @@ ...@@ -20,9 +20,11 @@
mod benchmarking; mod benchmarking;
mod types; mod types;
pub mod weights;
pub use pallet::*; pub use pallet::*;
pub use types::*; pub use types::*;
pub use weights::WeightInfo;
use frame_support::pallet_prelude::*; use frame_support::pallet_prelude::*;
use frame_support::traits::{OnUnbalanced, StoredMap}; use frame_support::traits::{OnUnbalanced, StoredMap};
...@@ -61,6 +63,8 @@ pub mod pallet { ...@@ -61,6 +63,8 @@ pub mod pallet {
type NewAccountPrice: Get<Self::Balance>; type NewAccountPrice: Get<Self::Balance>;
/// The overarching event type. /// The overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Type representing the weight of this pallet
type WeightInfo: WeightInfo;
} }
// STORAGE // // STORAGE //
...@@ -162,7 +166,9 @@ pub mod pallet { ...@@ -162,7 +166,9 @@ pub mod pallet {
H256(T::AccountIdToSalt::convert(account_id.clone())), H256(T::AccountIdToSalt::convert(account_id.clone())),
); );
PendingRandomIdAssignments::<T>::insert(request_id, account_id); PendingRandomIdAssignments::<T>::insert(request_id, account_id);
total_weight += Weight::from_ref_time(100_000); total_weight += <T as pallet::Config>::WeightInfo::on_initialize_sufficient(
T::MaxNewAccountsPerBlock::get(),
);
} else { } else {
// If the account is not self-sufficient, it must pay the account creation fees // If the account is not self-sufficient, it must pay the account creation fees
let account_data = frame_system::Pallet::<T>::get(&account_id); let account_data = frame_system::Pallet::<T>::get(&account_id);
...@@ -198,7 +204,10 @@ pub mod pallet { ...@@ -198,7 +204,10 @@ pub mod pallet {
H256(T::AccountIdToSalt::convert(account_id.clone())), H256(T::AccountIdToSalt::convert(account_id.clone())),
); );
PendingRandomIdAssignments::<T>::insert(request_id, account_id); PendingRandomIdAssignments::<T>::insert(request_id, account_id);
total_weight += Weight::from_ref_time(200_000); total_weight +=
<T as pallet::Config>::WeightInfo::on_initialize_with_balance(
T::MaxNewAccountsPerBlock::get(),
);
} }
} else { } else {
// The charges could not be deducted, we must destroy the account // The charges could not be deducted, we must destroy the account
...@@ -213,7 +222,9 @@ pub mod pallet { ...@@ -213,7 +222,9 @@ pub mod pallet {
T::OnUnbalanced::on_unbalanced(pallet_balances::NegativeImbalance::new( T::OnUnbalanced::on_unbalanced(pallet_balances::NegativeImbalance::new(
balance_to_suppr, balance_to_suppr,
)); ));
total_weight += Weight::from_ref_time(300_000); total_weight += <T as pallet::Config>::WeightInfo::on_initialize_no_balance(
T::MaxNewAccountsPerBlock::get(),
);
} }
} }
} }
...@@ -236,9 +247,9 @@ where ...@@ -236,9 +247,9 @@ where
who: account_id, who: account_id,
random_id: randomness, random_id: randomness,
}); });
Weight::from_ref_time(200_000) <T as pallet::Config>::WeightInfo::on_filled_randomness_pending()
} else { } else {
Weight::from_ref_time(100_000) <T as pallet::Config>::WeightInfo::on_filled_randomness_no_pending()
} }
} }
} }
......
// 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_sufficient(i: u32) -> Weight;
fn on_initialize_with_balance(i: u32) -> Weight;
fn on_initialize_no_balance(i: u32) -> Weight;
fn on_filled_randomness_pending() -> Weight;
fn on_filled_randomness_no_pending() -> Weight;
}
// Insecure weights implementation, use it for tests only!
impl WeightInfo for () {
// Storage: Account PendingNewAccounts (r:1 w:0)
// Storage: ProvideRandomness RequestIdProvider (r:1 w:1)
// Storage: ProvideRandomness RequestsIds (r:1 w:1)
// Storage: ProvideRandomness CounterForRequestsIds (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)
// Storage: Account PendingRandomIdAssignments (r:0 w:1)
/// The range of component `i` is `[0, 1]`.
fn on_initialize_sufficient(i: u32) -> Weight {
// Minimum execution time: 12_958 nanoseconds.
Weight::from_ref_time(14_907_902 as u64)
// Standard Error: 550_025
.saturating_add(Weight::from_ref_time(79_482_297 as u64).saturating_mul(i as u64))
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().reads((6 as u64).saturating_mul(i as u64)))
.saturating_add(RocksDbWeight::get().writes((6 as u64).saturating_mul(i as u64)))
}
// Storage: Account PendingNewAccounts (r:1 w:0)
// Storage: ProvideRandomness RequestIdProvider (r:1 w:1)
// Storage: ProvideRandomness RequestsIds (r:1 w:1)
// Storage: ProvideRandomness CounterForRequestsIds (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)
// Storage: Account PendingRandomIdAssignments (r:0 w:1)
/// The range of component `i` is `[0, 1]`.
fn on_initialize_with_balance(i: u32) -> Weight {
// Minimum execution time: 12_965 nanoseconds.
Weight::from_ref_time(16_754_718 as u64)
// Standard Error: 1_790_537
.saturating_add(Weight::from_ref_time(164_043_481 as u64).saturating_mul(i as u64))
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().reads((6 as u64).saturating_mul(i as u64)))
.saturating_add(RocksDbWeight::get().writes((6 as u64).saturating_mul(i as u64)))
}
// Storage: Account PendingNewAccounts (r:1 w:0)
/// The range of component `i` is `[0, 1]`.
fn on_initialize_no_balance(i: u32) -> Weight {
// Minimum execution time: 12_912 nanoseconds.
Weight::from_ref_time(13_846_469 as u64)
// Standard Error: 115_598
.saturating_add(Weight::from_ref_time(67_524_530 as u64).saturating_mul(i as u64))
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(i as u64)))
}
// Storage: Account PendingRandomIdAssignments (r:1 w:1)
fn on_filled_randomness_pending() -> Weight {
// Minimum execution time: 66_963 nanoseconds.
Weight::from_ref_time(69_757_000 as u64)
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
// Storage: Account PendingRandomIdAssignments (r:1 w:0)
fn on_filled_randomness_no_pending() -> Weight {
// Minimum execution time: 16_088 nanoseconds.
Weight::from_ref_time(27_963_000 as u64)
.saturating_add(RocksDbWeight::get().reads(1 as u64))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment