mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 15:51:12 +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:
@@ -467,6 +467,23 @@ impl<T: Trait + Send + Sync> ChargeTransactionPayment<T> where
|
||||
Err(_) => Err(InvalidTransaction::Payment.into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get an appropriate priority for a transaction with the given length and info.
|
||||
///
|
||||
/// This will try and optimise the `fee/weight` `fee/length`, whichever is consuming more of the
|
||||
/// maximum corresponding limit.
|
||||
///
|
||||
/// For example, if a transaction consumed 1/4th of the block length and half of the weight, its
|
||||
/// final priority is `fee * min(2, 4) = fee * 2`. If it consumed `1/4th` of the block length
|
||||
/// and the entire block weight `(1/1)`, its priority is `fee * min(1, 4) = fee * 1`. This means
|
||||
/// that the transaction which consumes more resources (either length or weight) with the same
|
||||
/// `fee` ends up having lower priority.
|
||||
fn get_priority(len: usize, info: &DispatchInfoOf<T::Call>, final_fee: BalanceOf<T>) -> TransactionPriority {
|
||||
let weight_saturation = T::MaximumBlockWeight::get() / info.weight.max(1);
|
||||
let len_saturation = T::MaximumBlockLength::get() as u64 / (len as u64).max(1);
|
||||
let coefficient: BalanceOf<T> = weight_saturation.min(len_saturation).saturated_into::<BalanceOf<T>>();
|
||||
final_fee.saturating_mul(coefficient).saturated_into::<TransactionPriority>()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait + Send + Sync> sp_std::fmt::Debug for ChargeTransactionPayment<T> {
|
||||
@@ -499,12 +516,10 @@ impl<T: Trait + Send + Sync> SignedExtension for ChargeTransactionPayment<T> whe
|
||||
len: usize,
|
||||
) -> TransactionValidity {
|
||||
let (fee, _) = self.withdraw_fee(who, info, len)?;
|
||||
|
||||
let mut r = ValidTransaction::default();
|
||||
// NOTE: we probably want to maximize the _fee (of any type) per weight unit_ here, which
|
||||
// will be a bit more than setting the priority to tip. For now, this is enough.
|
||||
r.priority = fee.saturated_into::<TransactionPriority>();
|
||||
Ok(r)
|
||||
Ok(ValidTransaction {
|
||||
priority: Self::get_priority(len, info, fee),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn pre_dispatch(
|
||||
|
||||
Reference in New Issue
Block a user