Skip to content
Snippets Groups Projects
Commit abf39880 authored by Éloïs's avatar Éloïs
Browse files

fix(weights): use our own extrinsic base weights constant

parent ea9f4a81
No related branches found
No related tags found
No related merge requests found
...@@ -38,15 +38,6 @@ const SECS_PER_YEAR: u64 = 31_557_600; // (365.25 * 24 * 60 * 60) ...@@ -38,15 +38,6 @@ const SECS_PER_YEAR: u64 = 31_557_600; // (365.25 * 24 * 60 * 60)
pub const MONTHS: BlockNumber = (SECS_PER_YEAR / (12 * SECS_PER_BLOCK)) as BlockNumber; pub const MONTHS: BlockNumber = (SECS_PER_YEAR / (12 * SECS_PER_BLOCK)) as BlockNumber;
pub const YEARS: BlockNumber = (SECS_PER_YEAR / SECS_PER_BLOCK) as BlockNumber; pub const YEARS: BlockNumber = (SECS_PER_YEAR / SECS_PER_BLOCK) as BlockNumber;
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
frame_support::parameter_types! {
pub const DbWeight: frame_support::weights::RuntimeDbWeight = frame_support::weights::RuntimeDbWeight {
read: 250 * frame_support::weights::constants::WEIGHT_PER_MICROS, // ~25 µs
write: 1_000 * frame_support::weights::constants::WEIGHT_PER_MICROS, // ~100 µs
};
}
// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks. // 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4); pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
...@@ -64,3 +55,44 @@ pub const DEPOSIT_PER_ITEM: Balance = 100; ...@@ -64,3 +55,44 @@ pub const DEPOSIT_PER_ITEM: Balance = 100;
pub const fn deposit(items: u32, bytes: u32) -> Balance { pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * DEPOSIT_PER_ITEM + (bytes as Balance * DEPOSIT_PER_BYTE) items as Balance * DEPOSIT_PER_ITEM + (bytes as Balance * DEPOSIT_PER_BYTE)
} }
// WEIGHTS COMSTANTS //
// Execution cost of everything outside of the call itself:
// signature verification, pre_dispatch and post_dispatch
pub const EXTRINSIC_BASE_WEIGHTS: frame_support::weights::Weight = 1_000_000_000;
// Maximal weight proportion of normal extrinsics per block
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
// DB weights
frame_support::parameter_types! {
pub const DbWeight: frame_support::weights::RuntimeDbWeight = frame_support::weights::RuntimeDbWeight {
read: 250 * frame_support::weights::constants::WEIGHT_PER_MICROS, // ~25 µs
write: 1_000 * frame_support::weights::constants::WEIGHT_PER_MICROS, // ~100 µs
};
}
// Block weights limits
pub fn block_weights(
expected_block_weight: frame_support::weights::Weight,
normal_ratio: sp_arithmetic::Perbill,
) -> frame_system::limits::BlockWeights {
let normal_weight = normal_ratio * expected_block_weight;
frame_system::limits::BlockWeights::builder()
.for_class(frame_support::weights::DispatchClass::Normal, |weights| {
weights.base_extrinsic = EXTRINSIC_BASE_WEIGHTS;
weights.max_total = normal_weight.into();
})
.for_class(
frame_support::weights::DispatchClass::Operational,
|weights| {
weights.base_extrinsic = EXTRINSIC_BASE_WEIGHTS;
weights.max_total = expected_block_weight.into();
weights.reserved = (expected_block_weight - normal_weight).into();
},
)
.avg_block_initialization(sp_arithmetic::Perbill::from_percent(10))
.build()
.expect("Fatal error: invalid BlockWeights configuration")
}
...@@ -26,8 +26,7 @@ use sp_runtime::transaction_validity::TransactionPriority; ...@@ -26,8 +26,7 @@ use sp_runtime::transaction_validity::TransactionPriority;
parameter_types! { parameter_types! {
pub const BlockHashCount: BlockNumber = 2400; pub const BlockHashCount: BlockNumber = 2400;
/// We allow for 2 seconds of compute with a 6 second average block time. /// We allow for 2 seconds of compute with a 6 second average block time.
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights pub BlockWeights: frame_system::limits::BlockWeights = block_weights(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u16 = 3682; pub const SS58Prefix: u16 = 3682;
......
...@@ -26,8 +26,7 @@ use sp_runtime::transaction_validity::TransactionPriority; ...@@ -26,8 +26,7 @@ use sp_runtime::transaction_validity::TransactionPriority;
parameter_types! { parameter_types! {
pub const BlockHashCount: BlockNumber = 2400; pub const BlockHashCount: BlockNumber = 2400;
/// We allow for 2 seconds of compute with a 6 second average block time. /// We allow for 2 seconds of compute with a 6 second average block time.
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights pub BlockWeights: frame_system::limits::BlockWeights = block_weights(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u16 = 42; pub const SS58Prefix: u16 = 42;
......
...@@ -26,8 +26,7 @@ use sp_runtime::transaction_validity::TransactionPriority; ...@@ -26,8 +26,7 @@ use sp_runtime::transaction_validity::TransactionPriority;
parameter_types! { parameter_types! {
pub const BlockHashCount: BlockNumber = 2400; pub const BlockHashCount: BlockNumber = 2400;
/// We allow for 2 seconds of compute with a 6 second average block time. /// We allow for 2 seconds of compute with a 6 second average block time.
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights pub BlockWeights: frame_system::limits::BlockWeights = block_weights(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u16 = 42; pub const SS58Prefix: u16 = 42;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment