mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 13:27:57 +00:00
Use proper weights in the pallet-template (#13817)
* benchmarking to generate weights file * add the calculated weights in the extrinsics * use benchmarking v2 syntax to generate the weights * minor syntax change when benchmarking * added WeightInfo in the mock to pass tests * minor cargo fmt format changes
This commit is contained in:
@@ -13,9 +13,12 @@ mod tests;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
mod benchmarking;
|
||||
pub mod weights;
|
||||
pub use weights::*;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
@@ -27,6 +30,8 @@ pub mod pallet {
|
||||
pub trait Config: frame_system::Config {
|
||||
/// Because this pallet emits events, it depends on the runtime's definition of an event.
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
/// Type representing the weight of this pallet
|
||||
type WeightInfo: WeightInfo;
|
||||
}
|
||||
|
||||
// The pallet's runtime storage items.
|
||||
@@ -64,7 +69,7 @@ pub mod pallet {
|
||||
/// An example dispatchable that takes a singles value as a parameter, writes the value to
|
||||
/// storage and emits an event. This function must be dispatched by a signed extrinsic.
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())]
|
||||
#[pallet::weight(T::WeightInfo::do_something())]
|
||||
pub fn do_something(origin: OriginFor<T>, something: u32) -> DispatchResult {
|
||||
// Check that the extrinsic was signed and get the signer.
|
||||
// This function will return an error if the extrinsic is not signed.
|
||||
@@ -82,7 +87,7 @@ pub mod pallet {
|
||||
|
||||
/// An example dispatchable that may throw a custom error.
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1).ref_time())]
|
||||
#[pallet::weight(T::WeightInfo::cause_error())]
|
||||
pub fn cause_error(origin: OriginFor<T>) -> DispatchResult {
|
||||
let _who = ensure_signed(origin)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user