Skip to content
Snippets Groups Projects
Commit 70ac32cd authored by Benjamin Gallois's avatar Benjamin Gallois Committed by Hugo Trentesaux
Browse files

Oneshot account pallet benchmark (!153)

* feat(runtimes): use our benchmarks for pallet oneshot_account

* feat(pallet_oneshot_account): add weights info

* fix(pallet_oneshot_account): remove unecessary where clause
parent 7a128091
No related branches found
No related tags found
1 merge request!153Oneshot account pallet benchmark
Pipeline #25782 failed
...@@ -29,10 +29,11 @@ use crate::Pallet; ...@@ -29,10 +29,11 @@ use crate::Pallet;
const SEED: u32 = 0; const SEED: u32 = 0;
benchmarks! { benchmarks! {
where_clause { where where_clause {
where
T: pallet_balances::Config, T: pallet_balances::Config,
T::Balance: From<u64>, T::Balance: From<u64>,
<T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance> <T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance>+From<T::Balance>
} }
create_oneshot_account { create_oneshot_account {
let existential_deposit = T::ExistentialDeposit::get(); let existential_deposit = T::ExistentialDeposit::get();
...@@ -51,11 +52,6 @@ benchmarks! { ...@@ -51,11 +52,6 @@ benchmarks! {
assert_eq!(Balances::<T>::free_balance(&caller), transfer_amount); assert_eq!(Balances::<T>::free_balance(&caller), transfer_amount);
assert_eq!(OneshotAccounts::<T>::get(&recipient), Some(transfer_amount.into())); assert_eq!(OneshotAccounts::<T>::get(&recipient), Some(transfer_amount.into()));
} }
where_clause { where
T: pallet_balances::Config,
T::Balance: From<u64>,
<T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance>+From<T::Balance>
}
consume_oneshot_account { consume_oneshot_account {
let existential_deposit = T::ExistentialDeposit::get(); let existential_deposit = T::ExistentialDeposit::get();
let caller: T::AccountId = whitelisted_caller(); let caller: T::AccountId = whitelisted_caller();
...@@ -85,11 +81,6 @@ benchmarks! { ...@@ -85,11 +81,6 @@ benchmarks! {
existential_deposit.saturating_mul((3).into()) existential_deposit.saturating_mul((3).into())
); );
} }
where_clause { where
T: pallet_balances::Config,
T::Balance: From<u64>,
<T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance>+From<T::Balance>
}
consume_oneshot_account_with_remaining { consume_oneshot_account_with_remaining {
let existential_deposit = T::ExistentialDeposit::get(); let existential_deposit = T::ExistentialDeposit::get();
let caller: T::AccountId = whitelisted_caller(); let caller: T::AccountId = whitelisted_caller();
......
...@@ -21,10 +21,12 @@ mod check_nonce; ...@@ -21,10 +21,12 @@ mod check_nonce;
#[cfg(test)] #[cfg(test)]
mod mock; mod mock;
mod types; mod types;
pub mod weights;
pub use check_nonce::CheckNonce; pub use check_nonce::CheckNonce;
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::{ use frame_support::traits::{
...@@ -56,6 +58,8 @@ pub mod pallet { ...@@ -56,6 +58,8 @@ pub mod pallet {
type Currency: Currency<Self::AccountId>; type Currency: Currency<Self::AccountId>;
type InnerOnChargeTransaction: OnChargeTransaction<Self>; type InnerOnChargeTransaction: OnChargeTransaction<Self>;
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 //
...@@ -127,7 +131,7 @@ pub mod pallet { ...@@ -127,7 +131,7 @@ pub mod pallet {
/// - `balance`: The balance to be transfered to this oneshot account. /// - `balance`: The balance to be transfered to this oneshot account.
/// ///
/// Origin account is kept alive. /// Origin account is kept alive.
#[pallet::weight(500_000_000)] #[pallet::weight(T::WeightInfo::create_oneshot_account())]
pub fn create_oneshot_account( pub fn create_oneshot_account(
origin: OriginFor<T>, origin: OriginFor<T>,
dest: <T::Lookup as StaticLookup>::Source, dest: <T::Lookup as StaticLookup>::Source,
...@@ -165,7 +169,7 @@ pub mod pallet { ...@@ -165,7 +169,7 @@ pub mod pallet {
/// - `block_height`: Must be a recent block number. The limit is `BlockHashCount` in the past. (this is to prevent replay attacks) /// - `block_height`: Must be a recent block number. The limit is `BlockHashCount` in the past. (this is to prevent replay attacks)
/// - `dest`: The destination account. /// - `dest`: The destination account.
/// - `dest_is_oneshot`: If set to `true`, then a oneshot account is created at `dest`. Else, `dest` has to be an existing account. /// - `dest_is_oneshot`: If set to `true`, then a oneshot account is created at `dest`. Else, `dest` has to be an existing account.
#[pallet::weight(500_000_000)] #[pallet::weight(T::WeightInfo::consume_oneshot_account())]
pub fn consume_oneshot_account( pub fn consume_oneshot_account(
origin: OriginFor<T>, origin: OriginFor<T>,
block_height: T::BlockNumber, block_height: T::BlockNumber,
...@@ -223,7 +227,7 @@ pub mod pallet { ...@@ -223,7 +227,7 @@ pub mod pallet {
/// - `dest2`: The second destination account. /// - `dest2`: The second destination account.
/// - `dest2_is_oneshot`: If set to `true`, then a oneshot account is created at `dest2`. Else, `dest2` has to be an existing account. /// - `dest2_is_oneshot`: If set to `true`, then a oneshot account is created at `dest2`. Else, `dest2` has to be an existing account.
/// - `balance1`: The amount transfered to `dest`, the leftover being transfered to `dest2`. /// - `balance1`: The amount transfered to `dest`, the leftover being transfered to `dest2`.
#[pallet::weight(500_000_000)] #[pallet::weight(T::WeightInfo::consume_oneshot_account_with_remaining())]
pub fn consume_oneshot_account_with_remaining( pub fn consume_oneshot_account_with_remaining(
origin: OriginFor<T>, origin: OriginFor<T>,
block_height: T::BlockNumber, block_height: T::BlockNumber,
......
...@@ -104,6 +104,7 @@ impl pallet_oneshot_account::Config for Test { ...@@ -104,6 +104,7 @@ impl pallet_oneshot_account::Config for Test {
type Currency = Balances; type Currency = Balances;
type InnerOnChargeTransaction = CurrencyAdapter<Balances, HandleFees>; type InnerOnChargeTransaction = CurrencyAdapter<Balances, HandleFees>;
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
} }
pub struct HandleFees; pub struct HandleFees;
......
...@@ -186,6 +186,7 @@ macro_rules! pallets_config { ...@@ -186,6 +186,7 @@ macro_rules! pallets_config {
type Currency = Balances; type Currency = Balances;
type RuntimeEvent = RuntimeEvent; type RuntimeEvent = RuntimeEvent;
type InnerOnChargeTransaction = CurrencyAdapter<Balances, HandleFees>; type InnerOnChargeTransaction = CurrencyAdapter<Balances, HandleFees>;
type WeightInfo = common_runtime::weights::pallet_oneshot_account::WeightInfo<Runtime>;
} }
// CONSENSUS // // CONSENSUS //
......
...@@ -33,6 +33,7 @@ pub mod pallet_upgrade_origin; ...@@ -33,6 +33,7 @@ pub mod pallet_upgrade_origin;
pub mod pallet_provide_randomness; pub mod pallet_provide_randomness;
pub mod pallet_identity; pub mod pallet_identity;
pub mod pallet_duniter_account; pub mod pallet_duniter_account;
pub mod pallet_oneshot_account;
pub mod pallet_certification_cert; pub mod pallet_certification_cert;
pub mod pallet_certification_smith_cert; pub mod pallet_certification_smith_cert;
pub mod paritydb_weights; pub mod paritydb_weights;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment