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

Commit

Permalink
Companion for #11415 (WeightToFee) (#5525)
Browse files Browse the repository at this point in the history
* Companion for paritytech/substrate#11415

* Rename `WeightToFee::calc()` to `WeightToFee::wight_to_fee()`

* Fix typo

* Fix compile errors

* update lockfile for {"substrate"}

Co-authored-by: parity-processbot <>
  • Loading branch information
nazar-pc authored May 25, 2022
1 parent 74ae110 commit d21399a
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 208 deletions.
345 changes: 172 additions & 173 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bridges/bin/rialto/runtime/src/millau_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ mod tests {
let bridge = MILLAU_CHAIN_ID;
let call: Call = SystemCall::set_heap_pages { pages: 64 }.into();
let dispatch_weight = call.get_dispatch_info().weight;
let dispatch_fee = <Runtime as pallet_transaction_payment::Config>::WeightToFee::calc(
let dispatch_fee = <Runtime as pallet_transaction_payment::Config>::WeightToFee::weight_to_fee(
&dispatch_weight,
);
assert!(dispatch_fee > 0);
Expand Down Expand Up @@ -508,7 +508,7 @@ mod tests {
}

let dispatch_weight = 500;
let dispatch_fee = <Runtime as pallet_transaction_payment::Config>::WeightToFee::calc(
let dispatch_fee = <Runtime as pallet_transaction_payment::Config>::WeightToFee::weight_to_fee(
&dispatch_weight,
);
assert!(dispatch_fee > 0);
Expand Down
5 changes: 3 additions & 2 deletions bridges/bin/runtime-common/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use bp_runtime::{
use codec::{Decode, DecodeLimit, Encode};
use frame_support::{
traits::{Currency, ExistenceRequirement},
weights::{Weight, WeightToFeePolynomial},
weights::{Weight, WeightToFee},
RuntimeDebug,
};
use hash_db::Hasher;
Expand Down Expand Up @@ -598,7 +598,8 @@ pub mod target {
message_id,
message.data.payload.map_err(drop),
|dispatch_origin, dispatch_weight| {
let unadjusted_weight_fee = ThisRuntime::WeightToFee::calc(&dispatch_weight);
let unadjusted_weight_fee =
ThisRuntime::WeightToFee::weight_to_fee(&dispatch_weight);
let fee_multiplier =
pallet_transaction_payment::Pallet::<ThisRuntime>::next_fee_multiplier();
let adjusted_weight_fee =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub(crate) mod tests {
// for simplicity - add extra weight for base tx fee + fee that is paid for the tx size +
// adjusted fee
let single_source_header_submit_tx_weight = single_source_header_submit_call_weight * 3 / 2;
let single_source_header_tx_cost = W::calc(&single_source_header_submit_tx_weight);
let single_source_header_tx_cost = W::weight_to_fee(&single_source_header_submit_tx_weight);
single_source_header_tx_cost * B::from(expected_source_headers_per_day)
}

Expand Down
10 changes: 5 additions & 5 deletions bridges/relays/lib-substrate-relay/src/messages_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ fn compute_fee_multiplier<C: Chain>(
) -> FixedU128 {
let adjusted_weight_fee_difference =
larger_adjusted_weight_fee.saturating_sub(smaller_adjusted_weight_fee);
let smaller_tx_unadjusted_weight_fee = WeightToFeeOf::<C>::calc(&smaller_tx_weight);
let larger_tx_unadjusted_weight_fee = WeightToFeeOf::<C>::calc(&larger_tx_weight);
let smaller_tx_unadjusted_weight_fee = WeightToFeeOf::<C>::weight_to_fee(&smaller_tx_weight);
let larger_tx_unadjusted_weight_fee = WeightToFeeOf::<C>::weight_to_fee(&larger_tx_weight);
FixedU128::saturating_from_rational(
adjusted_weight_fee_difference,
larger_tx_unadjusted_weight_fee.saturating_sub(smaller_tx_unadjusted_weight_fee),
Expand All @@ -507,7 +507,7 @@ fn compute_prepaid_messages_refund<C: ChainWithMessages>(
total_prepaid_nonces: MessageNonce,
fee_multiplier: FixedU128,
) -> BalanceOf<C> {
fee_multiplier.saturating_mul_int(WeightToFeeOf::<C>::calc(
fee_multiplier.saturating_mul_int(WeightToFeeOf::<C>::weight_to_fee(
&C::PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN.saturating_mul(total_prepaid_nonces),
))
}
Expand Down Expand Up @@ -554,11 +554,11 @@ mod tests {

let smaller_weight = 1_000_000;
let smaller_adjusted_weight_fee =
multiplier.saturating_mul_int(WeightToFeeOf::<Rococo>::calc(&smaller_weight));
multiplier.saturating_mul_int(WeightToFeeOf::<Rococo>::weight_to_fee(&smaller_weight));

let larger_weight = smaller_weight + 200_000;
let larger_adjusted_weight_fee =
multiplier.saturating_mul_int(WeightToFeeOf::<Rococo>::calc(&larger_weight));
multiplier.saturating_mul_int(WeightToFeeOf::<Rococo>::weight_to_fee(&larger_weight));

assert_eq!(
compute_fee_multiplier::<Rococo>(
Expand Down
6 changes: 3 additions & 3 deletions runtime/kusama/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ mod tests {
fee::WeightToFee,
};
use crate::weights::ExtrinsicBaseWeight;
use frame_support::weights::WeightToFeePolynomial;
use frame_support::weights::WeightToFee as WeightToFeeT;
use runtime_common::MAXIMUM_BLOCK_WEIGHT;

#[test]
// Test that the fee for `MAXIMUM_BLOCK_WEIGHT` of weight has sane bounds.
fn full_block_fee_is_correct() {
// A full block should cost between 1,000 and 10,000 CENTS.
let full_block = WeightToFee::calc(&MAXIMUM_BLOCK_WEIGHT);
let full_block = WeightToFee::weight_to_fee(&MAXIMUM_BLOCK_WEIGHT);
assert!(full_block >= 1_000 * CENTS);
assert!(full_block <= 10_000 * CENTS);
}
Expand All @@ -117,7 +117,7 @@ mod tests {
fn extrinsic_base_fee_is_correct() {
// `ExtrinsicBaseWeight` should cost 1/10 of a CENT
println!("Base: {}", ExtrinsicBaseWeight::get());
let x = WeightToFee::calc(&ExtrinsicBaseWeight::get());
let x = WeightToFee::weight_to_fee(&ExtrinsicBaseWeight::get());
let y = CENTS / 10;
assert!(x.max(y) - x.min(y) < MILLICENTS);
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/kusama/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Tests for the Kusama Runtime Configuration

use crate::*;
use frame_support::weights::{GetDispatchInfo, WeightToFeePolynomial};
use frame_support::weights::{GetDispatchInfo, WeightToFee as WeightToFeeT};
use keyring::Sr25519Keyring::Charlie;
use pallet_transaction_payment::Multiplier;
use parity_scale_codec::Encode;
Expand Down Expand Up @@ -68,7 +68,7 @@ fn payout_weight_portion() {
#[ignore]
fn block_cost() {
let max_block_weight = BlockWeights::get().max_block;
let raw_fee = WeightToFee::calc(&max_block_weight);
let raw_fee = WeightToFee::weight_to_fee(&max_block_weight);

println!(
"Full Block weight == {} // WeightToFee(full_block) == {} plank",
Expand Down
6 changes: 3 additions & 3 deletions runtime/polkadot/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ mod tests {
fee::WeightToFee,
};
use crate::weights::ExtrinsicBaseWeight;
use frame_support::weights::WeightToFeePolynomial;
use frame_support::weights::WeightToFee as WeightToFeeT;
use runtime_common::MAXIMUM_BLOCK_WEIGHT;

#[test]
// Test that the fee for `MAXIMUM_BLOCK_WEIGHT` of weight has sane bounds.
fn full_block_fee_is_correct() {
// A full block should cost between 10 and 100 DOLLARS.
let full_block = WeightToFee::calc(&MAXIMUM_BLOCK_WEIGHT);
let full_block = WeightToFee::weight_to_fee(&MAXIMUM_BLOCK_WEIGHT);
assert!(full_block >= 10 * DOLLARS);
assert!(full_block <= 100 * DOLLARS);
}
Expand All @@ -119,7 +119,7 @@ mod tests {
fn extrinsic_base_fee_is_correct() {
// `ExtrinsicBaseWeight` should cost 1/10 of a CENT
println!("Base: {}", ExtrinsicBaseWeight::get());
let x = WeightToFee::calc(&ExtrinsicBaseWeight::get());
let x = WeightToFee::weight_to_fee(&ExtrinsicBaseWeight::get());
let y = CENTS / 10;
assert!(x.max(y) - x.min(y) < MILLICENTS);
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,7 @@ sp_api::impl_runtime_apis! {
#[cfg(test)]
mod test_fees {
use super::*;
use frame_support::weights::{GetDispatchInfo, WeightToFeePolynomial};
use frame_support::weights::{GetDispatchInfo, WeightToFee as WeightToFeeT};
use keyring::Sr25519Keyring::Charlie;
use pallet_transaction_payment::Multiplier;
use runtime_common::MinimumMultiplier;
Expand Down Expand Up @@ -2038,7 +2038,7 @@ mod test_fees {
#[ignore]
fn block_cost() {
let max_block_weight = BlockWeights::get().max_block;
let raw_fee = WeightToFee::calc(&max_block_weight);
let raw_fee = WeightToFee::weight_to_fee(&max_block_weight);

println!(
"Full Block weight == {} // WeightToFee(full_block) == {} plank",
Expand Down
6 changes: 3 additions & 3 deletions runtime/rococo/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ mod tests {
fee::WeightToFee,
};
use crate::weights::ExtrinsicBaseWeight;
use frame_support::weights::WeightToFeePolynomial;
use frame_support::weights::WeightToFee as WeightToFeeT;
use runtime_common::MAXIMUM_BLOCK_WEIGHT;

#[test]
// Test that the fee for `MAXIMUM_BLOCK_WEIGHT` of weight has sane bounds.
fn full_block_fee_is_correct() {
// A full block should cost between 10 and 100 DOLLARS.
let full_block = WeightToFee::calc(&MAXIMUM_BLOCK_WEIGHT);
let full_block = WeightToFee::weight_to_fee(&MAXIMUM_BLOCK_WEIGHT);
assert!(full_block >= 10 * DOLLARS);
assert!(full_block <= 100 * DOLLARS);
}
Expand All @@ -117,7 +117,7 @@ mod tests {
fn extrinsic_base_fee_is_correct() {
// `ExtrinsicBaseWeight` should cost 1/10 of a CENT
println!("Base: {}", ExtrinsicBaseWeight::get());
let x = WeightToFee::calc(&ExtrinsicBaseWeight::get());
let x = WeightToFee::weight_to_fee(&ExtrinsicBaseWeight::get());
let y = CENTS / 10;
assert!(x.max(y) - x.min(y) < MILLICENTS);
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/rococo/src/bridge_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use bridge_runtime_common::messages::{
};
use frame_support::{
traits::Get,
weights::{Weight, WeightToFeePolynomial},
weights::{Weight, WeightToFee as WeightToFeeT},
RuntimeDebug,
};
use rococo_runtime_constants::fee::WeightToFee;
Expand Down Expand Up @@ -141,7 +141,7 @@ impl<B, GI> ThisChainWithMessages for RococoLikeChain<B, GI> {
.base_extrinsic,
crate::TransactionByteFee::get(),
pallet_transaction_payment::Pallet::<Runtime>::next_fee_multiplier(),
|weight| WeightToFee::calc(&weight),
|weight| WeightToFee::weight_to_fee(&weight),
transaction,
)
}
Expand Down Expand Up @@ -199,7 +199,7 @@ impl<B, GI> BridgedChainWithMessages for RococoLikeChain<B, GI> {
.base_extrinsic,
crate::TransactionByteFee::get(),
pallet_transaction_payment::Pallet::<Runtime>::next_fee_multiplier(),
|weight| WeightToFee::calc(&weight),
|weight| WeightToFee::weight_to_fee(&weight),
transaction,
)
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/westend/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ mod tests {
fee::WeightToFee,
};
use crate::weights::ExtrinsicBaseWeight;
use frame_support::weights::WeightToFeePolynomial;
use frame_support::weights::WeightToFee as WeightToFeeT;
use runtime_common::MAXIMUM_BLOCK_WEIGHT;

#[test]
// Test that the fee for `MAXIMUM_BLOCK_WEIGHT` of weight has sane bounds.
fn full_block_fee_is_correct() {
// A full block should cost between 10 and 100 UNITS.
let full_block = WeightToFee::calc(&MAXIMUM_BLOCK_WEIGHT);
let full_block = WeightToFee::weight_to_fee(&MAXIMUM_BLOCK_WEIGHT);
assert!(full_block >= 10 * UNITS);
assert!(full_block <= 100 * UNITS);
}
Expand All @@ -117,7 +117,7 @@ mod tests {
fn extrinsic_base_fee_is_correct() {
// `ExtrinsicBaseWeight` should cost 1/10 of a CENT
println!("Base: {}", ExtrinsicBaseWeight::get());
let x = WeightToFee::calc(&ExtrinsicBaseWeight::get());
let x = WeightToFee::weight_to_fee(&ExtrinsicBaseWeight::get());
let y = CENTS / 10;
assert!(x.max(y) - x.min(y) < MILLICENTS);
}
Expand Down
12 changes: 6 additions & 6 deletions xcm/xcm-builder/src/weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use frame_support::{
traits::{tokens::currency::Currency as CurrencyT, Get, OnUnbalanced as OnUnbalancedT},
weights::{constants::WEIGHT_PER_SECOND, GetDispatchInfo, Weight, WeightToFeePolynomial},
weights::{constants::WEIGHT_PER_SECOND, GetDispatchInfo, Weight, WeightToFee as WeightToFeeT},
};
use parity_scale_codec::Decode;
use sp_runtime::traits::{SaturatedConversion, Saturating, Zero};
Expand Down Expand Up @@ -241,7 +241,7 @@ impl<T: Get<(AssetId, u128)>, R: TakeRevenue> Drop for FixedRateOfFungible<T, R>
/// Weight trader which uses the `TransactionPayment` pallet to set the right price for weight and then
/// places any weight bought into the right account.
pub struct UsingComponents<
WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,
WeightToFee: WeightToFeeT<Balance = Currency::Balance>,
AssetId: Get<MultiLocation>,
AccountId,
Currency: CurrencyT<AccountId>,
Expand All @@ -252,7 +252,7 @@ pub struct UsingComponents<
PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,
);
impl<
WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,
WeightToFee: WeightToFeeT<Balance = Currency::Balance>,
AssetId: Get<MultiLocation>,
AccountId,
Currency: CurrencyT<AccountId>,
Expand All @@ -265,7 +265,7 @@ impl<

fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {
log::trace!(target: "xcm::weight", "UsingComponents::buy_weight weight: {:?}, payment: {:?}", weight, payment);
let amount = WeightToFee::calc(&weight);
let amount = WeightToFee::weight_to_fee(&weight);
let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;
let required = (Concrete(AssetId::get()), u128_amount).into();
let unused = payment.checked_sub(required).map_err(|_| XcmError::TooExpensive)?;
Expand All @@ -277,7 +277,7 @@ impl<
fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {
log::trace!(target: "xcm::weight", "UsingComponents::refund_weight weight: {:?}", weight);
let weight = weight.min(self.0);
let amount = WeightToFee::calc(&weight);
let amount = WeightToFee::weight_to_fee(&weight);
self.0 -= weight;
self.1 = self.1.saturating_sub(amount);
let amount: u128 = amount.saturated_into();
Expand All @@ -289,7 +289,7 @@ impl<
}
}
impl<
WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,
WeightToFee: WeightToFeeT<Balance = Currency::Balance>,
AssetId: Get<MultiLocation>,
AccountId,
Currency: CurrencyT<AccountId>,
Expand Down

0 comments on commit d21399a

Please sign in to comment.