mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 19:17:58 +00:00
Partial fix for transaction priority (#7034)
* Partial fix for priority stuff. * Small fix * Fix tests. * Update frame/transaction-payment/src/lib.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Better doc Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
This commit is contained in:
@@ -25,12 +25,15 @@ use sp_runtime::{
|
||||
traits::{SignedExtension, DispatchInfoOf, Dispatchable, One},
|
||||
transaction_validity::{
|
||||
ValidTransaction, TransactionValidityError, InvalidTransaction, TransactionValidity,
|
||||
TransactionLongevity, TransactionPriority,
|
||||
TransactionLongevity,
|
||||
},
|
||||
};
|
||||
use sp_std::vec;
|
||||
|
||||
/// Nonce check and increment to give replay protection for transactions.
|
||||
///
|
||||
/// Note that this does not set any priority by default. Make sure that AT LEAST one of the signed
|
||||
/// extension sets some kind of priority upon validating transactions.
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
|
||||
pub struct CheckNonce<T: Trait>(#[codec(compact)] T::Index);
|
||||
|
||||
@@ -90,7 +93,7 @@ impl<T: Trait> SignedExtension for CheckNonce<T> where
|
||||
&self,
|
||||
who: &Self::AccountId,
|
||||
_call: &Self::Call,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
_info: &DispatchInfoOf<Self::Call>,
|
||||
_len: usize,
|
||||
) -> TransactionValidity {
|
||||
// check index
|
||||
@@ -107,7 +110,7 @@ impl<T: Trait> SignedExtension for CheckNonce<T> where
|
||||
};
|
||||
|
||||
Ok(ValidTransaction {
|
||||
priority: info.weight as TransactionPriority,
|
||||
priority: 0,
|
||||
requires,
|
||||
provides,
|
||||
longevity: TransactionLongevity::max_value(),
|
||||
|
||||
@@ -27,7 +27,7 @@ use sp_runtime::{
|
||||
};
|
||||
use frame_support::{
|
||||
traits::{Get},
|
||||
weights::{PostDispatchInfo, DispatchInfo, DispatchClass},
|
||||
weights::{PostDispatchInfo, DispatchInfo, DispatchClass, priority::FrameTransactionPriority},
|
||||
StorageValue,
|
||||
};
|
||||
|
||||
@@ -157,12 +157,18 @@ impl<T: Trait + Send + Sync> CheckWeight<T> where
|
||||
}
|
||||
|
||||
/// get the priority of an extrinsic denoted by `info`.
|
||||
///
|
||||
/// Operational transaction will be given a fixed initial amount to be fairly distinguished from
|
||||
/// the normal ones.
|
||||
fn get_priority(info: &DispatchInfoOf<T::Call>) -> TransactionPriority {
|
||||
match info.class {
|
||||
DispatchClass::Normal => info.weight.into(),
|
||||
// Don't use up the whole priority space, to allow things like `tip`
|
||||
// to be taken into account as well.
|
||||
DispatchClass::Operational => TransactionPriority::max_value() / 2,
|
||||
// Normal transaction.
|
||||
DispatchClass::Normal =>
|
||||
FrameTransactionPriority::Normal(info.weight.into()).into(),
|
||||
// Don't use up the whole priority space, to allow things like `tip` to be taken into
|
||||
// account as well.
|
||||
DispatchClass::Operational =>
|
||||
FrameTransactionPriority::Operational(info.weight.into()).into(),
|
||||
// Mandatory extrinsics are only for inherents; never transactions.
|
||||
DispatchClass::Mandatory => TransactionPriority::min_value(),
|
||||
}
|
||||
@@ -496,7 +502,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn signed_ext() {
|
||||
fn signed_ext_check_weight_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let normal = DispatchInfo { weight: 100, class: DispatchClass::Normal, pays_fee: Pays::Yes };
|
||||
let op = DispatchInfo { weight: 100, class: DispatchClass::Operational, pays_fee: Pays::Yes };
|
||||
@@ -512,7 +518,7 @@ mod tests {
|
||||
.validate(&1, CALL, &op, len)
|
||||
.unwrap()
|
||||
.priority;
|
||||
assert_eq!(priority, u64::max_value() / 2);
|
||||
assert_eq!(priority, frame_support::weights::priority::LIMIT + 100);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user