Revert "FRAME: Create TransactionExtension as a replacement for SignedExtension (#2280)" (#3665)

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:
georgepisaltu
2024-03-13 16:10:59 +02:00
committed by GitHub
parent 60ac5a723c
commit bbd51ce867
350 changed files with 15826 additions and 24304 deletions
+1 -28
View File
@@ -20,23 +20,14 @@
use super::*;
use crate::Pallet;
use frame_benchmarking::v2::*;
use frame_support::dispatch::DispatchInfo;
use frame_system::RawOrigin;
use sp_runtime::traits::{AsSystemOriginSigner, DispatchTransaction, Dispatchable};
fn assert_last_event<T: Config>(generic_event: crate::Event<T>) {
let re: <T as Config>::RuntimeEvent = generic_event.into();
frame_system::Pallet::<T>::assert_last_event(re.into());
}
#[benchmarks(where
T: Send + Sync,
<T as Config>::RuntimeCall: From<frame_system::Call<T>>,
<T as frame_system::Config>::RuntimeCall: Dispatchable<Info = DispatchInfo>,
<<T as frame_system::Config>::RuntimeCall as Dispatchable>::PostInfo: From<()>,
<<T as frame_system::Config>::RuntimeCall as Dispatchable>::RuntimeOrigin:
AsSystemOriginSigner<T::AccountId> + Clone,
)]
#[benchmarks(where <T as Config>::RuntimeCall: From<frame_system::Call<T>>)]
mod benchmarks {
use super::*;
@@ -94,23 +85,5 @@ mod benchmarks {
assert_last_event::<T>(Event::KeyRemoved {});
}
#[benchmark]
fn check_only_sudo_account() {
let caller: T::AccountId = whitelisted_caller();
Key::<T>::put(&caller);
let call = frame_system::Call::remark { remark: vec![] }.into();
let info = DispatchInfo { ..Default::default() };
let ext = CheckOnlySudoAccount::<T>::new();
#[block]
{
assert!(ext
.test_run(RawOrigin::Signed(caller).into(), &call, &info, 0, |_| Ok(().into()))
.unwrap()
.is_ok());
}
}
impl_benchmark_test_suite!(Pallet, crate::mock::new_bench_ext(), crate::mock::Test);
}
+31 -47
View File
@@ -20,14 +20,10 @@ use codec::{Decode, Encode};
use frame_support::{dispatch::DispatchInfo, ensure};
use scale_info::TypeInfo;
use sp_runtime::{
impl_tx_ext_default,
traits::{
AsSystemOriginSigner, DispatchInfoOf, Dispatchable, TransactionExtension,
TransactionExtensionBase,
},
traits::{DispatchInfoOf, Dispatchable, SignedExtension},
transaction_validity::{
InvalidTransaction, TransactionPriority, TransactionValidityError, UnknownTransaction,
ValidTransaction,
InvalidTransaction, TransactionPriority, TransactionValidity, TransactionValidityError,
UnknownTransaction, ValidTransaction,
},
};
use sp_std::{fmt, marker::PhantomData};
@@ -63,61 +59,49 @@ impl<T: Config + Send + Sync> fmt::Debug for CheckOnlySudoAccount<T> {
}
impl<T: Config + Send + Sync> CheckOnlySudoAccount<T> {
/// Creates new `TransactionExtension` to check sudo key.
/// Creates new `SignedExtension` to check sudo key.
pub fn new() -> Self {
Self::default()
}
}
impl<T: Config + Send + Sync> TransactionExtensionBase for CheckOnlySudoAccount<T> {
const IDENTIFIER: &'static str = "CheckOnlySudoAccount";
type Implicit = ();
fn weight(&self) -> frame_support::weights::Weight {
use crate::weights::WeightInfo;
T::WeightInfo::check_only_sudo_account()
}
}
impl<T: Config + Send + Sync, Context>
TransactionExtension<<T as frame_system::Config>::RuntimeCall, Context> for CheckOnlySudoAccount<T>
impl<T: Config + Send + Sync> SignedExtension for CheckOnlySudoAccount<T>
where
<T as frame_system::Config>::RuntimeCall: Dispatchable<Info = DispatchInfo>,
<<T as frame_system::Config>::RuntimeCall as Dispatchable>::RuntimeOrigin:
AsSystemOriginSigner<T::AccountId> + Clone,
<T as Config>::RuntimeCall: Dispatchable<Info = DispatchInfo>,
{
const IDENTIFIER: &'static str = "CheckOnlySudoAccount";
type AccountId = T::AccountId;
type Call = <T as Config>::RuntimeCall;
type AdditionalSigned = ();
type Pre = ();
type Val = ();
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Ok(())
}
fn validate(
&self,
origin: <<T as frame_system::Config>::RuntimeCall as Dispatchable>::RuntimeOrigin,
_call: &<T as frame_system::Config>::RuntimeCall,
info: &DispatchInfoOf<<T as frame_system::Config>::RuntimeCall>,
who: &Self::AccountId,
_call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
_len: usize,
_context: &mut Context,
_self_implicit: Self::Implicit,
_inherited_implication: &impl Encode,
) -> Result<
(
ValidTransaction,
Self::Val,
<<T as frame_system::Config>::RuntimeCall as Dispatchable>::RuntimeOrigin,
),
TransactionValidityError,
> {
let who = origin.as_system_origin_signer().ok_or(InvalidTransaction::BadSigner)?;
) -> TransactionValidity {
let sudo_key: T::AccountId = Key::<T>::get().ok_or(UnknownTransaction::CannotLookup)?;
ensure!(*who == sudo_key, InvalidTransaction::BadSigner);
Ok((
ValidTransaction {
priority: info.weight.ref_time() as TransactionPriority,
..Default::default()
},
(),
origin,
))
Ok(ValidTransaction {
priority: info.weight.ref_time() as TransactionPriority,
..Default::default()
})
}
impl_tx_ext_default!(<T as frame_system::Config>::RuntimeCall; Context; prepare);
fn pre_dispatch(
self,
who: &Self::AccountId,
call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
self.validate(who, call, info, len).map(|_| ())
}
}
+2 -2
View File
@@ -85,8 +85,8 @@
//! meant to be used by constructing runtime calls from outside the runtime.
//! </pre></div>
//!
//! This pallet also defines a [`TransactionExtension`](sp_runtime::traits::TransactionExtension)
//! called [`CheckOnlySudoAccount`] to ensure that only signed transactions by the sudo account are
//! This pallet also defines a [`SignedExtension`](sp_runtime::traits::SignedExtension) called
//! [`CheckOnlySudoAccount`] to ensure that only signed transactions by the sudo account are
//! accepted by the transaction pool. The intended use of this signed extension is to prevent other
//! accounts from spamming the transaction pool for the initial phase of a chain, during which
//! developers may only want a sudo account to be able to make transactions.
+24 -47
View File
@@ -17,28 +17,26 @@
//! Autogenerated weights for `pallet_sudo`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-03-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-11-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `runner-bn-ce5rx-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! HOSTNAME: `runner-yprdrvc7-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024`
// Executed Command:
// ./target/production/substrate-node
// target/production/substrate-node
// benchmark
// pallet
// --chain=dev
// --steps=50
// --repeat=20
// --pallet=pallet_sudo
// --no-storage-info
// --no-median-slopes
// --no-min-squares
// --extrinsic=*
// --wasm-execution=compiled
// --heap-pages=4096
// --output=./substrate/frame/sudo/src/weights.rs
// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json
// --pallet=pallet_sudo
// --chain=dev
// --header=./substrate/HEADER-APACHE2
// --output=./substrate/frame/sudo/src/weights.rs
// --template=./substrate/.maintain/frame-weight-template.hbs
#![cfg_attr(rustfmt, rustfmt_skip)]
@@ -55,7 +53,6 @@ pub trait WeightInfo {
fn sudo() -> Weight;
fn sudo_as() -> Weight;
fn remove_key() -> Weight;
fn check_only_sudo_account() -> Weight;
}
/// Weights for `pallet_sudo` using the Substrate node and recommended hardware.
@@ -67,8 +64,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 9_590_000 picoseconds.
Weight::from_parts(9_924_000, 1517)
// Minimum execution time: 9_600_000 picoseconds.
Weight::from_parts(10_076_000, 1517)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
@@ -78,8 +75,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 9_825_000 picoseconds.
Weight::from_parts(10_373_000, 1517)
// Minimum execution time: 10_453_000 picoseconds.
Weight::from_parts(10_931_000, 1517)
.saturating_add(T::DbWeight::get().reads(1_u64))
}
/// Storage: `Sudo::Key` (r:1 w:0)
@@ -88,8 +85,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 10_140_000 picoseconds.
Weight::from_parts(10_382_000, 1517)
// Minimum execution time: 10_202_000 picoseconds.
Weight::from_parts(10_800_000, 1517)
.saturating_add(T::DbWeight::get().reads(1_u64))
}
/// Storage: `Sudo::Key` (r:1 w:1)
@@ -98,21 +95,11 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 8_610_000 picoseconds.
Weight::from_parts(8_975_000, 1517)
// Minimum execution time: 8_555_000 picoseconds.
Weight::from_parts(8_846_000, 1517)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `Sudo::Key` (r:1 w:0)
/// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn check_only_sudo_account() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 3_416_000 picoseconds.
Weight::from_parts(3_645_000, 1517)
.saturating_add(T::DbWeight::get().reads(1_u64))
}
}
// For backwards compatibility and tests.
@@ -123,8 +110,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 9_590_000 picoseconds.
Weight::from_parts(9_924_000, 1517)
// Minimum execution time: 9_600_000 picoseconds.
Weight::from_parts(10_076_000, 1517)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
@@ -134,8 +121,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 9_825_000 picoseconds.
Weight::from_parts(10_373_000, 1517)
// Minimum execution time: 10_453_000 picoseconds.
Weight::from_parts(10_931_000, 1517)
.saturating_add(RocksDbWeight::get().reads(1_u64))
}
/// Storage: `Sudo::Key` (r:1 w:0)
@@ -144,8 +131,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 10_140_000 picoseconds.
Weight::from_parts(10_382_000, 1517)
// Minimum execution time: 10_202_000 picoseconds.
Weight::from_parts(10_800_000, 1517)
.saturating_add(RocksDbWeight::get().reads(1_u64))
}
/// Storage: `Sudo::Key` (r:1 w:1)
@@ -154,19 +141,9 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 8_610_000 picoseconds.
Weight::from_parts(8_975_000, 1517)
// Minimum execution time: 8_555_000 picoseconds.
Weight::from_parts(8_846_000, 1517)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `Sudo::Key` (r:1 w:0)
/// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn check_only_sudo_account() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 3_416_000 picoseconds.
Weight::from_parts(3_645_000, 1517)
.saturating_add(RocksDbWeight::get().reads(1_u64))
}
}