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

Allow adjusting priority coming from Signed Extensions #9596

Closed
wants to merge 13 commits into from
2 changes: 1 addition & 1 deletion bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ mod tests {
let check_genesis = frame_system::CheckGenesis::new();
let check_era = frame_system::CheckEra::from(Era::Immortal);
let check_nonce = frame_system::CheckNonce::from(index);
let check_weight = frame_system::CheckWeight::new();
let check_weight = frame_system::CheckWeight::new().into();
let payment = pallet_transaction_payment::ChargeTransactionPayment::from(0);
let extra = (
check_spec_version,
Expand Down
21 changes: 19 additions & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
construct_runtime, parameter_types,
signed_extensions::{AdjustPriority, Divide},
traits::{
Currency, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem, LockIdentifier,
Nothing, OnUnbalanced, U128CurrencyToVote,
Expand Down Expand Up @@ -927,7 +928,7 @@ where
frame_system::CheckGenesis::<Runtime>::new(),
frame_system::CheckEra::<Runtime>::from(era),
frame_system::CheckNonce::<Runtime>::from(nonce),
frame_system::CheckWeight::<Runtime>::new(),
frame_system::CheckWeight::<Runtime>::new().into(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
);
let raw_payload = SignedPayload::new(call, extra)
Expand Down Expand Up @@ -1268,7 +1269,7 @@ pub type SignedExtra = (
frame_system::CheckGenesis<Runtime>,
frame_system::CheckEra<Runtime>,
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
AdjustPriority<frame_system::CheckWeight<Runtime>, Divide, CHECK_WEIGHT_PRIORITY_DIVISOR>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
Expand Down Expand Up @@ -1297,6 +1298,22 @@ mod mmr {
pub type Hashing = <Runtime as pallet_mmr::Config>::Hashing;
}

/// There are two extensions returning the priority:
/// 1. The `CheckWeight` extension.
/// 2. The `TransactionPayment` extension.
///
/// The first one gives a significant bump to `Operational` transactions, but for `Normal`
/// it's within `[0..MAXIMUM_BLOCK_WEIGHT]` range.
///
/// The second one roughly represents the amount of fees being paid (and the tip) with
/// size-adjustment coefficient. I.e. we are interested to maximize `fee/consumed_weight` or
/// `fee/size_limit`. The returned value is potentially unbounded though.
///
/// The idea for the adjustment is scale the priority coming from `CheckWeight` for
/// `Normal` transactions down to zero, leaving the priority bump for `Operational` and
/// `Mandatory` though.
const CHECK_WEIGHT_PRIORITY_DIVISOR: TransactionPriority = MAXIMUM_BLOCK_WEIGHT;

impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
Expand Down
2 changes: 1 addition & 1 deletion bin/node/test-runner-example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl ChainInfo for NodeTemplateChainInfo {
frame_system::CheckNonce::<Self::Runtime>::from(
frame_system::Pallet::<Self::Runtime>::account_nonce(from),
),
frame_system::CheckWeight::<Self::Runtime>::new(),
frame_system::CheckWeight::<Self::Runtime>::new().into(),
pallet_transaction_payment::ChargeTransactionPayment::<Self::Runtime>::from(0),
)
}
Expand Down
2 changes: 1 addition & 1 deletion bin/node/testing/src/keyring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn signed_extra(nonce: Index, extra_fee: Balance) -> SignedExtra {
frame_system::CheckGenesis::new(),
frame_system::CheckEra::from(Era::mortal(256, 0)),
frame_system::CheckNonce::from(nonce),
frame_system::CheckWeight::new(),
frame_system::CheckWeight::new().into(),
pallet_transaction_payment::ChargeTransactionPayment::from(extra_fee),
)
}
Expand Down
1 change: 1 addition & 0 deletions frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub mod inherent;
pub mod error;
pub mod instances;
pub mod migrations;
pub mod signed_extensions;
pub mod traits;
pub mod weights;

Expand Down
Loading