Runtime dependent weights (#5064)

* Copy Substrate weights into each runtime

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Define weights per runtime

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Do the same for test-runtime

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix CI

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Generate multiplier tests via macro

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix CI

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix imports

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix imports

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Change rococo tests to use ExtrinsicBaseWeight

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix imports

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Spellcheck on

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Spellcheck on

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Spellcheck

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Re-Export weight constants in the runtime

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Prepare for cumulus companion

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Oliver Tale-Yazdi
2022-03-11 17:36:08 +01:00
committed by GitHub
parent 078bf68037
commit 2b8f6e9d0a
41 changed files with 1490 additions and 218 deletions
+11 -9
View File
@@ -16,6 +16,8 @@
#![cfg_attr(not(feature = "std"), no_std)]
pub mod weights;
/// Money matters.
pub mod currency {
use primitives::v2::Balance;
@@ -53,11 +55,11 @@ pub mod time {
/// Fee-related.
pub mod fee {
use crate::weights::ExtrinsicBaseWeight;
use frame_support::weights::{
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
};
use primitives::v2::Balance;
use runtime_common::ExtrinsicBaseWeight;
use smallvec::smallvec;
pub use sp_runtime::Perbill;
@@ -97,15 +99,16 @@ mod tests {
currency::{CENTS, DOLLARS, MILLICENTS},
fee::WeightToFee,
};
use frame_support::weights::{DispatchClass, WeightToFeePolynomial};
use runtime_common::BlockWeights;
use crate::weights::ExtrinsicBaseWeight;
use frame_support::weights::WeightToFeePolynomial;
use runtime_common::MAXIMUM_BLOCK_WEIGHT;
#[test]
// This function tests that the fee for `MaximumBlockWeight` of weight is correct
// This function tests that the fee for `MAXIMUM_BLOCK_WEIGHT` of weight is correct
fn full_block_fee_is_correct() {
// A full block should cost 16 DOLLARS
println!("Base: {}", BlockWeights::get().get(DispatchClass::Normal).base_extrinsic);
let x = WeightToFee::calc(&BlockWeights::get().max_block);
println!("Base: {}", ExtrinsicBaseWeight::get());
let x = WeightToFee::calc(&MAXIMUM_BLOCK_WEIGHT);
let y = 16 * DOLLARS;
assert!(x.max(y) - x.min(y) < MILLICENTS);
}
@@ -114,9 +117,8 @@ mod tests {
// This function tests that the fee for `ExtrinsicBaseWeight` of weight is correct
fn extrinsic_base_fee_is_correct() {
// `ExtrinsicBaseWeight` should cost 1/10 of a CENT
let base_weight = BlockWeights::get().get(DispatchClass::Normal).base_extrinsic;
println!("Base: {}", base_weight);
let x = WeightToFee::calc(&base_weight);
println!("Base: {}", ExtrinsicBaseWeight::get());
let x = WeightToFee::calc(&ExtrinsicBaseWeight::get());
let y = CENTS / 10;
assert!(x.max(y) - x.min(y) < MILLICENTS);
}