#[allow(unused_imports)]
use super::Authorizer;
use crate::{chain_params, opaque, FixedVec};
use bounded_collections::Get;
use core::sync::atomic::Ordering::Relaxed;
use scale::{Decode, Encode};
pub const JAM_COMMON_ERA: u64 = 1_735_732_800;
pub const MEMO_LEN: usize = 128;
#[cfg(not(feature = "tiny"))]
mod defaults {
use super::ValIndex;
pub(super) const VAL_COUNT: ValIndex = 1023;
pub(super) const BASIC_PIECE_LEN: usize = 684;
}
#[cfg(feature = "tiny")]
mod defaults {
use super::ValIndex;
pub(super) const VAL_COUNT: ValIndex = 6;
pub(super) const BASIC_PIECE_LEN: usize = 4;
}
chain_params! {
static VAL_COUNT: _ = _(defaults::VAL_COUNT);
pub fn val_count() -> ValIndex;
pub struct ValCount; impl Get<_> for _ {}
static BASIC_PIECE_LEN: _ = _(defaults::BASIC_PIECE_LEN);
pub fn basic_piece_len() -> usize;
static AUTH_QUEUE_LEN: _ = _(80);
pub fn auth_queue_len() -> usize;
pub struct AuthQueueLen; impl Get<_> for _ {}
static MIN_TURNAROUND_PERIOD: _ = _(28_800);
pub fn min_turnaround_period() -> Slot;
static MAX_WORK_ITEMS: _ = _(16);
pub fn max_work_items() -> usize;
pub struct MaxWorkItems; impl Get<_> for _ {}
static MAX_IMPORTS: _ = _(3072);
pub fn max_imports() -> u32;
pub struct MaxImports; impl Get<_> for _ {}
static MAX_EXPORTS: _ = _(3072);
pub fn max_exports() -> u32;
static MAX_EXTRINSICS: _ = _(128);
pub fn max_extrinsics() -> u32;
static MAX_DEPENDENCIES: _ = _(8);
pub fn max_dependencies() -> usize;
static MAX_INPUT: _ = _(12 * 1024 * 1024);
pub fn max_input() -> u32;
pub fn segment_slice_len() -> usize {
segment_len() / basic_piece_points()
}
pub struct SegmentSliceLen; impl Get<_> for _ {}
pub const SEGMENT_LEN: _ = 4104;
pub fn segment_len() -> usize;
pub struct SegmentLen; impl Get<_> for _ {}
}
pub fn basic_piece_points() -> usize {
basic_piece_len() / POINT_LEN
}
pub fn pieces_per_segment() -> usize {
SEGMENT_LEN / basic_piece_len()
}
#[derive(Copy, Clone, Eq, PartialEq, Debug, Encode, Decode)]
pub struct Parameters {
pub val_count: ValIndex,
pub basic_piece_len: u32,
pub auth_queue_len: u32,
pub min_turnaround_period: Slot,
pub max_work_items: u32,
pub max_imports: u32,
pub max_exports: u32,
pub max_extrinsics: u32,
pub max_dependencies: u32,
pub max_input: u32,
}
impl Parameters {
pub fn get() -> Self {
Self {
val_count: val_count(),
basic_piece_len: basic_piece_len() as u32,
auth_queue_len: auth_queue_len() as u32,
min_turnaround_period: min_turnaround_period(),
max_work_items: max_work_items() as u32,
max_imports: max_imports(),
max_exports: max_exports(),
max_extrinsics: max_extrinsics(),
max_dependencies: max_dependencies() as u32,
max_input: max_input(),
}
}
pub fn validate(self) -> Result<(), &'static str> {
if self.basic_piece_len % 2 != 0 {
return Err("`basic_piece_len` is not even")
}
if SEGMENT_LEN % (self.basic_piece_len as usize) != 0 {
return Err("`basic_piece_len` does not divide into `SEGMENT_LEN` (4,104)")
}
Ok(())
}
pub fn apply(self) -> Result<(), &'static str> {
self.validate()?;
VAL_COUNT.store(self.val_count, Relaxed);
BASIC_PIECE_LEN.store(self.basic_piece_len as usize, Relaxed);
AUTH_QUEUE_LEN.store(self.auth_queue_len as usize, Relaxed);
MIN_TURNAROUND_PERIOD.store(self.min_turnaround_period, Relaxed);
MAX_WORK_ITEMS.store(self.max_work_items as usize, Relaxed);
MAX_IMPORTS.store(self.max_imports, Relaxed);
MAX_EXPORTS.store(self.max_exports, Relaxed);
MAX_EXTRINSICS.store(self.max_extrinsics, Relaxed);
MAX_DEPENDENCIES.store(self.max_dependencies as usize, Relaxed);
MAX_INPUT.store(self.max_input, Relaxed);
Ok(())
}
}
pub const POINT_LEN: usize = 2;
#[doc(hidden)]
#[derive(Copy, Clone, Eq, PartialEq, Default, Debug)]
pub struct ValSuperMajority;
impl Get<u32> for ValSuperMajority {
fn get() -> u32 {
val_count() as u32 / 3 * 2 + 1
}
}
pub type Slot = u32;
pub type ValIndex = u16;
pub type CoreIndex = u16;
pub type ServiceId = u32;
pub type Balance = u64;
#[doc(hidden)]
pub type DoubleBalance = u128;
pub type SignedGas = i64;
pub type UnsignedGas = u64;
#[doc(hidden)]
pub type DoubleGas = u128;
pub type Hash = [u8; 32];
opaque! {
pub struct HeaderHash(pub [u8; 32]);
pub struct CodeHash(pub [u8; 32]);
pub struct WorkPackageHash(pub [u8; 32]);
#[doc(hidden)]
pub struct WorkReportHash(pub [u8; 32]);
pub struct PayloadHash(pub [u8; 32]);
#[doc(hidden)]
pub struct StateRootHash(pub [u8; 32]);
#[doc(hidden)]
pub struct MmrPeakHash(pub [u8; 32]);
#[doc(hidden)]
pub struct AccumulateRootHash(pub [u8; 32]);
pub struct ExtrinsicHash(pub [u8; 32]);
pub struct AuthorizerHash(pub [u8; 32]);
pub struct SegmentTreeRoot(pub [u8; 32]);
pub struct SegmentHash(pub [u8; 32]);
#[doc(hidden)]
pub struct MerkleNodeHash(pub [u8; 32]);
#[doc(hidden)]
pub struct AnyHash(pub [u8; 32]);
pub struct Memo(pub [u8; MEMO_LEN]);
pub struct Authorization(pub Vec<u8>);
#[doc(hidden)]
pub struct Code(pub Vec<u8>);
pub struct WorkPayload(pub Vec<u8>);
pub struct AuthParam(pub Vec<u8>);
#[doc(hidden)]
pub struct AnyVec(pub Vec<u8>);
pub struct WorkOutput(pub Vec<u8>);
pub struct AuthOutput(pub Vec<u8>);
#[doc(hidden)]
pub struct Bundle(pub Vec<u8>);
pub struct OpaqueEd25519Public(pub [u8; 32]);
pub struct OpaqueBandersnatchPublic(pub [u8; 32]);
pub struct OpaqueBlsPublic(pub [u8; 144]);
pub struct OpaqueValidatorMetadata(pub [u8; 128]);
}
pub type AuthQueue = FixedVec<AuthorizerHash, AuthQueueLen>;
pub type Segment = FixedVec<u8, SegmentLen>;