use crate::{Balance, BlockNumber};
use frame_support::weights::Weight;
use sp_runtime::Perbill;
pub use crate::weights::paritydb_weights::constants::ParityDbWeight as DbWeight;
pub const MILLISECS_PER_BLOCK: u64 = 6000;
pub const SECS_PER_BLOCK: u64 = MILLISECS_PER_BLOCK / 1_000;
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;
const SECS_PER_YEAR: u64 = 31_557_600; 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 PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration =
sp_consensus_babe::BabeEpochConfiguration {
c: PRIMARY_PROBABILITY,
allowed_slots: sp_consensus_babe::AllowedSlots::PrimaryAndSecondaryVRFSlots,
};
pub const DEPOSIT_PER_BYTE: Balance = 1;
pub const DEPOSIT_PER_ITEM: Balance = 100;
pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * DEPOSIT_PER_ITEM + (bytes as Balance * DEPOSIT_PER_BYTE)
}
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
pub fn block_weights(
expected_block_weight: Weight,
normal_ratio: sp_arithmetic::Perbill,
) -> frame_system::limits::BlockWeights {
let base_weight = crate::weights::extrinsic_weights::ExtrinsicBaseWeight::get();
let normal_weight = normal_ratio * expected_block_weight;
frame_system::limits::BlockWeights::builder()
.base_block(crate::weights::block_weights::BlockExecutionWeight::get())
.for_class(frame_support::dispatch::DispatchClass::all(), |weights| {
weights.base_extrinsic = base_weight;
})
.for_class(frame_support::dispatch::DispatchClass::Normal, |weights| {
weights.max_total = normal_weight.into();
})
.for_class(
frame_support::dispatch::DispatchClass::Operational,
|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")
}