feat: Rebrand Polkadot/Substrate references to PezkuwiChain
This commit systematically rebrands various references from Parity Technologies' Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk. Key changes include: - Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks. - Modified internal documentation and code comments to reflect PezkuwiChain naming and structure. - Replaced direct references to with or specific paths within the for XCM, Pezkuwi, and other modules. - Cleaned up deprecated issue and PR references in various and files, particularly in and modules. - Adjusted image and logo URLs in documentation to point to PezkuwiChain assets. - Removed or rephrased comments related to external Polkadot/Substrate PRs and issues. This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Glutton pallet benchmarking.
|
||||
//!
|
||||
//! Has to be compiled and run twice to calibrate on new hardware.
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
use pezframe_benchmarking::v2::*;
|
||||
use pezframe_support::{pezpallet_prelude::*, weights::constants::*};
|
||||
use pezframe_system::RawOrigin;
|
||||
use pezsp_runtime::{traits::One, Perbill};
|
||||
|
||||
use crate::*;
|
||||
|
||||
#[benchmarks]
|
||||
mod benchmarks {
|
||||
use super::*;
|
||||
|
||||
#[benchmark]
|
||||
fn initialize_pallet_grow(n: Linear<0, 1_000>) -> Result<(), BenchmarkError> {
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::initialize_pallet(RawOrigin::Root.into(), n, None)?;
|
||||
}
|
||||
|
||||
assert_eq!(TrashDataCount::<T>::get(), n);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn initialize_pallet_shrink(n: Linear<0, 1_000>) -> Result<(), BenchmarkError> {
|
||||
Pallet::<T>::initialize_pallet(RawOrigin::Root.into(), n, None)?;
|
||||
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::initialize_pallet(RawOrigin::Root.into(), 0, Some(n))?;
|
||||
}
|
||||
|
||||
assert_eq!(TrashDataCount::<T>::get(), 0);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn waste_ref_time_iter(i: Linear<0, 100_000>) {
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::waste_ref_time_iter(vec![0u8; 64], i);
|
||||
}
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn waste_proof_size_some(i: Linear<0, 5_000>) {
|
||||
(0..5000).for_each(|i| TrashData::<T>::insert(i, [i as u8; 1024]));
|
||||
|
||||
#[block]
|
||||
{
|
||||
(0..i).for_each(|i| {
|
||||
TrashData::<T>::get(i);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// For manual verification only.
|
||||
#[benchmark]
|
||||
fn on_idle_high_proof_waste() {
|
||||
(0..5000).for_each(|i| TrashData::<T>::insert(i, [i as u8; 1024]));
|
||||
let _ = Pallet::<T>::set_compute(RawOrigin::Root.into(), One::one());
|
||||
let _ = Pallet::<T>::set_storage(RawOrigin::Root.into(), One::one());
|
||||
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::on_idle(
|
||||
pezframe_system::Pallet::<T>::block_number(),
|
||||
Weight::from_parts(WEIGHT_REF_TIME_PER_MILLIS * 100, WEIGHT_PROOF_SIZE_PER_MB * 5),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// For manual verification only.
|
||||
#[benchmark]
|
||||
fn on_idle_low_proof_waste() {
|
||||
(0..5000).for_each(|i| TrashData::<T>::insert(i, [i as u8; 1024]));
|
||||
let _ = Pallet::<T>::set_compute(RawOrigin::Root.into(), One::one());
|
||||
let _ = Pallet::<T>::set_storage(RawOrigin::Root.into(), One::one());
|
||||
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::on_idle(
|
||||
pezframe_system::Pallet::<T>::block_number(),
|
||||
Weight::from_parts(WEIGHT_REF_TIME_PER_MILLIS * 100, WEIGHT_PROOF_SIZE_PER_KB * 20),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn empty_on_idle() {
|
||||
// Enough weight to do nothing.
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::on_idle(
|
||||
pezframe_system::Pallet::<T>::block_number(),
|
||||
T::WeightInfo::empty_on_idle(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn set_compute() {
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Root, FixedU64::from_perbill(Perbill::from_percent(50)));
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn set_storage() {
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Root, FixedU64::from_perbill(Perbill::from_percent(50)));
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite! {
|
||||
Pallet,
|
||||
mock::new_test_ext(),
|
||||
mock::Test
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,456 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! # WARNING
|
||||
//!
|
||||
//! **DO NOT USE ON VALUE-BEARING CHAINS. THIS PALLET IS ONLY INTENDED FOR TESTING USAGE.**
|
||||
//!
|
||||
//! # Glutton Pallet
|
||||
//!
|
||||
//! Pallet that consumes `ref_time` and `proof_size` of a block. Based on the `Compute` and
|
||||
//! `Storage` parameters the pallet consumes the adequate amount of weight.
|
||||
|
||||
#![deny(missing_docs)]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
mod benchmarking;
|
||||
#[cfg(test)]
|
||||
mod mock;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
pub mod weights;
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::{vec, vec::Vec};
|
||||
use blake2::{Blake2b512, Digest};
|
||||
use pezframe_support::{pezpallet_prelude::*, weights::WeightMeter, DefaultNoBound};
|
||||
use pezframe_system::pezpallet_prelude::*;
|
||||
use pezsp_io::hashing::twox_256;
|
||||
use pezsp_runtime::{traits::Zero, FixedPointNumber, FixedU64};
|
||||
|
||||
pub use pallet::*;
|
||||
pub use weights::WeightInfo;
|
||||
|
||||
/// The size of each value in the `TrashData` storage in bytes.
|
||||
pub const VALUE_SIZE: usize = 1024;
|
||||
/// Max number of entries for the `TrashData` map.
|
||||
pub const MAX_TRASH_DATA_ENTRIES: u32 = 65_000;
|
||||
/// Hard limit for any other resource limit (in units).
|
||||
pub const RESOURCE_HARD_LIMIT: FixedU64 = FixedU64::from_u32(10);
|
||||
|
||||
#[pezframe_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: pezframe_system::Config {
|
||||
/// The overarching event type.
|
||||
#[allow(deprecated)]
|
||||
type RuntimeEvent: From<Event> + IsType<<Self as pezframe_system::Config>::RuntimeEvent>;
|
||||
|
||||
/// The admin origin that can set computational limits and initialize the pallet.
|
||||
type AdminOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Weight information for this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event {
|
||||
/// The pallet has been (re)initialized.
|
||||
PalletInitialized {
|
||||
/// Whether the pallet has been re-initialized.
|
||||
reinit: bool,
|
||||
},
|
||||
/// The computation limit has been updated.
|
||||
ComputationLimitSet {
|
||||
/// The computation limit.
|
||||
compute: FixedU64,
|
||||
},
|
||||
/// The storage limit has been updated.
|
||||
StorageLimitSet {
|
||||
/// The storage limit.
|
||||
storage: FixedU64,
|
||||
},
|
||||
/// The block length limit has been updated.
|
||||
BlockLengthLimitSet {
|
||||
/// The block length limit.
|
||||
block_length: FixedU64,
|
||||
},
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
pub enum Error<T> {
|
||||
/// The pallet was already initialized.
|
||||
///
|
||||
/// Set `witness_count` to `Some` to bypass this error.
|
||||
AlreadyInitialized,
|
||||
|
||||
/// The limit was over [`crate::RESOURCE_HARD_LIMIT`].
|
||||
InsaneLimit,
|
||||
}
|
||||
|
||||
/// The proportion of the remaining `ref_time` to consume during `on_idle`.
|
||||
///
|
||||
/// `1.0` is mapped to `100%`. Must be at most [`crate::RESOURCE_HARD_LIMIT`]. Setting this to
|
||||
/// over `1.0` could stall the chain.
|
||||
#[pallet::storage]
|
||||
pub(crate) type Compute<T: Config> = StorageValue<_, FixedU64, ValueQuery>;
|
||||
|
||||
/// The proportion of the remaining `proof_size` to consume during `on_idle`.
|
||||
///
|
||||
/// `1.0` is mapped to `100%`. Must be at most [`crate::RESOURCE_HARD_LIMIT`]. Setting this to
|
||||
/// over `1.0` could stall the chain.
|
||||
#[pallet::storage]
|
||||
pub(crate) type Storage<T: Config> = StorageValue<_, FixedU64, ValueQuery>;
|
||||
|
||||
/// The proportion of the `block length` to consume on each block.
|
||||
///
|
||||
/// `1.0` is mapped to `100%`. Must be at most [`crate::RESOURCE_HARD_LIMIT`]. Setting this to
|
||||
/// over `1.0` could stall the chain.
|
||||
#[pallet::storage]
|
||||
pub(crate) type Length<T: Config> = StorageValue<_, FixedU64, ValueQuery>;
|
||||
|
||||
/// Storage map used for wasting proof size.
|
||||
///
|
||||
/// It contains no meaningful data - hence the name "Trash". The maximal number of entries is
|
||||
/// set to 65k, which is just below the next jump at 16^4. This is important to reduce the proof
|
||||
/// size benchmarking overestimate. The assumption here is that we won't have more than 65k *
|
||||
/// 1KiB = 65MiB of proof size wasting in practice. However, this limit is not enforced, so the
|
||||
/// pallet would also work out of the box with more entries, but its benchmarked proof weight
|
||||
/// would possibly be underestimated in that case.
|
||||
#[pallet::storage]
|
||||
pub(super) type TrashData<T: Config> = StorageMap<
|
||||
Hasher = Twox64Concat,
|
||||
Key = u32,
|
||||
Value = [u8; VALUE_SIZE],
|
||||
QueryKind = OptionQuery,
|
||||
MaxValues = ConstU32<MAX_TRASH_DATA_ENTRIES>,
|
||||
>;
|
||||
|
||||
/// The current number of entries in `TrashData`.
|
||||
#[pallet::storage]
|
||||
pub(crate) type TrashDataCount<T: Config> = StorageValue<_, u32, ValueQuery>;
|
||||
|
||||
#[pallet::genesis_config]
|
||||
#[derive(DefaultNoBound)]
|
||||
pub struct GenesisConfig<T: Config> {
|
||||
/// The compute limit.
|
||||
pub compute: FixedU64,
|
||||
/// The storage limit.
|
||||
pub storage: FixedU64,
|
||||
/// The amount of trash data for wasting proof size.
|
||||
pub trash_data_count: u32,
|
||||
/// The block length limit.
|
||||
pub block_length: FixedU64,
|
||||
#[serde(skip)]
|
||||
/// The required configuration field.
|
||||
pub _config: core::marker::PhantomData<T>,
|
||||
}
|
||||
|
||||
#[pallet::genesis_build]
|
||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||
fn build(&self) {
|
||||
assert!(
|
||||
self.trash_data_count <= MAX_TRASH_DATA_ENTRIES,
|
||||
"number of TrashData entries cannot be bigger than {:?}",
|
||||
MAX_TRASH_DATA_ENTRIES
|
||||
);
|
||||
|
||||
(0..self.trash_data_count)
|
||||
.for_each(|i| TrashData::<T>::insert(i, Pallet::<T>::gen_value(i)));
|
||||
|
||||
TrashDataCount::<T>::set(self.trash_data_count);
|
||||
|
||||
assert!(self.compute <= RESOURCE_HARD_LIMIT, "Compute limit is insane");
|
||||
<Compute<T>>::put(self.compute);
|
||||
|
||||
assert!(self.storage <= RESOURCE_HARD_LIMIT, "Storage limit is insane");
|
||||
<Storage<T>>::put(self.storage);
|
||||
|
||||
assert!(self.block_length <= RESOURCE_HARD_LIMIT, "Block length limit is insane");
|
||||
<Length<T>>::put(self.block_length);
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn integrity_test() {
|
||||
assert!(
|
||||
!T::WeightInfo::waste_ref_time_iter(1).ref_time().is_zero(),
|
||||
"Weight zero; would get stuck in an infinite loop"
|
||||
);
|
||||
assert!(
|
||||
!T::WeightInfo::waste_proof_size_some(1).proof_size().is_zero(),
|
||||
"Weight zero; would get stuck in an infinite loop"
|
||||
);
|
||||
}
|
||||
|
||||
fn on_idle(_: BlockNumberFor<T>, remaining_weight: Weight) -> Weight {
|
||||
let mut meter = WeightMeter::with_limit(remaining_weight);
|
||||
if meter.try_consume(T::WeightInfo::empty_on_idle()).is_err() {
|
||||
return T::WeightInfo::empty_on_idle();
|
||||
}
|
||||
|
||||
let proof_size_limit =
|
||||
Storage::<T>::get().saturating_mul_int(meter.remaining().proof_size());
|
||||
let computation_weight_limit =
|
||||
Compute::<T>::get().saturating_mul_int(meter.remaining().ref_time());
|
||||
let mut meter = WeightMeter::with_limit(Weight::from_parts(
|
||||
computation_weight_limit,
|
||||
proof_size_limit,
|
||||
));
|
||||
|
||||
Self::waste_at_most_proof_size(&mut meter);
|
||||
Self::waste_at_most_ref_time(&mut meter);
|
||||
|
||||
meter.consumed()
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::inherent]
|
||||
impl<T: Config> ProvideInherent for Pallet<T> {
|
||||
type Call = Call<T>;
|
||||
type Error = pezsp_inherents::MakeFatalError<()>;
|
||||
|
||||
const INHERENT_IDENTIFIER: InherentIdentifier = *b"bloated0";
|
||||
|
||||
fn create_inherent(_data: &InherentData) -> Option<Self::Call> {
|
||||
let max_block_length = *T::BlockLength::get().max.get(DispatchClass::Mandatory);
|
||||
let bloat_size = Length::<T>::get().saturating_mul_int(max_block_length) as usize;
|
||||
let amount_trash = bloat_size / VALUE_SIZE;
|
||||
let garbage = TrashData::<T>::iter()
|
||||
.map(|(_k, v)| v)
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
.cycle()
|
||||
.take(amount_trash)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Some(Call::bloat { garbage })
|
||||
}
|
||||
|
||||
fn is_inherent(call: &Self::Call) -> bool {
|
||||
matches!(call, Call::bloat { .. })
|
||||
}
|
||||
|
||||
fn check_inherent(call: &Self::Call, _: &InherentData) -> Result<(), Self::Error> {
|
||||
match call {
|
||||
Call::bloat { .. } => Ok(()),
|
||||
_ => unreachable!("other calls are not inherents"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::call(weight = T::WeightInfo)]
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Initialize the pallet. Should be called once, if no genesis state was provided.
|
||||
///
|
||||
/// `current_count` is the current number of elements in `TrashData`. This can be set to
|
||||
/// `None` when the pallet is first initialized.
|
||||
///
|
||||
/// Only callable by Root or `AdminOrigin`. A good default for `new_count` is `5_000`.
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight(
|
||||
T::WeightInfo::initialize_pallet_grow(witness_count.unwrap_or_default())
|
||||
.max(T::WeightInfo::initialize_pallet_shrink(witness_count.unwrap_or_default()))
|
||||
)]
|
||||
pub fn initialize_pallet(
|
||||
origin: OriginFor<T>,
|
||||
new_count: u32,
|
||||
witness_count: Option<u32>,
|
||||
) -> DispatchResult {
|
||||
T::AdminOrigin::ensure_origin_or_root(origin)?;
|
||||
|
||||
let current_count = TrashDataCount::<T>::get();
|
||||
ensure!(
|
||||
current_count == witness_count.unwrap_or_default(),
|
||||
Error::<T>::AlreadyInitialized
|
||||
);
|
||||
|
||||
if new_count > current_count {
|
||||
(current_count..new_count)
|
||||
.for_each(|i| TrashData::<T>::insert(i, Self::gen_value(i)));
|
||||
} else {
|
||||
(new_count..current_count).for_each(TrashData::<T>::remove);
|
||||
}
|
||||
|
||||
Self::deposit_event(Event::PalletInitialized { reinit: witness_count.is_some() });
|
||||
TrashDataCount::<T>::set(new_count);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set how much of the remaining `ref_time` weight should be consumed by `on_idle`.
|
||||
///
|
||||
/// Only callable by Root or `AdminOrigin`.
|
||||
#[pallet::call_index(1)]
|
||||
pub fn set_compute(origin: OriginFor<T>, compute: FixedU64) -> DispatchResult {
|
||||
T::AdminOrigin::ensure_origin_or_root(origin)?;
|
||||
|
||||
ensure!(compute <= RESOURCE_HARD_LIMIT, Error::<T>::InsaneLimit);
|
||||
Compute::<T>::set(compute);
|
||||
|
||||
Self::deposit_event(Event::ComputationLimitSet { compute });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set how much of the remaining `proof_size` weight should be consumed by `on_idle`.
|
||||
///
|
||||
/// `1.0` means that all remaining `proof_size` will be consumed. The PoV benchmarking
|
||||
/// results that are used here are likely an over-estimation. 100% intended consumption will
|
||||
/// therefore translate to less than 100% actual consumption.
|
||||
///
|
||||
/// Only callable by Root or `AdminOrigin`.
|
||||
#[pallet::call_index(2)]
|
||||
pub fn set_storage(origin: OriginFor<T>, storage: FixedU64) -> DispatchResult {
|
||||
T::AdminOrigin::ensure_origin_or_root(origin)?;
|
||||
|
||||
ensure!(storage <= RESOURCE_HARD_LIMIT, Error::<T>::InsaneLimit);
|
||||
Storage::<T>::set(storage);
|
||||
|
||||
Self::deposit_event(Event::StorageLimitSet { storage });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Increase the block size by including the specified garbage bytes.
|
||||
#[pallet::call_index(3)]
|
||||
#[pallet::weight((0, DispatchClass::Mandatory))]
|
||||
pub fn bloat(_origin: OriginFor<T>, _garbage: Vec<[u8; VALUE_SIZE]>) -> DispatchResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set how much of the block length should be filled with trash data on each block.
|
||||
///
|
||||
/// `1.0` means that all block should be filled. If set to `1.0`, storage proof size will
|
||||
/// be close to zero.
|
||||
///
|
||||
/// Only callable by Root or `AdminOrigin`.
|
||||
#[pallet::call_index(4)]
|
||||
#[pallet::weight({1})]
|
||||
pub fn set_block_length(origin: OriginFor<T>, block_length: FixedU64) -> DispatchResult {
|
||||
T::AdminOrigin::ensure_origin_or_root(origin)?;
|
||||
|
||||
ensure!(block_length <= RESOURCE_HARD_LIMIT, Error::<T>::InsaneLimit);
|
||||
Length::<T>::set(block_length);
|
||||
|
||||
Self::deposit_event(Event::BlockLengthLimitSet { block_length });
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Waste at most the remaining proof size of `meter`.
|
||||
///
|
||||
/// Tries to come as close to the limit as possible.
|
||||
pub(crate) fn waste_at_most_proof_size(meter: &mut WeightMeter) {
|
||||
let Ok(n) = Self::calculate_proof_size_iters(&meter) else { return };
|
||||
|
||||
meter.consume(T::WeightInfo::waste_proof_size_some(n));
|
||||
|
||||
(0..n).for_each(|i| {
|
||||
TrashData::<T>::get(i);
|
||||
});
|
||||
}
|
||||
|
||||
/// Calculate how many times `waste_proof_size_some` should be called to fill up `meter`.
|
||||
fn calculate_proof_size_iters(meter: &WeightMeter) -> Result<u32, ()> {
|
||||
let base = T::WeightInfo::waste_proof_size_some(0);
|
||||
let slope = T::WeightInfo::waste_proof_size_some(1).saturating_sub(base);
|
||||
|
||||
let remaining = meter.remaining().saturating_sub(base);
|
||||
let iter_by_proof_size =
|
||||
remaining.proof_size().checked_div(slope.proof_size()).ok_or(())?;
|
||||
let iter_by_ref_time = remaining.ref_time().checked_div(slope.ref_time()).ok_or(())?;
|
||||
|
||||
if iter_by_proof_size > 0 && iter_by_proof_size <= iter_by_ref_time {
|
||||
Ok(iter_by_proof_size as u32)
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Waste at most the remaining ref time weight of `meter`.
|
||||
///
|
||||
/// Tries to come as close to the limit as possible.
|
||||
pub(crate) fn waste_at_most_ref_time(meter: &mut WeightMeter) {
|
||||
let Ok(n) = Self::calculate_ref_time_iters(&meter) else { return };
|
||||
meter.consume(T::WeightInfo::waste_ref_time_iter(n));
|
||||
|
||||
let clobber = Self::waste_ref_time_iter(vec![0u8; 64], n);
|
||||
|
||||
// By casting it into a vec we can hopefully prevent the compiler from optimizing it
|
||||
// out. Note that `Blake2b512` produces 64 bytes, this is therefore impossible - but the
|
||||
// compiler does not know that (hopefully).
|
||||
debug_assert!(clobber.len() == 64);
|
||||
if clobber.len() == 65 {
|
||||
TrashData::<T>::insert(0, [clobber[0] as u8; VALUE_SIZE]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Wastes some `ref_time`. Receives the previous result as an argument.
|
||||
///
|
||||
/// The ref_time of one iteration should be in the order of 1-10 ms.
|
||||
pub(crate) fn waste_ref_time_iter(clobber: Vec<u8>, i: u32) -> Vec<u8> {
|
||||
let mut hasher = Blake2b512::new();
|
||||
|
||||
// Blake2 has a very high speed of hashing so we make multiple hashes with it to
|
||||
// waste more `ref_time` at once.
|
||||
(0..i).for_each(|_| {
|
||||
hasher.update(clobber.as_slice());
|
||||
});
|
||||
|
||||
hasher.finalize().to_vec()
|
||||
}
|
||||
|
||||
/// Calculate how many times `waste_ref_time_iter` should be called to fill up `meter`.
|
||||
fn calculate_ref_time_iters(meter: &WeightMeter) -> Result<u32, ()> {
|
||||
let base = T::WeightInfo::waste_ref_time_iter(0);
|
||||
let slope = T::WeightInfo::waste_ref_time_iter(1).saturating_sub(base);
|
||||
if !slope.proof_size().is_zero() || !base.proof_size().is_zero() {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
match meter
|
||||
.remaining()
|
||||
.ref_time()
|
||||
.saturating_sub(base.ref_time())
|
||||
.checked_div(slope.ref_time())
|
||||
{
|
||||
Some(0) | None => Err(()),
|
||||
Some(i) => Ok(i as u32),
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate a pseudo-random deterministic value from a `seed`.
|
||||
pub(crate) fn gen_value(seed: u32) -> [u8; VALUE_SIZE] {
|
||||
let mut ret = [0u8; VALUE_SIZE];
|
||||
|
||||
for i in 0u32..(VALUE_SIZE as u32 / 32) {
|
||||
let hash = (seed, i).using_encoded(twox_256);
|
||||
ret[i as usize * 32..(i + 1) as usize * 32].copy_from_slice(&hash);
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use super::*;
|
||||
use crate as pezpallet_glutton;
|
||||
|
||||
use pezframe_support::{assert_ok, derive_impl};
|
||||
use pezsp_runtime::BuildStorage;
|
||||
|
||||
type Block = pezframe_system::mocking::MockBlock<Test>;
|
||||
|
||||
pezframe_support::construct_runtime!(
|
||||
pub enum Test
|
||||
{
|
||||
System: pezframe_system,
|
||||
Glutton: pezpallet_glutton,
|
||||
}
|
||||
);
|
||||
|
||||
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
|
||||
impl pezframe_system::Config for Test {
|
||||
type Block = Block;
|
||||
}
|
||||
|
||||
impl Config for Test {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type AdminOrigin = pezframe_system::EnsureRoot<Self::AccountId>;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
pub fn new_test_ext() -> pezsp_io::TestExternalities {
|
||||
let t = pezframe_system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
|
||||
let mut ext = pezsp_io::TestExternalities::new(t);
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
}
|
||||
|
||||
/// Set the `compute`, `storage` and `block_length` limits.
|
||||
///
|
||||
/// `1.0` corresponds to `100%`.
|
||||
pub fn set_limits(compute: f64, storage: f64, block_length: f64) {
|
||||
assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_float(compute)));
|
||||
assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), FixedU64::from_float(storage)));
|
||||
assert_ok!(Glutton::set_block_length(
|
||||
RuntimeOrigin::root(),
|
||||
FixedU64::from_float(block_length)
|
||||
));
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Tests for the glutton pallet.
|
||||
|
||||
use super::{mock::*, *};
|
||||
|
||||
use pezframe_support::{assert_err, assert_noop, assert_ok, weights::constants::*};
|
||||
use pezsp_runtime::{traits::One, Perbill};
|
||||
|
||||
const CALIBRATION_ERROR: &'static str =
|
||||
"Weight calibration failed. Please re-run the benchmarks on the same hardware.";
|
||||
|
||||
#[test]
|
||||
fn initialize_pallet_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(TrashData::<Test>::get(0), None);
|
||||
|
||||
assert_noop!(
|
||||
Glutton::initialize_pallet(RuntimeOrigin::signed(1), 3, None),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
assert_noop!(
|
||||
Glutton::initialize_pallet(RuntimeOrigin::none(), 3, None),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
|
||||
assert_ok!(Glutton::initialize_pallet(RuntimeOrigin::root(), 2, None));
|
||||
System::assert_last_event(Event::PalletInitialized { reinit: false }.into());
|
||||
assert_err!(
|
||||
Glutton::initialize_pallet(RuntimeOrigin::root(), 2, None),
|
||||
Error::<Test>::AlreadyInitialized
|
||||
);
|
||||
|
||||
assert_eq!(TrashData::<Test>::get(0), Some(Pallet::<Test>::gen_value(0)));
|
||||
assert_eq!(TrashData::<Test>::get(1), Some(Pallet::<Test>::gen_value(1)));
|
||||
assert_eq!(TrashData::<Test>::get(2), None);
|
||||
|
||||
assert_eq!(TrashDataCount::<Test>::get(), 2);
|
||||
|
||||
assert_ok!(Glutton::initialize_pallet(RuntimeOrigin::root(), 20, Some(2)));
|
||||
|
||||
assert_eq!(TrashDataCount::<Test>::get(), 20);
|
||||
assert_eq!(TrashData::<Test>::iter_keys().count(), 20);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expand_and_shrink_trash_data_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(TrashDataCount::<Test>::get(), 0);
|
||||
|
||||
assert_ok!(Glutton::initialize_pallet(RuntimeOrigin::root(), 5000, None));
|
||||
assert_eq!(TrashDataCount::<Test>::get(), 5000);
|
||||
assert_eq!(TrashData::<Test>::iter_keys().count(), 5000);
|
||||
|
||||
assert_ok!(Glutton::initialize_pallet(RuntimeOrigin::root(), 8000, Some(5000)));
|
||||
assert_eq!(TrashDataCount::<Test>::get(), 8000);
|
||||
assert_eq!(TrashData::<Test>::iter_keys().count(), 8000);
|
||||
|
||||
assert_ok!(Glutton::initialize_pallet(RuntimeOrigin::root(), 6000, Some(8000)));
|
||||
assert_eq!(TrashDataCount::<Test>::get(), 6000);
|
||||
assert_eq!(TrashData::<Test>::iter_keys().count(), 6000);
|
||||
|
||||
assert_noop!(
|
||||
Glutton::initialize_pallet(RuntimeOrigin::root(), 0, None),
|
||||
Error::<Test>::AlreadyInitialized
|
||||
);
|
||||
assert_ok!(Glutton::initialize_pallet(RuntimeOrigin::root(), 0, Some(6000)));
|
||||
assert_eq!(TrashDataCount::<Test>::get(), 0);
|
||||
assert_eq!(TrashData::<Test>::iter_keys().count(), 0);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn setting_compute_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(Compute::<Test>::get(), Zero::zero());
|
||||
|
||||
assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_float(0.3)));
|
||||
assert_eq!(Compute::<Test>::get(), FixedU64::from_float(0.3));
|
||||
System::assert_last_event(
|
||||
Event::ComputationLimitSet { compute: FixedU64::from_float(0.3) }.into(),
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Glutton::set_compute(RuntimeOrigin::signed(1), FixedU64::from_float(0.5)),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
assert_noop!(
|
||||
Glutton::set_compute(RuntimeOrigin::none(), FixedU64::from_float(0.5)),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn setting_compute_respects_limit() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// < 1000% is fine
|
||||
assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_float(9.99)),);
|
||||
// == 1000% is fine
|
||||
assert_ok!(Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_u32(10)),);
|
||||
// > 1000% is not
|
||||
assert_noop!(
|
||||
Glutton::set_compute(RuntimeOrigin::root(), FixedU64::from_float(10.01)),
|
||||
Error::<Test>::InsaneLimit
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn setting_block_length_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_eq!(Compute::<Test>::get(), Zero::zero());
|
||||
|
||||
assert_ok!(Glutton::set_block_length(RuntimeOrigin::root(), FixedU64::from_float(0.3)));
|
||||
assert_eq!(Length::<Test>::get(), FixedU64::from_float(0.3));
|
||||
System::assert_last_event(
|
||||
Event::BlockLengthLimitSet { block_length: FixedU64::from_float(0.3) }.into(),
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Glutton::set_block_length(RuntimeOrigin::signed(1), FixedU64::from_float(0.5)),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
assert_noop!(
|
||||
Glutton::set_block_length(RuntimeOrigin::none(), FixedU64::from_float(0.5)),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn setting_block_length_respects_limit() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// < 1000% is fine
|
||||
assert_ok!(Glutton::set_block_length(RuntimeOrigin::root(), FixedU64::from_float(9.99)),);
|
||||
// == 1000% is fine
|
||||
assert_ok!(Glutton::set_block_length(RuntimeOrigin::root(), FixedU64::from_u32(10)),);
|
||||
// > 1000% is not
|
||||
assert_noop!(
|
||||
Glutton::set_block_length(RuntimeOrigin::root(), FixedU64::from_float(10.01)),
|
||||
Error::<Test>::InsaneLimit
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn setting_storage_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(Storage::<Test>::get().is_zero());
|
||||
|
||||
assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), FixedU64::from_float(0.3)));
|
||||
assert_eq!(Storage::<Test>::get(), FixedU64::from_float(0.3));
|
||||
System::assert_last_event(
|
||||
Event::StorageLimitSet { storage: FixedU64::from_float(0.3) }.into(),
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Glutton::set_storage(RuntimeOrigin::signed(1), FixedU64::from_float(0.5)),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
assert_noop!(
|
||||
Glutton::set_storage(RuntimeOrigin::none(), FixedU64::from_float(0.5)),
|
||||
DispatchError::BadOrigin
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn setting_storage_respects_limit() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// < 1000% is fine
|
||||
assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), FixedU64::from_float(9.99)),);
|
||||
// == 1000% is fine
|
||||
assert_ok!(Glutton::set_storage(RuntimeOrigin::root(), FixedU64::from_u32(10)),);
|
||||
// > 1000% is not
|
||||
assert_noop!(
|
||||
Glutton::set_storage(RuntimeOrigin::root(), FixedU64::from_float(10.01)),
|
||||
Error::<Test>::InsaneLimit
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn on_idle_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
set_limits(One::one(), One::one(), One::one());
|
||||
|
||||
Glutton::on_idle(1, Weight::from_parts(20_000_000, 0));
|
||||
});
|
||||
}
|
||||
|
||||
/// Check that the expected is close enough to the consumed weight.
|
||||
#[test]
|
||||
fn on_idle_weight_high_proof_is_close_enough_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
set_limits(One::one(), One::one(), One::one());
|
||||
|
||||
let should = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, WEIGHT_PROOF_SIZE_PER_MB * 5);
|
||||
let got = Glutton::on_idle(1, should);
|
||||
assert!(got.all_lte(should), "Consumed too much weight");
|
||||
|
||||
let ratio = Perbill::from_rational(got.proof_size(), should.proof_size());
|
||||
assert!(
|
||||
ratio >= Perbill::from_percent(99),
|
||||
"Too few proof size consumed, was only {ratio:?} of expected",
|
||||
);
|
||||
|
||||
let ratio = Perbill::from_rational(got.ref_time(), should.ref_time());
|
||||
assert!(
|
||||
ratio >= Perbill::from_percent(99),
|
||||
"Too few ref time consumed, was only {ratio:?} of expected",
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn on_idle_weight_low_proof_is_close_enough_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
set_limits(One::one(), One::one(), One::one());
|
||||
|
||||
let should = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, WEIGHT_PROOF_SIZE_PER_KB * 20);
|
||||
let got = Glutton::on_idle(1, should);
|
||||
assert!(got.all_lte(should), "Consumed too much weight");
|
||||
|
||||
let ratio = Perbill::from_rational(got.proof_size(), should.proof_size());
|
||||
// Just a sanity check here for > 0
|
||||
assert!(
|
||||
ratio >= Perbill::from_percent(50),
|
||||
"Too few proof size consumed, was only {ratio:?} of expected",
|
||||
);
|
||||
|
||||
let ratio = Perbill::from_rational(got.ref_time(), should.ref_time());
|
||||
assert!(
|
||||
ratio >= Perbill::from_percent(99),
|
||||
"Too few ref time consumed, was only {ratio:?} of expected",
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn on_idle_weight_over_unity_is_close_enough_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Para blocks get ~500ms compute and ~5MB proof size.
|
||||
let max_block =
|
||||
Weight::from_parts(500 * WEIGHT_REF_TIME_PER_MILLIS, 5 * WEIGHT_PROOF_SIZE_PER_MB);
|
||||
// But now we tell it to consume more than that.
|
||||
set_limits(1.75, 1.5, 0.0);
|
||||
let want = Weight::from_parts(
|
||||
(1.75 * max_block.ref_time() as f64) as u64,
|
||||
(1.5 * max_block.proof_size() as f64) as u64,
|
||||
);
|
||||
|
||||
let consumed = Glutton::on_idle(1, max_block);
|
||||
assert!(consumed.all_gt(max_block), "Must consume more than the block limit");
|
||||
assert!(consumed.all_lte(want), "Consumed more than the requested weight");
|
||||
|
||||
let ratio = Perbill::from_rational(consumed.proof_size(), want.proof_size());
|
||||
assert!(
|
||||
ratio >= Perbill::from_percent(99),
|
||||
"Too few proof size consumed, was only {ratio:?} of expected",
|
||||
);
|
||||
|
||||
let ratio = Perbill::from_rational(consumed.ref_time(), want.ref_time());
|
||||
assert!(
|
||||
ratio >= Perbill::from_percent(99),
|
||||
"Too few ref time consumed, was only {ratio:?} of expected",
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn waste_at_most_ref_time_weight_close_enough() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let mut meter =
|
||||
WeightMeter::with_limit(Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, u64::MAX));
|
||||
// Over-spending fails defensively.
|
||||
Glutton::waste_at_most_ref_time(&mut meter);
|
||||
|
||||
// We require it to be under-spend by at most 1%.
|
||||
assert!(
|
||||
meter.consumed_ratio() >= Perbill::from_percent(99),
|
||||
"{CALIBRATION_ERROR}\nConsumed too few: {:?}",
|
||||
meter.consumed_ratio()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn waste_at_most_proof_size_weight_close_enough() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let mut meter =
|
||||
WeightMeter::with_limit(Weight::from_parts(u64::MAX, WEIGHT_PROOF_SIZE_PER_MB * 5));
|
||||
// Over-spending fails defensively.
|
||||
Glutton::waste_at_most_proof_size(&mut meter);
|
||||
|
||||
// We require it to be under-spend by at most 1%.
|
||||
assert!(
|
||||
meter.consumed_ratio() >= Perbill::from_percent(99),
|
||||
"{CALIBRATION_ERROR}\nConsumed too few: {:?}",
|
||||
meter.consumed_ratio()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gen_value_works() {
|
||||
let g0 = Pallet::<Test>::gen_value(0);
|
||||
let g1 = Pallet::<Test>::gen_value(1);
|
||||
|
||||
assert_eq!(g0.len(), VALUE_SIZE);
|
||||
assert_ne!(g0, g1, "Is distinct");
|
||||
assert_ne!(g0, [0; VALUE_SIZE], "Is not zero");
|
||||
assert_eq!(g0, Pallet::<Test>::gen_value(0), "Is deterministic");
|
||||
}
|
||||
@@ -0,0 +1,329 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Autogenerated weights for `pezpallet_glutton`
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE BIZINIKIWI BENCHMARK CLI VERSION 32.0.0
|
||||
//! DATE: 2025-02-21, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! WORST CASE MAP SIZE: `1000000`
|
||||
//! HOSTNAME: `4563561839a5`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
|
||||
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024`
|
||||
|
||||
// Executed Command:
|
||||
// frame-omni-bencher
|
||||
// v1
|
||||
// benchmark
|
||||
// pallet
|
||||
// --extrinsic=*
|
||||
// --runtime=target/production/wbuild/kitchensink-runtime/kitchensink_runtime.wasm
|
||||
// --pallet=pezpallet_glutton
|
||||
// --header=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/HEADER-APACHE2
|
||||
// --output=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/pezframe/glutton/src/weights.rs
|
||||
// --wasm-execution=compiled
|
||||
// --steps=50
|
||||
// --repeat=20
|
||||
// --heap-pages=4096
|
||||
// --template=bizinikiwi/.maintain/frame-weight-template.hbs
|
||||
// --no-storage-info
|
||||
// --no-min-squares
|
||||
// --no-median-slopes
|
||||
// --genesis-builder-policy=none
|
||||
// --exclude-pallets=pezpallet_xcm,pezpallet_xcm_benchmarks::fungible,pezpallet_xcm_benchmarks::generic,pezpallet_nomination_pools,pezpallet_remark,pezpallet_transaction_storage,pezpallet_election_provider_multi_block,pezpallet_election_provider_multi_block::signed,pezpallet_election_provider_multi_block::unsigned,pezpallet_election_provider_multi_block::verifier
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
#![allow(missing_docs)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use pezframe_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
|
||||
use core::marker::PhantomData;
|
||||
|
||||
/// Weight functions needed for `pezpallet_glutton`.
|
||||
pub trait WeightInfo {
|
||||
fn initialize_pallet_grow(n: u32, ) -> Weight;
|
||||
fn initialize_pallet_shrink(n: u32, ) -> Weight;
|
||||
fn waste_ref_time_iter(i: u32, ) -> Weight;
|
||||
fn waste_proof_size_some(i: u32, ) -> Weight;
|
||||
fn on_idle_high_proof_waste() -> Weight;
|
||||
fn on_idle_low_proof_waste() -> Weight;
|
||||
fn empty_on_idle() -> Weight;
|
||||
fn set_compute() -> Weight;
|
||||
fn set_storage() -> Weight;
|
||||
}
|
||||
|
||||
/// Weights for `pezpallet_glutton` using the Bizinikiwi node and recommended hardware.
|
||||
pub struct BizinikiwiWeight<T>(PhantomData<T>);
|
||||
impl<T: pezframe_system::Config> WeightInfo for BizinikiwiWeight<T> {
|
||||
/// Storage: `Glutton::TrashDataCount` (r:1 w:1)
|
||||
/// Proof: `Glutton::TrashDataCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Glutton::TrashData` (r:0 w:1000)
|
||||
/// Proof: `Glutton::TrashData` (`max_values`: Some(65000), `max_size`: Some(1036), added: 3016, mode: `MaxEncodedLen`)
|
||||
/// The range of component `n` is `[0, 1000]`.
|
||||
fn initialize_pallet_grow(n: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `1489`
|
||||
// Minimum execution time: 4_557_000 picoseconds.
|
||||
Weight::from_parts(4_660_000, 1489)
|
||||
// Standard Error: 2_163
|
||||
.saturating_add(Weight::from_parts(10_339_879, 0).saturating_mul(n.into()))
|
||||
.saturating_add(T::DbWeight::get().reads(1_u64))
|
||||
.saturating_add(T::DbWeight::get().writes(1_u64))
|
||||
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into())))
|
||||
}
|
||||
/// Storage: `Glutton::TrashDataCount` (r:1 w:1)
|
||||
/// Proof: `Glutton::TrashDataCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Glutton::TrashData` (r:0 w:1000)
|
||||
/// Proof: `Glutton::TrashData` (`max_values`: Some(65000), `max_size`: Some(1036), added: 3016, mode: `MaxEncodedLen`)
|
||||
/// The range of component `n` is `[0, 1000]`.
|
||||
fn initialize_pallet_shrink(n: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `1489`
|
||||
// Minimum execution time: 4_922_000 picoseconds.
|
||||
Weight::from_parts(5_004_000, 1489)
|
||||
// Standard Error: 1_139
|
||||
.saturating_add(Weight::from_parts(1_166_537, 0).saturating_mul(n.into()))
|
||||
.saturating_add(T::DbWeight::get().reads(1_u64))
|
||||
.saturating_add(T::DbWeight::get().writes(1_u64))
|
||||
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into())))
|
||||
}
|
||||
/// The range of component `i` is `[0, 100000]`.
|
||||
fn waste_ref_time_iter(i: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `0`
|
||||
// Minimum execution time: 644_000 picoseconds.
|
||||
Weight::from_parts(2_924_654, 0)
|
||||
// Standard Error: 9
|
||||
.saturating_add(Weight::from_parts(102_155, 0).saturating_mul(i.into()))
|
||||
}
|
||||
/// Storage: `Glutton::TrashData` (r:5000 w:0)
|
||||
/// Proof: `Glutton::TrashData` (`max_values`: Some(65000), `max_size`: Some(1036), added: 3016, mode: `MaxEncodedLen`)
|
||||
/// The range of component `i` is `[0, 5000]`.
|
||||
fn waste_proof_size_some(i: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `118478 + i * (1022 ±0)`
|
||||
// Estimated: `990 + i * (3016 ±0)`
|
||||
// Minimum execution time: 434_000 picoseconds.
|
||||
Weight::from_parts(327_172_459, 990)
|
||||
// Standard Error: 5_517
|
||||
.saturating_add(Weight::from_parts(6_487_717, 0).saturating_mul(i.into()))
|
||||
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(i.into())))
|
||||
.saturating_add(Weight::from_parts(0, 3016).saturating_mul(i.into()))
|
||||
}
|
||||
/// Storage: `Glutton::Storage` (r:1 w:0)
|
||||
/// Proof: `Glutton::Storage` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Glutton::Compute` (r:1 w:0)
|
||||
/// Proof: `Glutton::Compute` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Glutton::TrashData` (r:1737 w:0)
|
||||
/// Proof: `Glutton::TrashData` (`max_values`: Some(65000), `max_size`: Some(1036), added: 3016, mode: `MaxEncodedLen`)
|
||||
fn on_idle_high_proof_waste() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `1900378`
|
||||
// Estimated: `5239782`
|
||||
// Minimum execution time: 53_542_464_000 picoseconds.
|
||||
Weight::from_parts(53_694_275_000, 5239782)
|
||||
.saturating_add(T::DbWeight::get().reads(1739_u64))
|
||||
}
|
||||
/// Storage: `Glutton::Storage` (r:1 w:0)
|
||||
/// Proof: `Glutton::Storage` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Glutton::Compute` (r:1 w:0)
|
||||
/// Proof: `Glutton::Compute` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Glutton::TrashData` (r:5 w:0)
|
||||
/// Proof: `Glutton::TrashData` (`max_values`: Some(65000), `max_size`: Some(1036), added: 3016, mode: `MaxEncodedLen`)
|
||||
fn on_idle_low_proof_waste() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `9428`
|
||||
// Estimated: `16070`
|
||||
// Minimum execution time: 95_059_615_000 picoseconds.
|
||||
Weight::from_parts(95_174_107_000, 16070)
|
||||
.saturating_add(T::DbWeight::get().reads(7_u64))
|
||||
}
|
||||
/// Storage: `Glutton::Storage` (r:1 w:0)
|
||||
/// Proof: `Glutton::Storage` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Glutton::Compute` (r:1 w:0)
|
||||
/// Proof: `Glutton::Compute` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
fn empty_on_idle() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `1493`
|
||||
// Minimum execution time: 1_703_000 picoseconds.
|
||||
Weight::from_parts(1_784_000, 1493)
|
||||
.saturating_add(T::DbWeight::get().reads(2_u64))
|
||||
}
|
||||
/// Storage: `Glutton::Compute` (r:0 w:1)
|
||||
/// Proof: `Glutton::Compute` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
fn set_compute() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `0`
|
||||
// Minimum execution time: 4_351_000 picoseconds.
|
||||
Weight::from_parts(4_510_000, 0)
|
||||
.saturating_add(T::DbWeight::get().writes(1_u64))
|
||||
}
|
||||
/// Storage: `Glutton::Storage` (r:0 w:1)
|
||||
/// Proof: `Glutton::Storage` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
fn set_storage() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `0`
|
||||
// Minimum execution time: 4_253_000 picoseconds.
|
||||
Weight::from_parts(4_471_000, 0)
|
||||
.saturating_add(T::DbWeight::get().writes(1_u64))
|
||||
}
|
||||
}
|
||||
|
||||
// For backwards compatibility and tests.
|
||||
impl WeightInfo for () {
|
||||
/// Storage: `Glutton::TrashDataCount` (r:1 w:1)
|
||||
/// Proof: `Glutton::TrashDataCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Glutton::TrashData` (r:0 w:1000)
|
||||
/// Proof: `Glutton::TrashData` (`max_values`: Some(65000), `max_size`: Some(1036), added: 3016, mode: `MaxEncodedLen`)
|
||||
/// The range of component `n` is `[0, 1000]`.
|
||||
fn initialize_pallet_grow(n: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `1489`
|
||||
// Minimum execution time: 4_557_000 picoseconds.
|
||||
Weight::from_parts(4_660_000, 1489)
|
||||
// Standard Error: 2_163
|
||||
.saturating_add(Weight::from_parts(10_339_879, 0).saturating_mul(n.into()))
|
||||
.saturating_add(RocksDbWeight::get().reads(1_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(1_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(n.into())))
|
||||
}
|
||||
/// Storage: `Glutton::TrashDataCount` (r:1 w:1)
|
||||
/// Proof: `Glutton::TrashDataCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Glutton::TrashData` (r:0 w:1000)
|
||||
/// Proof: `Glutton::TrashData` (`max_values`: Some(65000), `max_size`: Some(1036), added: 3016, mode: `MaxEncodedLen`)
|
||||
/// The range of component `n` is `[0, 1000]`.
|
||||
fn initialize_pallet_shrink(n: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `1489`
|
||||
// Minimum execution time: 4_922_000 picoseconds.
|
||||
Weight::from_parts(5_004_000, 1489)
|
||||
// Standard Error: 1_139
|
||||
.saturating_add(Weight::from_parts(1_166_537, 0).saturating_mul(n.into()))
|
||||
.saturating_add(RocksDbWeight::get().reads(1_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(1_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(n.into())))
|
||||
}
|
||||
/// The range of component `i` is `[0, 100000]`.
|
||||
fn waste_ref_time_iter(i: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `0`
|
||||
// Minimum execution time: 644_000 picoseconds.
|
||||
Weight::from_parts(2_924_654, 0)
|
||||
// Standard Error: 9
|
||||
.saturating_add(Weight::from_parts(102_155, 0).saturating_mul(i.into()))
|
||||
}
|
||||
/// Storage: `Glutton::TrashData` (r:5000 w:0)
|
||||
/// Proof: `Glutton::TrashData` (`max_values`: Some(65000), `max_size`: Some(1036), added: 3016, mode: `MaxEncodedLen`)
|
||||
/// The range of component `i` is `[0, 5000]`.
|
||||
fn waste_proof_size_some(i: u32, ) -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `118478 + i * (1022 ±0)`
|
||||
// Estimated: `990 + i * (3016 ±0)`
|
||||
// Minimum execution time: 434_000 picoseconds.
|
||||
Weight::from_parts(327_172_459, 990)
|
||||
// Standard Error: 5_517
|
||||
.saturating_add(Weight::from_parts(6_487_717, 0).saturating_mul(i.into()))
|
||||
.saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(i.into())))
|
||||
.saturating_add(Weight::from_parts(0, 3016).saturating_mul(i.into()))
|
||||
}
|
||||
/// Storage: `Glutton::Storage` (r:1 w:0)
|
||||
/// Proof: `Glutton::Storage` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Glutton::Compute` (r:1 w:0)
|
||||
/// Proof: `Glutton::Compute` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Glutton::TrashData` (r:1737 w:0)
|
||||
/// Proof: `Glutton::TrashData` (`max_values`: Some(65000), `max_size`: Some(1036), added: 3016, mode: `MaxEncodedLen`)
|
||||
fn on_idle_high_proof_waste() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `1900378`
|
||||
// Estimated: `5239782`
|
||||
// Minimum execution time: 53_542_464_000 picoseconds.
|
||||
Weight::from_parts(53_694_275_000, 5239782)
|
||||
.saturating_add(RocksDbWeight::get().reads(1739_u64))
|
||||
}
|
||||
/// Storage: `Glutton::Storage` (r:1 w:0)
|
||||
/// Proof: `Glutton::Storage` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Glutton::Compute` (r:1 w:0)
|
||||
/// Proof: `Glutton::Compute` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Glutton::TrashData` (r:5 w:0)
|
||||
/// Proof: `Glutton::TrashData` (`max_values`: Some(65000), `max_size`: Some(1036), added: 3016, mode: `MaxEncodedLen`)
|
||||
fn on_idle_low_proof_waste() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `9428`
|
||||
// Estimated: `16070`
|
||||
// Minimum execution time: 95_059_615_000 picoseconds.
|
||||
Weight::from_parts(95_174_107_000, 16070)
|
||||
.saturating_add(RocksDbWeight::get().reads(7_u64))
|
||||
}
|
||||
/// Storage: `Glutton::Storage` (r:1 w:0)
|
||||
/// Proof: `Glutton::Storage` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
/// Storage: `Glutton::Compute` (r:1 w:0)
|
||||
/// Proof: `Glutton::Compute` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
fn empty_on_idle() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `1493`
|
||||
// Minimum execution time: 1_703_000 picoseconds.
|
||||
Weight::from_parts(1_784_000, 1493)
|
||||
.saturating_add(RocksDbWeight::get().reads(2_u64))
|
||||
}
|
||||
/// Storage: `Glutton::Compute` (r:0 w:1)
|
||||
/// Proof: `Glutton::Compute` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
fn set_compute() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `0`
|
||||
// Minimum execution time: 4_351_000 picoseconds.
|
||||
Weight::from_parts(4_510_000, 0)
|
||||
.saturating_add(RocksDbWeight::get().writes(1_u64))
|
||||
}
|
||||
/// Storage: `Glutton::Storage` (r:0 w:1)
|
||||
/// Proof: `Glutton::Storage` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
|
||||
fn set_storage() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `0`
|
||||
// Minimum execution time: 4_253_000 picoseconds.
|
||||
Weight::from_parts(4_471_000, 0)
|
||||
.saturating_add(RocksDbWeight::get().writes(1_u64))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user