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
@@ -20,12 +20,10 @@ use codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_runtime::{
generic::Era,
impl_tx_ext_default,
traits::{
DispatchInfoOf, SaturatedConversion, TransactionExtension, TransactionExtensionBase,
ValidateResult,
traits::{DispatchInfoOf, SaturatedConversion, SignedExtension},
transaction_validity::{
InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction,
},
transaction_validity::{InvalidTransaction, TransactionValidityError, ValidTransaction},
};
/// Check for transaction mortality.
@@ -56,11 +54,29 @@ impl<T: Config + Send + Sync> sp_std::fmt::Debug for CheckMortality<T> {
}
}
impl<T: Config + Send + Sync> TransactionExtensionBase for CheckMortality<T> {
impl<T: Config + Send + Sync> SignedExtension for CheckMortality<T> {
type AccountId = T::AccountId;
type Call = T::RuntimeCall;
type AdditionalSigned = T::Hash;
type Pre = ();
const IDENTIFIER: &'static str = "CheckMortality";
type Implicit = T::Hash;
fn implicit(&self) -> Result<Self::Implicit, TransactionValidityError> {
fn validate(
&self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
let current_u64 = <Pallet<T>>::block_number().saturated_into::<u64>();
let valid_till = self.0.death(current_u64);
Ok(ValidTransaction {
longevity: valid_till.saturating_sub(current_u64),
..Default::default()
})
}
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
let current_u64 = <Pallet<T>>::block_number().saturated_into::<u64>();
let n = self.0.birth(current_u64).saturated_into::<BlockNumberFor<T>>();
if !<BlockHash<T>>::contains_key(n) {
@@ -69,38 +85,16 @@ impl<T: Config + Send + Sync> TransactionExtensionBase for CheckMortality<T> {
Ok(<Pallet<T>>::block_hash(n))
}
}
fn weight(&self) -> sp_weights::Weight {
<T::ExtensionsWeightInfo as super::WeightInfo>::check_mortality()
}
}
impl<T: Config + Send + Sync, Context> TransactionExtension<T::RuntimeCall, Context>
for CheckMortality<T>
{
type Pre = ();
type Val = ();
fn validate(
&self,
origin: <T as Config>::RuntimeOrigin,
_call: &T::RuntimeCall,
_info: &DispatchInfoOf<T::RuntimeCall>,
_len: usize,
_context: &mut Context,
_self_implicit: Self::Implicit,
_inherited_implication: &impl Encode,
) -> ValidateResult<Self::Val, T::RuntimeCall> {
let current_u64 = <Pallet<T>>::block_number().saturated_into::<u64>();
let valid_till = self.0.death(current_u64);
Ok((
ValidTransaction {
longevity: valid_till.saturating_sub(current_u64),
..Default::default()
},
(),
origin,
))
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(|_| ())
}
impl_tx_ext_default!(T::RuntimeCall; Context; prepare);
}
#[cfg(test)]
@@ -112,21 +106,23 @@ mod tests {
weights::Weight,
};
use sp_core::H256;
use sp_runtime::traits::DispatchTransaction;
#[test]
fn signed_ext_check_era_should_work() {
new_test_ext().execute_with(|| {
// future
assert_eq!(
CheckMortality::<Test>::from(Era::mortal(4, 2)).implicit().err().unwrap(),
CheckMortality::<Test>::from(Era::mortal(4, 2))
.additional_signed()
.err()
.unwrap(),
InvalidTransaction::AncientBirthBlock.into(),
);
// correct
System::set_block_number(13);
<BlockHash<Test>>::insert(12, H256::repeat_byte(1));
assert!(CheckMortality::<Test>::from(Era::mortal(4, 12)).implicit().is_ok());
assert!(CheckMortality::<Test>::from(Era::mortal(4, 12)).additional_signed().is_ok());
})
}
@@ -146,10 +142,7 @@ mod tests {
System::set_block_number(17);
<BlockHash<Test>>::insert(16, H256::repeat_byte(1));
assert_eq!(
ext.validate_only(Some(1).into(), CALL, &normal, len).unwrap().0.longevity,
15
);
assert_eq!(ext.validate(&1, CALL, &normal, len).unwrap().longevity, 15);
})
}
}