-
Notifications
You must be signed in to change notification settings - Fork 119
/
lib.rs
144 lines (134 loc) · 5.18 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright 2020-2024 Manta Network.
// This file is part of Manta.
//
// Manta is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Manta is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Manta. If not, see <http://www.gnu.org/licenses/>.
#![allow(non_upper_case_globals)]
#![allow(clippy::unnecessary_cast)]
#![allow(clippy::upper_case_acronyms)]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "test-helpers")]
pub mod test_helpers;
use frame_support::{parameter_types, weights::Weight};
use manta_primitives::{constants::WEIGHT_PER_NANOS, types::BlockNumber};
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use sp_runtime::{traits::Bounded, FixedPointNumber, Perquintill};
// From https://github.com/paritytech/polkadot/pull/4332/files?diff=unified&w=1 @ runtime/common/src/lib.rs
/// Macro to set a value (e.g. when using the `parameter_types` macro) to either a production value
/// or to an environment variable or testing value (in case the `fast-runtime` feature is selected).
/// Note that the environment variable is evaluated _at compile time_.
///
/// Usage:
/// ```Rust
/// parameter_types! {
/// // Note that the env variable version parameter cannot be const.
/// pub LaunchPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1, "KSM_LAUNCH_PERIOD");
/// pub const VotingPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1 * MINUTES);
/// }
#[macro_export]
macro_rules! prod_or_fast {
($prod:expr, $test:expr) => {
if cfg!(feature = "fast-runtime") {
$test
} else {
$prod
}
};
($prod:expr, $test:expr, $env:expr) => {
if cfg!(feature = "fast-runtime") {
core::option_env!($env)
.map(|s| s.parse().ok())
.flatten()
.unwrap_or($test)
} else {
$prod
}
};
}
parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
/// The portion of the `NORMAL_DISPATCH_RATIO` that we adjust the fees with. Blocks filled less
/// than this will decrease the weight and more will increase.
pub const CalamariTargetBlockFullness: Perquintill = Perquintill::from_percent(50);
pub const MantaTargetBlockFullness: Perquintill = Perquintill::from_percent(25);
/// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to
/// change the fees more rapidly.
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(225, 100_000);
/// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure
/// that combined with `AdjustmentVariable`, we can recover from the minimum.
/// See `multiplier_can_grow_from_zero`.
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 5_000u128);
pub MaximumMultiplier: Multiplier = Bounded::max_value();
}
/// Parameterized slow adjusting fee updated based on
/// https://research.web3.foundation/en/latest/polkadot/overview/2-token-economics.html#-2.-slow-adjusting-mechanism
pub type CalamariSlowAdjustingFeeUpdate<R> = TargetedFeeAdjustment<
R,
CalamariTargetBlockFullness,
AdjustmentVariable,
MinimumMultiplier,
MaximumMultiplier,
>;
pub type MantaSlowAdjustingFeeUpdate<R> = TargetedFeeAdjustment<
R,
MantaTargetBlockFullness,
AdjustmentVariable,
MinimumMultiplier,
MaximumMultiplier,
>;
parameter_types! {
/// Time to execute an empty block.
/// Calculated by multiplying the *Average* with `1` and adding `0`.
///
/// Stats nanoseconds:
/// Min, Max: 5_303_128, 5_507_784
/// Average: 5_346_284
/// Median: 5_328_139
/// Std-Dev: 41749.5
///
/// Percentiles nanoseconds:
/// 99th: 5_489_273
/// 95th: 5_433_314
/// 75th: 5_354_812
pub const BlockExecutionWeight: Weight = Weight::from_parts(WEIGHT_PER_NANOS.saturating_mul(5_346_284), 0);
}
parameter_types! {
/// Time to execute a NO-OP extrinsic, for example `System::remark`.
/// Calculated by multiplying the *Average* with `1` and adding `0`.
///
/// Stats nanoseconds:
/// Min, Max: 86_060, 86_999
/// Average: 86_298
/// Median: 86_248
/// Std-Dev: 207.19
///
/// Percentiles nanoseconds:
/// 99th: 86_924
/// 95th: 86_828
/// 75th: 86_347
pub const ExtrinsicBaseWeight: Weight = Weight::from_parts(WEIGHT_PER_NANOS.saturating_mul(98_974), 0);
}
// todo, failed
#[cfg(test)]
mod sanity_tests {
use super::*;
use frame_support::weights::constants::ExtrinsicBaseWeight as ImportedExtrinsicBaseWeight;
#[test]
#[ignore]
fn sanity_check_extrinsic_base_weight() {
assert_eq!(
ExtrinsicBaseWeight::get(),
ImportedExtrinsicBaseWeight::get()
);
}
}