1#[allow(unused_imports)]
2use super::Authorizer;
3use crate::{chain_params, opaque, FixedVec};
4use bounded_collections::Get;
5use codec::{Decode, Encode};
6use core::sync::atomic::Ordering::Relaxed;
7
8pub const GP_VERSION: &str = "0.6.5";
10
11pub const JAM_COMMON_ERA: u64 = 1_735_732_800;
14
15pub const MEMO_LEN: usize = 128;
17
18#[doc(hidden)]
20pub const MAX_PREIMAGE_LEN: usize = 4 * 1024 * 1024;
22
23#[doc(hidden)]
28pub const MAX_PREIMAGE_BLOB_LEN: usize = MAX_PREIMAGE_LEN - 8;
29
30pub const PAGE_SIZE: u32 = 4096;
32
33#[cfg(not(feature = "tiny"))]
34mod defaults {
35 use super::ValIndex;
36 pub(super) const VAL_COUNT: ValIndex = 1023;
37 pub(super) const BASIC_PIECE_LEN: usize = 684;
38}
39
40#[cfg(feature = "tiny")]
41mod defaults {
42 use super::ValIndex;
43 pub(super) const VAL_COUNT: ValIndex = 6;
44 pub(super) const BASIC_PIECE_LEN: usize = 4;
45}
46
47chain_params! {
48 static VAL_COUNT: _ = _(defaults::VAL_COUNT);
50 pub fn val_count() -> ValIndex;
51 pub struct ValCount; impl Get<_> for _ {}
52
53 static BASIC_PIECE_LEN: _ = _(defaults::BASIC_PIECE_LEN);
55 pub fn basic_piece_len() -> usize;
56
57 static AUTH_QUEUE_LEN: _ = _(80);
59 pub fn auth_queue_len() -> usize;
60 pub struct AuthQueueLen; impl Get<_> for _ {}
61
62 static MIN_TURNAROUND_PERIOD: _ = _(28_800);
71 pub fn min_turnaround_period() -> Slot;
72
73 static MAX_WORK_ITEMS: _ = _(16);
75 pub fn max_work_items() -> usize;
76 pub struct MaxWorkItems; impl Get<_> for _ {}
77
78 static MAX_IMPORTS: _ = _(3072);
80 pub fn max_imports() -> u32;
81 pub struct MaxImports; impl Get<_> for _ {}
82
83 static MAX_EXPORTS: _ = _(3072);
85 pub fn max_exports() -> u32;
86
87 static MAX_EXTRINSICS: _ = _(128);
89 pub fn max_extrinsics() -> u32;
90
91 static MAX_DEPENDENCIES: _ = _(8);
93 pub fn max_dependencies() -> usize;
94
95 static MAX_INPUT: _ = _(12 * 1024 * 1024);
97 pub fn max_input() -> u32;
98
99 pub fn segment_slice_len() -> usize {
101 segment_len() / basic_piece_points()
102 }
103 pub struct SegmentSliceLen; impl Get<_> for _ {}
104
105 pub const SEGMENT_LEN: _ = 4104;
107 pub fn segment_len() -> usize;
108 pub struct SegmentLen; impl Get<_> for _ {}
109}
110
111pub fn basic_piece_points() -> usize {
113 basic_piece_len() / POINT_LEN
114}
115
116pub fn pieces_per_segment() -> usize {
118 SEGMENT_LEN / basic_piece_len()
119}
120
121#[derive(Copy, Clone, Eq, PartialEq, Debug, Encode, Decode)]
123pub struct Parameters {
124 pub val_count: ValIndex,
126 pub basic_piece_len: u32,
128 pub auth_queue_len: u32,
130 pub min_turnaround_period: Slot,
133 pub max_work_items: u32,
135 pub max_imports: u32,
137 pub max_exports: u32,
139 pub max_extrinsics: u32,
141 pub max_dependencies: u32,
143 pub max_input: u32,
145}
146
147impl Parameters {
148 pub fn get() -> Self {
149 Self {
150 val_count: val_count(),
151 basic_piece_len: basic_piece_len() as u32,
152 auth_queue_len: auth_queue_len() as u32,
153 min_turnaround_period: min_turnaround_period(),
154 max_work_items: max_work_items() as u32,
155 max_imports: max_imports(),
156 max_exports: max_exports(),
157 max_extrinsics: max_extrinsics(),
158 max_dependencies: max_dependencies() as u32,
159 max_input: max_input(),
160 }
161 }
162 pub fn validate(self) -> Result<(), &'static str> {
163 if self.basic_piece_len % 2 != 0 {
164 return Err("`basic_piece_len` is not even")
165 }
166 if SEGMENT_LEN % (self.basic_piece_len as usize) != 0 {
167 return Err("`basic_piece_len` does not divide into `SEGMENT_LEN` (4,104)")
168 }
169 Ok(())
170 }
171 pub fn apply(self) -> Result<(), &'static str> {
172 self.validate()?;
173 VAL_COUNT.store(self.val_count, Relaxed);
174 BASIC_PIECE_LEN.store(self.basic_piece_len as usize, Relaxed);
175 AUTH_QUEUE_LEN.store(self.auth_queue_len as usize, Relaxed);
176 MIN_TURNAROUND_PERIOD.store(self.min_turnaround_period, Relaxed);
177 MAX_WORK_ITEMS.store(self.max_work_items as usize, Relaxed);
178 MAX_IMPORTS.store(self.max_imports, Relaxed);
179 MAX_EXPORTS.store(self.max_exports, Relaxed);
180 MAX_EXTRINSICS.store(self.max_extrinsics, Relaxed);
181 MAX_DEPENDENCIES.store(self.max_dependencies as usize, Relaxed);
182 MAX_INPUT.store(self.max_input, Relaxed);
183 Ok(())
184 }
185}
186
187pub const POINT_LEN: usize = 2;
189
190#[doc(hidden)]
192#[derive(Copy, Clone, Eq, PartialEq, Default, Debug)]
193pub struct ValSuperMajority;
194impl Get<u32> for ValSuperMajority {
195 fn get() -> u32 {
196 val_count() as u32 / 3 * 2 + 1
197 }
198}
199
200pub type Slot = u32;
205pub type ValIndex = u16;
207pub type CoreIndex = u16;
209pub type ServiceId = u32;
211pub type Balance = u64;
213pub type DoubleBalance = u128;
215pub type SignedGas = i64;
218pub type UnsignedGas = u64;
220pub type DoubleGas = u128;
222
223pub type Hash = [u8; 32];
228
229opaque! {
230 pub struct HeaderHash(pub [u8; 32]);
232
233 pub struct CodeHash(pub [u8; 32]);
235
236 pub struct WorkPackageHash(pub [u8; 32]);
238
239 pub struct WorkReportHash(pub [u8; 32]);
241
242 pub struct PayloadHash(pub [u8; 32]);
244
245 pub struct StateRootHash(pub [u8; 32]);
247
248 pub struct MmrPeakHash(pub [u8; 32]);
250
251 pub struct AccumulateRootHash(pub [u8; 32]);
253
254 pub struct ExtrinsicHash(pub [u8; 32]);
256
257 pub struct AuthorizerHash(pub [u8; 32]);
259
260 pub struct SegmentTreeRoot(pub [u8; 32]);
262
263 pub struct SegmentHash(pub [u8; 32]);
265
266 pub struct MerkleNodeHash(pub [u8; 32]);
268
269 pub struct AnyHash(pub [u8; 32]);
273
274 pub struct Memo(pub [u8; MEMO_LEN]);
276
277 pub struct Authorization(pub Vec<u8>);
279
280 pub struct Code(pub Vec<u8>);
282
283 pub struct WorkPayload(pub Vec<u8>);
285
286 pub struct AuthConfig(pub Vec<u8>);
288
289 pub struct AnyVec(pub Vec<u8>);
293
294 pub struct WorkOutput(pub Vec<u8>);
296
297 pub struct AuthTrace(pub Vec<u8>);
299
300 pub struct Bundle(pub Vec<u8>);
303
304 pub struct OpaqueEd25519Public(pub [u8; 32]);
308
309 pub struct OpaqueBandersnatchPublic(pub [u8; 32]);
313
314 pub struct OpaqueBlsPublic(pub [u8; 144]);
318
319 pub struct OpaqueValidatorMetadata(pub [u8; 128]);
321}
322
323pub type AuthQueue = FixedVec<AuthorizerHash, AuthQueueLen>;
325
326pub type Segment = FixedVec<u8, SegmentLen>;
328pub trait ToAny {
331 type Any;
332 fn any(&self) -> Self::Any;
333 fn into_any(self) -> Self::Any;
334}
335
336impl ToAny for [u8; 32] {
337 type Any = AnyHash;
338 fn any(&self) -> Self::Any {
339 AnyHash(*self)
340 }
341 fn into_any(self) -> Self::Any {
342 AnyHash(self)
343 }
344}
345
346impl ToAny for alloc::vec::Vec<u8> {
347 type Any = AnyVec;
348 fn any(&self) -> Self::Any {
349 AnyVec(self.clone())
350 }
351 fn into_any(self) -> Self::Any {
352 AnyVec(self)
353 }
354}
355
356impl ToAny for &[u8] {
357 type Any = AnyVec;
358 fn any(&self) -> Self::Any {
359 AnyVec(self.to_vec())
360 }
361 fn into_any(self) -> Self::Any {
362 AnyVec(self.to_vec())
363 }
364}