mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 09:57:56 +00:00
Make CheckNonce refuse transactions signed by accounts with no providers (#1578)
See #1453. Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -20,7 +20,7 @@ use codec::{Decode, Encode};
|
||||
use frame_support::dispatch::DispatchInfo;
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{
|
||||
traits::{DispatchInfoOf, Dispatchable, One, SignedExtension},
|
||||
traits::{DispatchInfoOf, Dispatchable, One, SignedExtension, Zero},
|
||||
transaction_validity::{
|
||||
InvalidTransaction, TransactionLongevity, TransactionValidity, TransactionValidityError,
|
||||
ValidTransaction,
|
||||
@@ -80,6 +80,10 @@ where
|
||||
_len: usize,
|
||||
) -> Result<(), TransactionValidityError> {
|
||||
let mut account = crate::Account::<T>::get(who);
|
||||
if account.providers.is_zero() && account.sufficients.is_zero() {
|
||||
// Nonce storage not paid for
|
||||
return Err(InvalidTransaction::Payment.into())
|
||||
}
|
||||
if self.0 != account.nonce {
|
||||
return Err(if self.0 < account.nonce {
|
||||
InvalidTransaction::Stale
|
||||
@@ -100,8 +104,11 @@ where
|
||||
_info: &DispatchInfoOf<Self::Call>,
|
||||
_len: usize,
|
||||
) -> TransactionValidity {
|
||||
// check index
|
||||
let account = crate::Account::<T>::get(who);
|
||||
if account.providers.is_zero() && account.sufficients.is_zero() {
|
||||
// Nonce storage not paid for
|
||||
return InvalidTransaction::Payment.into()
|
||||
}
|
||||
if self.0 < account.nonce {
|
||||
return InvalidTransaction::Stale.into()
|
||||
}
|
||||
@@ -137,7 +144,7 @@ mod tests {
|
||||
crate::AccountInfo {
|
||||
nonce: 1,
|
||||
consumers: 0,
|
||||
providers: 0,
|
||||
providers: 1,
|
||||
sufficients: 0,
|
||||
data: 0,
|
||||
},
|
||||
@@ -164,4 +171,47 @@ mod tests {
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn signed_ext_check_nonce_requires_provider() {
|
||||
new_test_ext().execute_with(|| {
|
||||
crate::Account::<Test>::insert(
|
||||
2,
|
||||
crate::AccountInfo {
|
||||
nonce: 1,
|
||||
consumers: 0,
|
||||
providers: 1,
|
||||
sufficients: 0,
|
||||
data: 0,
|
||||
},
|
||||
);
|
||||
crate::Account::<Test>::insert(
|
||||
3,
|
||||
crate::AccountInfo {
|
||||
nonce: 1,
|
||||
consumers: 0,
|
||||
providers: 0,
|
||||
sufficients: 1,
|
||||
data: 0,
|
||||
},
|
||||
);
|
||||
let info = DispatchInfo::default();
|
||||
let len = 0_usize;
|
||||
// Both providers and sufficients zero
|
||||
assert_noop!(
|
||||
CheckNonce::<Test>(1).validate(&1, CALL, &info, len),
|
||||
InvalidTransaction::Payment
|
||||
);
|
||||
assert_noop!(
|
||||
CheckNonce::<Test>(1).pre_dispatch(&1, CALL, &info, len),
|
||||
InvalidTransaction::Payment
|
||||
);
|
||||
// Non-zero providers
|
||||
assert_ok!(CheckNonce::<Test>(1).validate(&2, CALL, &info, len));
|
||||
assert_ok!(CheckNonce::<Test>(1).pre_dispatch(&2, CALL, &info, len));
|
||||
// Non-zero sufficients
|
||||
assert_ok!(CheckNonce::<Test>(1).validate(&3, CALL, &info, len));
|
||||
assert_ok!(CheckNonce::<Test>(1).pre_dispatch(&3, CALL, &info, len));
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user