Skip to content

Commit 2af6e2c

Browse files
committed
Joshy Premerging for early access: Allow adjusting priority coming from Signed Extensions (paritytech#9596)
1 parent fdedb87 commit 2af6e2c

File tree

6 files changed

+350
-5
lines changed

6 files changed

+350
-5
lines changed

bin/node/cli/src/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ mod tests {
803803
let check_genesis = frame_system::CheckGenesis::new();
804804
let check_era = frame_system::CheckEra::from(Era::Immortal);
805805
let check_nonce = frame_system::CheckNonce::from(index);
806-
let check_weight = frame_system::CheckWeight::new();
806+
let check_weight = frame_system::CheckWeight::new().into();
807807
let payment = pallet_transaction_payment::ChargeTransactionPayment::from(0);
808808
let extra = (
809809
check_spec_version,

bin/node/runtime/src/lib.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use codec::{Decode, Encode, MaxEncodedLen};
2626
use frame_support::{
2727
construct_runtime, parameter_types,
28+
signed_extensions::{AdjustPriority, Divide},
2829
traits::{
2930
Currency, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem, LockIdentifier,
3031
Nothing, OnUnbalanced, U128CurrencyToVote,
@@ -912,7 +913,7 @@ where
912913
frame_system::CheckGenesis::<Runtime>::new(),
913914
frame_system::CheckEra::<Runtime>::from(era),
914915
frame_system::CheckNonce::<Runtime>::from(nonce),
915-
frame_system::CheckWeight::<Runtime>::new(),
916+
frame_system::CheckWeight::<Runtime>::new().into(),
916917
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
917918
);
918919
let raw_payload = SignedPayload::new(call, extra)
@@ -1248,7 +1249,7 @@ pub type SignedExtra = (
12481249
frame_system::CheckGenesis<Runtime>,
12491250
frame_system::CheckEra<Runtime>,
12501251
frame_system::CheckNonce<Runtime>,
1251-
frame_system::CheckWeight<Runtime>,
1252+
AdjustPriority<frame_system::CheckWeight<Runtime>, Divide, CHECK_WEIGHT_PRIORITY_DIVISOR>,
12521253
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
12531254
);
12541255
/// Unchecked extrinsic type as expected by this runtime.
@@ -1277,6 +1278,22 @@ mod mmr {
12771278
pub type Hashing = <Runtime as pallet_mmr::Config>::Hashing;
12781279
}
12791280

1281+
/// There are two extnsions returning the priority:
1282+
/// 1. The `CheckWeight` extension.
1283+
/// 2. The `TransactionPayment` extension.
1284+
///
1285+
/// The first one gives a significant bump to `Operational` transactions, but for `Normal`
1286+
/// it's within `[0..MAXIMUM_BLOCK_WEIGHT]` range.
1287+
///
1288+
/// The second one roughly represents the amount of fees being paid (and the tip) with
1289+
/// size-adjustment coefficient. I.e. we are interested to maximize `fee/consumed_weight` or
1290+
/// `fee/size_limit`. The returned value is potentially unbounded though.
1291+
///
1292+
/// The idea for the adjustment is scale the priority coming from `CheckWeight` for
1293+
/// `Normal` transactions down to zero, leaving the priority bump for `Operational` and
1294+
/// `Mandatory` though.
1295+
const CHECK_WEIGHT_PRIORITY_DIVISOR: TransactionPriority = MAXIMUM_BLOCK_WEIGHT;
1296+
12801297
impl_runtime_apis! {
12811298
impl sp_api::Core<Block> for Runtime {
12821299
fn version() -> RuntimeVersion {

bin/node/test-runner-example/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl ChainInfo for NodeTemplateChainInfo {
6868
frame_system::CheckNonce::<Self::Runtime>::from(
6969
frame_system::Pallet::<Self::Runtime>::account_nonce(from),
7070
),
71-
frame_system::CheckWeight::<Self::Runtime>::new(),
71+
frame_system::CheckWeight::<Self::Runtime>::new().into(),
7272
pallet_transaction_payment::ChargeTransactionPayment::<Self::Runtime>::from(0),
7373
)
7474
}

bin/node/testing/src/keyring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn signed_extra(nonce: Index, extra_fee: Balance) -> SignedExtra {
7575
frame_system::CheckGenesis::new(),
7676
frame_system::CheckEra::from(Era::mortal(256, 0)),
7777
frame_system::CheckNonce::from(nonce),
78-
frame_system::CheckWeight::new(),
78+
frame_system::CheckWeight::new().into(),
7979
pallet_transaction_payment::ChargeTransactionPayment::from(extra_fee),
8080
)
8181
}

frame/support/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub mod inherent;
6060
pub mod error;
6161
pub mod instances;
6262
pub mod migrations;
63+
pub mod signed_extensions;
6364
pub mod traits;
6465
pub mod weights;
6566

0 commit comments

Comments
 (0)