Skip to content

Commit 0e27b88

Browse files
authored
Fixes validation for SkipCheckIfFeeless extension (paritytech#3993)
During validation, `SkipCheckIfFeeless` should check if the call is `feeless` and delegate to the wrapped extension if not.
1 parent d733c77 commit 0e27b88

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

substrate/frame/transaction-payment/skip-feeless-payment/src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use frame_support::{
4343
use scale_info::{StaticTypeInfo, TypeInfo};
4444
use sp_runtime::{
4545
traits::{DispatchInfoOf, PostDispatchInfoOf, SignedExtension},
46-
transaction_validity::TransactionValidityError,
46+
transaction_validity::{TransactionValidity, TransactionValidityError, ValidTransaction},
4747
};
4848

4949
#[cfg(test)]
@@ -122,6 +122,20 @@ where
122122
self.0.additional_signed()
123123
}
124124

125+
fn validate(
126+
&self,
127+
who: &Self::AccountId,
128+
call: &Self::Call,
129+
info: &DispatchInfoOf<Self::Call>,
130+
len: usize,
131+
) -> TransactionValidity {
132+
if call.is_feeless(&<T as frame_system::Config>::RuntimeOrigin::signed(who.clone())) {
133+
Ok(ValidTransaction::default())
134+
} else {
135+
self.0.validate(who, call, info, len)
136+
}
137+
}
138+
125139
fn pre_dispatch(
126140
self,
127141
who: &Self::AccountId,

substrate/frame/transaction-payment/skip-feeless-payment/src/mock.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ impl Config for Runtime {
3333

3434
parameter_types! {
3535
pub static PreDispatchCount: u32 = 0;
36+
pub static ValidateCount: u32 = 0;
3637
}
3738

3839
#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, TypeInfo)]
@@ -47,6 +48,18 @@ impl SignedExtension for DummyExtension {
4748
fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> {
4849
Ok(())
4950
}
51+
52+
fn validate(
53+
&self,
54+
_who: &Self::AccountId,
55+
_call: &Self::Call,
56+
_info: &DispatchInfoOf<Self::Call>,
57+
_len: usize,
58+
) -> TransactionValidity {
59+
ValidateCount::mutate(|c| *c += 1);
60+
Ok(Default::default())
61+
}
62+
5063
fn pre_dispatch(
5164
self,
5265
_who: &Self::AccountId,

substrate/frame/transaction-payment/skip-feeless-payment/src/tests.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
// limitations under the License.
1515

1616
use super::*;
17-
use crate::mock::{pallet_dummy::Call, DummyExtension, PreDispatchCount, Runtime, RuntimeCall};
17+
use crate::mock::{
18+
pallet_dummy::Call, DummyExtension, PreDispatchCount, Runtime, RuntimeCall, ValidateCount,
19+
};
1820
use frame_support::dispatch::DispatchInfo;
1921

2022
#[test]
@@ -31,3 +33,20 @@ fn skip_feeless_payment_works() {
3133
.unwrap();
3234
assert_eq!(PreDispatchCount::get(), 1);
3335
}
36+
37+
#[test]
38+
fn validate_works() {
39+
assert_eq!(ValidateCount::get(), 0);
40+
41+
let call = RuntimeCall::DummyPallet(Call::<Runtime>::aux { data: 1 });
42+
SkipCheckIfFeeless::<Runtime, DummyExtension>::from(DummyExtension)
43+
.validate(&0, &call, &DispatchInfo::default(), 0)
44+
.unwrap();
45+
assert_eq!(ValidateCount::get(), 1);
46+
47+
let call = RuntimeCall::DummyPallet(Call::<Runtime>::aux { data: 0 });
48+
SkipCheckIfFeeless::<Runtime, DummyExtension>::from(DummyExtension)
49+
.validate(&0, &call, &DispatchInfo::default(), 0)
50+
.unwrap();
51+
assert_eq!(ValidateCount::get(), 1);
52+
}

0 commit comments

Comments
 (0)