use crate::{weights::WeightInfo, Config};
use codec::{Decode, Encode};
use core::marker::PhantomData;
use frame_support::DefaultNoBound;
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "std", serde(bound(serialize = "", deserialize = "")))]
#[cfg_attr(feature = "runtime-benchmarks", derive(frame_support::DebugNoBound))]
#[derive(Clone, Encode, Decode, PartialEq, Eq, DefaultNoBound, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct Schedule<T: Config> {
pub limits: Limits,
pub instruction_weights: InstructionWeights<T>,
}
impl<T: Config> Schedule<T> {
pub fn ref_time_by_fuel(&self) -> u64 {
self.instruction_weights.base as u64
}
}
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "runtime-benchmarks", derive(Debug))]
#[derive(Clone, Encode, Decode, PartialEq, Eq, TypeInfo)]
pub struct Limits {
pub event_topics: u32,
pub memory_pages: u32,
pub subject_len: u32,
pub payload_len: u32,
pub runtime_memory: u32,
pub validator_runtime_memory: u32,
pub event_ref_time: u64,
}
impl Limits {
pub fn max_memory_size(&self) -> u32 {
self.memory_pages * 64 * 1024
}
}
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "runtime-benchmarks", derive(frame_support::DebugNoBound))]
#[derive(Clone, Encode, Decode, PartialEq, Eq, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct InstructionWeights<T: Config> {
pub base: u32,
#[codec(skip)]
pub _phantom: PhantomData<T>,
}
impl Default for Limits {
fn default() -> Self {
Self {
event_topics: 4,
memory_pages: 16,
subject_len: 32,
payload_len: 16 * 1024,
runtime_memory: 1024 * 1024 * 128,
validator_runtime_memory: 1024 * 1024 * 512,
event_ref_time: 60_000,
}
}
}
impl<T: Config> Default for InstructionWeights<T> {
fn default() -> Self {
let instr_cost = T::WeightInfo::instr_i64_load_store(1)
.saturating_sub(T::WeightInfo::instr_i64_load_store(0))
.ref_time() as u32;
let base = instr_cost / 6;
Self { base, _phantom: PhantomData }
}
}