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

Commit 2dbf625

Browse files
notleshjoepetrowskiggwpez
authored
Add WeightToFee and LengthToFee impls to transaction-payment Runtime API (#13110)
* Add WeightToFee and LengthToFee impls to RPC * Remove RPC additions * Update frame/transaction-payment/rpc/runtime-api/src/lib.rs Co-authored-by: joe petrowski <[email protected]> * Add comments to length_to_fee and weight_to_fee Co-authored-by: joe petrowski <[email protected]> Co-authored-by: Oliver Tale-Yazdi <[email protected]>
1 parent f4bc993 commit 2dbf625

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

bin/node-template/runtime/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@ impl_runtime_apis! {
477477
) -> pallet_transaction_payment::FeeDetails<Balance> {
478478
TransactionPayment::query_fee_details(uxt, len)
479479
}
480+
fn query_weight_to_fee(weight: Weight) -> Balance {
481+
TransactionPayment::weight_to_fee(weight)
482+
}
483+
fn query_length_to_fee(length: u32) -> Balance {
484+
TransactionPayment::length_to_fee(length)
485+
}
480486
}
481487

482488
impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi<Block, Balance, RuntimeCall>
@@ -494,6 +500,12 @@ impl_runtime_apis! {
494500
) -> pallet_transaction_payment::FeeDetails<Balance> {
495501
TransactionPayment::query_call_fee_details(call, len)
496502
}
503+
fn query_weight_to_fee(weight: Weight) -> Balance {
504+
TransactionPayment::weight_to_fee(weight)
505+
}
506+
fn query_length_to_fee(length: u32) -> Balance {
507+
TransactionPayment::length_to_fee(length)
508+
}
497509
}
498510

499511
#[cfg(feature = "runtime-benchmarks")]

bin/node/runtime/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,12 @@ impl_runtime_apis! {
21202120
fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {
21212121
TransactionPayment::query_fee_details(uxt, len)
21222122
}
2123+
fn query_weight_to_fee(weight: Weight) -> Balance {
2124+
TransactionPayment::weight_to_fee(weight)
2125+
}
2126+
fn query_length_to_fee(length: u32) -> Balance {
2127+
TransactionPayment::length_to_fee(length)
2128+
}
21232129
}
21242130

21252131
impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi<Block, Balance, RuntimeCall>
@@ -2131,6 +2137,12 @@ impl_runtime_apis! {
21312137
fn query_call_fee_details(call: RuntimeCall, len: u32) -> FeeDetails<Balance> {
21322138
TransactionPayment::query_call_fee_details(call, len)
21332139
}
2140+
fn query_weight_to_fee(weight: Weight) -> Balance {
2141+
TransactionPayment::weight_to_fee(weight)
2142+
}
2143+
fn query_length_to_fee(length: u32) -> Balance {
2144+
TransactionPayment::length_to_fee(length)
2145+
}
21342146
}
21352147

21362148
impl pallet_mmr::primitives::MmrApi<

frame/transaction-payment/rpc/runtime-api/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ use sp_runtime::traits::MaybeDisplay;
2525
pub use pallet_transaction_payment::{FeeDetails, InclusionFee, RuntimeDispatchInfo};
2626

2727
sp_api::decl_runtime_apis! {
28-
#[api_version(2)]
28+
#[api_version(3)]
2929
pub trait TransactionPaymentApi<Balance> where
3030
Balance: Codec + MaybeDisplay,
3131
{
3232
#[changed_in(2)]
3333
fn query_info(uxt: Block::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance, sp_weights::OldWeight>;
3434
fn query_info(uxt: Block::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance>;
3535
fn query_fee_details(uxt: Block::Extrinsic, len: u32) -> FeeDetails<Balance>;
36+
fn query_weight_to_fee(weight: sp_weights::Weight) -> Balance;
37+
fn query_length_to_fee(length: u32) -> Balance;
3638
}
3739

38-
#[api_version(2)]
40+
#[api_version(3)]
3941
pub trait TransactionPaymentCallApi<Balance, Call>
4042
where
4143
Balance: Codec + MaybeDisplay,
@@ -46,5 +48,11 @@ sp_api::decl_runtime_apis! {
4648

4749
/// Query fee details of a given encoded `Call`.
4850
fn query_call_fee_details(call: Call, len: u32) -> FeeDetails<Balance>;
51+
52+
/// Query the output of the current `WeightToFee` given some input.
53+
fn query_weight_to_fee(weight: sp_weights::Weight) -> Balance;
54+
55+
/// Query the output of the current `LengthToFee` given some input.
56+
fn query_length_to_fee(length: u32) -> Balance;
4957
}
5058
}

frame/transaction-payment/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,14 @@ where
612612
}
613613
}
614614

615-
fn length_to_fee(length: u32) -> BalanceOf<T> {
615+
/// Compute the length portion of a fee by invoking the configured `LengthToFee` impl.
616+
pub fn length_to_fee(length: u32) -> BalanceOf<T> {
616617
T::LengthToFee::weight_to_fee(&Weight::from_ref_time(length as u64))
617618
}
618619

619-
fn weight_to_fee(weight: Weight) -> BalanceOf<T> {
620+
/// Compute the unadjusted portion of the weight fee by invoking the configured `WeightToFee`
621+
/// impl. Note that the input `weight` is capped by the maximum block weight before computation.
622+
pub fn weight_to_fee(weight: Weight) -> BalanceOf<T> {
620623
// cap the weight to the maximum defined in runtime, otherwise it will be the
621624
// `Bounded` maximum of its data type, which is not desired.
622625
let capped_weight = weight.min(T::BlockWeights::get().max_block);

0 commit comments

Comments
 (0)