1#[allow(unused_imports)]
2use super::Authorizer;
3use crate::{chain_params, opaque, FixedVec};
4use bounded_collections::Get;
5use core::sync::atomic::Ordering::Relaxed;
6use scale::{Decode, Encode};
7
8pub const JAM_COMMON_ERA: u64 = 1_735_732_800;
11
12pub const MEMO_LEN: usize = 128;
14
15#[cfg(not(feature = "tiny"))]
16mod defaults {
17 use super::ValIndex;
18 pub(super) const VAL_COUNT: ValIndex = 1023;
19 pub(super) const BASIC_PIECE_LEN: usize = 684;
20}
21
22#[cfg(feature = "tiny")]
23mod defaults {
24 use super::ValIndex;
25 pub(super) const VAL_COUNT: ValIndex = 6;
26 pub(super) const BASIC_PIECE_LEN: usize = 4;
27}
28
29chain_params! {
30 static VAL_COUNT: _ = _(defaults::VAL_COUNT);
32 pub fn val_count() -> ValIndex;
33 pub struct ValCount; impl Get<_> for _ {}
34
35 static BASIC_PIECE_LEN: _ = _(defaults::BASIC_PIECE_LEN);
37 pub fn basic_piece_len() -> usize;
38
39 static AUTH_QUEUE_LEN: _ = _(80);
41 pub fn auth_queue_len() -> usize;
42 pub struct AuthQueueLen; impl Get<_> for _ {}
43
44 static MIN_TURNAROUND_PERIOD: _ = _(28_800);
53 pub fn min_turnaround_period() -> Slot;
54
55 static MAX_WORK_ITEMS: _ = _(16);
57 pub fn max_work_items() -> usize;
58 pub struct MaxWorkItems; impl Get<_> for _ {}
59
60 static MAX_IMPORTS: _ = _(3072);
62 pub fn max_imports() -> u32;
63 pub struct MaxImports; impl Get<_> for _ {}
64
65 static MAX_EXPORTS: _ = _(3072);
67 pub fn max_exports() -> u32;
68
69 static MAX_EXTRINSICS: _ = _(128);
71 pub fn max_extrinsics() -> u32;
72
73 static MAX_DEPENDENCIES: _ = _(8);
75 pub fn max_dependencies() -> usize;
76
77 static MAX_INPUT: _ = _(12 * 1024 * 1024);
79 pub fn max_input() -> u32;
80
81 pub fn segment_slice_len() -> usize {
83 segment_len() / basic_piece_points()
84 }
85 pub struct SegmentSliceLen; impl Get<_> for _ {}
86
87 pub const SEGMENT_LEN: _ = 4104;
89 pub fn segment_len() -> usize;
90 pub struct SegmentLen; impl Get<_> for _ {}
91}
92
93pub fn basic_piece_points() -> usize {
95 basic_piece_len() / POINT_LEN
96}
97
98pub fn pieces_per_segment() -> usize {
100 SEGMENT_LEN / basic_piece_len()
101}
102
103#[derive(Copy, Clone, Eq, PartialEq, Debug, Encode, Decode)]
105pub struct Parameters {
106 pub val_count: ValIndex,
108 pub basic_piece_len: u32,
110 pub auth_queue_len: u32,
112 pub min_turnaround_period: Slot,
115 pub max_work_items: u32,
117 pub max_imports: u32,
119 pub max_exports: u32,
121 pub max_extrinsics: u32,
123 pub max_dependencies: u32,
125 pub max_input: u32,
127}
128
129impl Parameters {
130 pub fn get() -> Self {
131 Self {
132 val_count: val_count(),
133 basic_piece_len: basic_piece_len() as u32,
134 auth_queue_len: auth_queue_len() as u32,
135 min_turnaround_period: min_turnaround_period(),
136 max_work_items: max_work_items() as u32,
137 max_imports: max_imports(),
138 max_exports: max_exports(),
139 max_extrinsics: max_extrinsics(),
140 max_dependencies: max_dependencies() as u32,
141 max_input: max_input(),
142 }
143 }
144 pub fn validate(self) -> Result<(), &'static str> {
145 if self.basic_piece_len % 2 != 0 {
146 return Err("`basic_piece_len` is not even")
147 }
148 if SEGMENT_LEN % (self.basic_piece_len as usize) != 0 {
149 return Err("`basic_piece_len` does not divide into `SEGMENT_LEN` (4,104)")
150 }
151 Ok(())
152 }
153 pub fn apply(self) -> Result<(), &'static str> {
154 self.validate()?;
155 VAL_COUNT.store(self.val_count, Relaxed);
156 BASIC_PIECE_LEN.store(self.basic_piece_len as usize, Relaxed);
157 AUTH_QUEUE_LEN.store(self.auth_queue_len as usize, Relaxed);
158 MIN_TURNAROUND_PERIOD.store(self.min_turnaround_period, Relaxed);
159 MAX_WORK_ITEMS.store(self.max_work_items as usize, Relaxed);
160 MAX_IMPORTS.store(self.max_imports, Relaxed);
161 MAX_EXPORTS.store(self.max_exports, Relaxed);
162 MAX_EXTRINSICS.store(self.max_extrinsics, Relaxed);
163 MAX_DEPENDENCIES.store(self.max_dependencies as usize, Relaxed);
164 MAX_INPUT.store(self.max_input, Relaxed);
165 Ok(())
166 }
167}
168
169pub const POINT_LEN: usize = 2;
171
172#[doc(hidden)]
174#[derive(Copy, Clone, Eq, PartialEq, Default, Debug)]
175pub struct ValSuperMajority;
176impl Get<u32> for ValSuperMajority {
177 fn get() -> u32 {
178 val_count() as u32 / 3 * 2 + 1
179 }
180}
181
182pub type Slot = u32;
187pub type ValIndex = u16;
189pub type CoreIndex = u16;
191pub type ServiceId = u32;
193pub type Balance = u64;
195#[doc(hidden)]
197pub type DoubleBalance = u128;
198pub type SignedGas = i64;
201pub type UnsignedGas = u64;
203#[doc(hidden)]
205pub type DoubleGas = u128;
206
207pub type Hash = [u8; 32];
212
213opaque! {
214 pub struct HeaderHash(pub [u8; 32]);
216
217 pub struct CodeHash(pub [u8; 32]);
219
220 pub struct WorkPackageHash(pub [u8; 32]);
222
223 #[doc(hidden)]
225 pub struct WorkReportHash(pub [u8; 32]);
226
227 pub struct PayloadHash(pub [u8; 32]);
229
230 #[doc(hidden)]
232 pub struct StateRootHash(pub [u8; 32]);
233
234 #[doc(hidden)]
236 pub struct MmrPeakHash(pub [u8; 32]);
237
238 #[doc(hidden)]
240 pub struct AccumulateRootHash(pub [u8; 32]);
241
242 pub struct ExtrinsicHash(pub [u8; 32]);
244
245 pub struct AuthorizerHash(pub [u8; 32]);
247
248 pub struct SegmentTreeRoot(pub [u8; 32]);
250
251 pub struct SegmentHash(pub [u8; 32]);
253
254 #[doc(hidden)]
256 pub struct MerkleNodeHash(pub [u8; 32]);
257
258 #[doc(hidden)]
262 pub struct AnyHash(pub [u8; 32]);
263
264 pub struct Memo(pub [u8; MEMO_LEN]);
266
267 pub struct Authorization(pub Vec<u8>);
269
270 #[doc(hidden)]
272 pub struct Code(pub Vec<u8>);
273
274 pub struct WorkPayload(pub Vec<u8>);
276
277 pub struct AuthParam(pub Vec<u8>);
279
280 #[doc(hidden)]
284 pub struct AnyVec(pub Vec<u8>);
285
286 pub struct WorkOutput(pub Vec<u8>);
288
289 pub struct AuthOutput(pub Vec<u8>);
291
292 #[doc(hidden)]
295 pub struct Bundle(pub Vec<u8>);
296
297 pub struct OpaqueEd25519Public(pub [u8; 32]);
301
302 pub struct OpaqueBandersnatchPublic(pub [u8; 32]);
306
307 pub struct OpaqueBlsPublic(pub [u8; 144]);
311
312 pub struct OpaqueValidatorMetadata(pub [u8; 128]);
314}
315
316pub type AuthQueue = FixedVec<AuthorizerHash, AuthQueueLen>;
318
319pub type Segment = FixedVec<u8, SegmentLen>;
321