Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

allow tip value of 1 #10425

Merged
merged 5 commits into from
Dec 6, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions frame/transaction-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ use scale_info::TypeInfo;

use sp_runtime::{
traits::{
Convert, DispatchInfoOf, Dispatchable, PostDispatchInfoOf, SaturatedConversion, Saturating,
SignedExtension, Zero,
Convert, DispatchInfoOf, Dispatchable, One, PostDispatchInfoOf, SaturatedConversion,
Saturating, SignedExtension, Zero,
},
transaction_validity::{
TransactionPriority, TransactionValidity, TransactionValidityError, ValidTransaction,
Expand Down Expand Up @@ -649,9 +649,9 @@ where
.saturated_into::<BalanceOf<T>>();
let max_reward = |val: BalanceOf<T>| val.saturating_mul(max_tx_per_block);

// To distribute no-tip transactions a little bit, we set the minimal tip as `1`.
// To distribute no-tip transactions a little bit, we increase the tip value by one.
// This means that given two transactions without a tip, smaller one will be preferred.
let tip = tip.max(1.saturated_into());
let tip = tip.saturating_add(One::one());
let scaled_tip = max_reward(tip);

match info.class {
Expand Down Expand Up @@ -1480,14 +1480,14 @@ mod tests {
.unwrap()
.priority;

assert_eq!(priority, 50);
assert_eq!(priority, 60);

let priority = ChargeTransactionPayment::<Runtime>(2 * tip)
.validate(&2, CALL, &normal, len)
.unwrap()
.priority;

assert_eq!(priority, 100);
assert_eq!(priority, 110);
});

ExtBuilder::default().balance_factor(100).build().execute_with(|| {
Expand All @@ -1500,13 +1500,13 @@ mod tests {
.validate(&2, CALL, &op, len)
.unwrap()
.priority;
assert_eq!(priority, 5800);
assert_eq!(priority, 5810);

let priority = ChargeTransactionPayment::<Runtime>(2 * tip)
.validate(&2, CALL, &op, len)
.unwrap()
.priority;
assert_eq!(priority, 6100);
assert_eq!(priority, 6110);
});
}

Expand Down Expand Up @@ -1540,6 +1540,36 @@ mod tests {
});
}

#[test]
fn one_tip_has_more_priority() {
xlc marked this conversation as resolved.
Show resolved Hide resolved
let tip = 1;
let len = 10;

ExtBuilder::default().balance_factor(100).build().execute_with(|| {
let normal =
DispatchInfo { weight: 100, class: DispatchClass::Normal, pays_fee: Pays::Yes };
let priority = ChargeTransactionPayment::<Runtime>(tip)
.validate(&2, CALL, &normal, len)
.unwrap()
.priority;

assert_eq!(priority, 20);
});

ExtBuilder::default().balance_factor(100).build().execute_with(|| {
let op = DispatchInfo {
weight: 100,
class: DispatchClass::Operational,
pays_fee: Pays::Yes,
};
let priority = ChargeTransactionPayment::<Runtime>(tip)
.validate(&2, CALL, &op, len)
.unwrap()
.priority;
assert_eq!(priority, 5570);
});
}

#[test]
fn post_info_can_change_pays_fee() {
ExtBuilder::default()
Expand Down