mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 15:51:12 +00:00
This PR reverts #2280 which introduced `TransactionExtension` to replace `SignedExtension`. As a result of the discussion [here](https://github.com/paritytech/polkadot-sdk/pull/3623#issuecomment-1986789700), the changes will be reverted for now with plans to reintroduce the concept in the future. --------- Signed-off-by: georgepisaltu <george.pisaltu@parity.io>
This commit is contained in:
@@ -1,213 +0,0 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// 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.
|
||||
|
||||
// Benchmarks for System Extensions
|
||||
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use frame_benchmarking::{account, v2::*, BenchmarkError};
|
||||
use frame_support::{
|
||||
dispatch::{DispatchClass, DispatchInfo, PostDispatchInfo},
|
||||
weights::Weight,
|
||||
};
|
||||
use frame_system::{
|
||||
pallet_prelude::*, CheckGenesis, CheckMortality, CheckNonZeroSender, CheckNonce,
|
||||
CheckSpecVersion, CheckTxVersion, CheckWeight, Config, Pallet as System, RawOrigin,
|
||||
};
|
||||
use sp_runtime::{
|
||||
generic::Era,
|
||||
traits::{AsSystemOriginSigner, DispatchTransaction, Dispatchable, Get},
|
||||
};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
pub struct Pallet<T: Config>(System<T>);
|
||||
|
||||
#[benchmarks(where
|
||||
T: Send + Sync,
|
||||
T::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
|
||||
<T::RuntimeCall as Dispatchable>::RuntimeOrigin: AsSystemOriginSigner<T::AccountId> + Clone)
|
||||
]
|
||||
mod benchmarks {
|
||||
use super::*;
|
||||
|
||||
#[benchmark]
|
||||
fn check_genesis() -> Result<(), BenchmarkError> {
|
||||
let len = 0_usize;
|
||||
let caller = account("caller", 0, 0);
|
||||
let info = DispatchInfo { weight: Weight::zero(), ..Default::default() };
|
||||
let call: T::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into();
|
||||
|
||||
#[block]
|
||||
{
|
||||
CheckGenesis::<T>::new()
|
||||
.test_run(RawOrigin::Signed(caller).into(), &call, &info, len, |_| Ok(().into()))
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn check_mortality() -> Result<(), BenchmarkError> {
|
||||
let len = 0_usize;
|
||||
let ext = CheckMortality::<T>::from(Era::mortal(16, 256));
|
||||
let block_number: BlockNumberFor<T> = 17u32.into();
|
||||
System::<T>::set_block_number(block_number);
|
||||
let prev_block: BlockNumberFor<T> = 16u32.into();
|
||||
let default_hash: T::Hash = Default::default();
|
||||
frame_system::BlockHash::<T>::insert(prev_block, default_hash);
|
||||
let caller = account("caller", 0, 0);
|
||||
let info = DispatchInfo {
|
||||
weight: Weight::from_parts(100, 0),
|
||||
class: DispatchClass::Normal,
|
||||
..Default::default()
|
||||
};
|
||||
let call: T::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into();
|
||||
|
||||
#[block]
|
||||
{
|
||||
ext.test_run(RawOrigin::Signed(caller).into(), &call, &info, len, |_| Ok(().into()))
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn check_non_zero_sender() -> Result<(), BenchmarkError> {
|
||||
let len = 0_usize;
|
||||
let ext = CheckNonZeroSender::<T>::new();
|
||||
let caller = account("caller", 0, 0);
|
||||
let info = DispatchInfo { weight: Weight::zero(), ..Default::default() };
|
||||
let call: T::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into();
|
||||
|
||||
#[block]
|
||||
{
|
||||
ext.test_run(RawOrigin::Signed(caller).into(), &call, &info, len, |_| Ok(().into()))
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn check_nonce() -> Result<(), BenchmarkError> {
|
||||
let caller: T::AccountId = account("caller", 0, 0);
|
||||
let mut info = frame_system::AccountInfo::default();
|
||||
info.nonce = 1u32.into();
|
||||
info.providers = 1;
|
||||
let expected_nonce = info.nonce + 1u32.into();
|
||||
frame_system::Account::<T>::insert(caller.clone(), info);
|
||||
let len = 0_usize;
|
||||
let ext = CheckNonce::<T>::from(1u32.into());
|
||||
let info = DispatchInfo { weight: Weight::zero(), ..Default::default() };
|
||||
let call: T::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into();
|
||||
|
||||
#[block]
|
||||
{
|
||||
ext.test_run(RawOrigin::Signed(caller.clone()).into(), &call, &info, len, |_| {
|
||||
Ok(().into())
|
||||
})
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let updated_info = frame_system::Account::<T>::get(caller.clone());
|
||||
assert_eq!(updated_info.nonce, expected_nonce);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn check_spec_version() -> Result<(), BenchmarkError> {
|
||||
let len = 0_usize;
|
||||
let caller = account("caller", 0, 0);
|
||||
let info = DispatchInfo { weight: Weight::zero(), ..Default::default() };
|
||||
let call: T::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into();
|
||||
|
||||
#[block]
|
||||
{
|
||||
CheckSpecVersion::<T>::new()
|
||||
.test_run(RawOrigin::Signed(caller).into(), &call, &info, len, |_| Ok(().into()))
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn check_tx_version() -> Result<(), BenchmarkError> {
|
||||
let len = 0_usize;
|
||||
let caller = account("caller", 0, 0);
|
||||
let info = DispatchInfo { weight: Weight::zero(), ..Default::default() };
|
||||
let call: T::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into();
|
||||
|
||||
#[block]
|
||||
{
|
||||
CheckTxVersion::<T>::new()
|
||||
.test_run(RawOrigin::Signed(caller).into(), &call, &info, len, |_| Ok(().into()))
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn check_weight() -> Result<(), BenchmarkError> {
|
||||
let caller = account("caller", 0, 0);
|
||||
let base_extrinsic = <T as frame_system::Config>::BlockWeights::get()
|
||||
.get(DispatchClass::Normal)
|
||||
.base_extrinsic;
|
||||
let info = DispatchInfo {
|
||||
weight: Weight::from_parts(base_extrinsic.ref_time() * 5, 0),
|
||||
class: DispatchClass::Normal,
|
||||
..Default::default()
|
||||
};
|
||||
let call: T::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into();
|
||||
let post_info = PostDispatchInfo {
|
||||
actual_weight: Some(Weight::from_parts(base_extrinsic.ref_time() * 2, 0)),
|
||||
pays_fee: Default::default(),
|
||||
};
|
||||
let len = 0_usize;
|
||||
let base_extrinsic = <T as frame_system::Config>::BlockWeights::get()
|
||||
.get(DispatchClass::Normal)
|
||||
.base_extrinsic;
|
||||
|
||||
let ext = CheckWeight::<T>::new();
|
||||
|
||||
let initial_block_weight = Weight::from_parts(base_extrinsic.ref_time() * 2, 0);
|
||||
frame_system::BlockWeight::<T>::mutate(|current_weight| {
|
||||
current_weight.set(Weight::zero(), DispatchClass::Mandatory);
|
||||
current_weight.set(initial_block_weight, DispatchClass::Normal);
|
||||
});
|
||||
|
||||
#[block]
|
||||
{
|
||||
ext.test_run(RawOrigin::Signed(caller).into(), &call, &info, len, |_| Ok(post_info))
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
System::<T>::block_weight().total(),
|
||||
initial_block_weight + base_extrinsic + post_info.actual_weight.unwrap(),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test,);
|
||||
}
|
||||
@@ -28,7 +28,6 @@ use sp_core::storage::well_known_keys;
|
||||
use sp_runtime::traits::Hash;
|
||||
use sp_std::{prelude::*, vec};
|
||||
|
||||
pub mod extensions;
|
||||
mod mock;
|
||||
|
||||
pub struct Pallet<T: Config>(System<T>);
|
||||
|
||||
@@ -57,7 +57,6 @@ impl frame_system::Config for Test {
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
type SystemWeightInfo = ();
|
||||
type ExtensionsWeightInfo = ();
|
||||
type SS58Prefix = ();
|
||||
type OnSetCode = ();
|
||||
type MaxConsumers = frame_support::traits::ConstU32<16>;
|
||||
|
||||
Reference in New Issue
Block a user