jam_types/
simple.rs

1#[allow(unused_imports)]
2use super::Authorizer;
3use crate::{opaque, FixedVec};
4use bounded_collections::ConstU32;
5pub use config::*;
6
7#[cfg(not(feature = "tiny"))]
8mod config {
9	/// Total number of validators.
10	pub const VAL_COUNT: super::ValIndex = 1023;
11
12	/// Number of points in a chunk.
13	pub const CHUNK_POINTS: usize = 342;
14
15	/// Number of chunks in a segment.
16	pub const CHUNKS_PER_SEGMENT: usize = 6;
17}
18
19#[cfg(feature = "tiny")]
20mod config {
21	/// Total number of validators.
22	pub const VAL_COUNT: super::ValIndex = 6;
23
24	/// Number of points in a chunk.
25	pub const CHUNK_POINTS: usize = 2;
26
27	/// Number of chunks in a segment.
28	pub const CHUNKS_PER_SEGMENT: usize = 1026;
29}
30
31/// Minimum period in blocks between going from becoming `Available` to `Zombie`, and then
32/// again from `Zombie` to non-existent.
33///
34/// This ensures firstly that any data added and referenced in a Work Report's lookup anchor
35/// block will remain on-chain right up until the latest possible time a dispute might
36/// conclude. Secondly, it ensure that we only need to record one "flip-flop" of the data's
37/// availability in order to be able to determine whether it's available or not at any block
38/// within this period.
39pub const MIN_TURNAROUND_PERIOD: Slot = 28_800;
40
41/// Number of bytes in an erasure-coding point.
42pub const POINT_LEN: usize = 2;
43
44/// Number of bytes in a segment slice.
45#[doc(hidden)]
46pub const SEGMENT_SLICE_LEN: usize = CHUNKS_PER_SEGMENT * POINT_LEN;
47
48/// Number of bytes in a chunk.
49pub const CHUNK_LEN: usize = CHUNK_POINTS * POINT_LEN;
50
51/// Number of bytes in a segment.
52pub const SEGMENT_LEN: usize = CHUNK_LEN * CHUNKS_PER_SEGMENT;
53
54/// Validators super-majority.
55#[doc(hidden)]
56pub const VAL_SUPER_MAJORITY: u32 = VAL_COUNT as u32 / 3 * 2 + 1;
57
58/// Maximum number of Work Items in a Work Package.
59pub const MAX_WORK_ITEMS: u32 = 4;
60
61/// Maximum number of imports in a Work Package.
62pub const MAX_IMPORTS: u32 = 2048;
63
64/// Maximum number of exports in a Work Package.
65#[doc(hidden)]
66pub const MAX_EXPORTS: u32 = 2048;
67
68/// Maximum number of dependencies (total of prerequisites and SR lookup entries).
69#[doc(hidden)]
70pub const MAX_DEPENDENCIES: usize = 8;
71
72/// Maximum size of a Work Package together with all extrinsic data and imported segments.
73#[doc(hidden)]
74pub const MAX_INPUT: u32 = 12 * 1024 * 1024;
75
76/// Size of memo in transfers.
77pub const MEMO_LEN: usize = 64;
78
79/// Number of authorizations in a queue allocated to a core.
80pub const AUTH_QUEUE_LEN: usize = 80;
81
82/// Type that represents a time slot of six seconds.
83///
84/// This can be either in a relative sense or as a period which has elapsed from the Polkadot
85/// Common Era, beginning 1200 UTC, 1 January 2025.
86pub type Slot = u32;
87/// Type to represent the index of a validator.
88pub type ValIndex = u16;
89/// Type to represent the index of a compute core.
90pub type CoreIndex = u16;
91/// Type to represent the index of a service.
92pub type ServiceId = u32;
93/// Type to represent a balance.
94pub type Balance = u64;
95/// Type which is double the length of Balance, for non-overflowing multiplies.
96#[doc(hidden)]
97pub type DoubleBalance = u128;
98/// Type to represent some gas.
99pub type Gas = i64;
100/// Type which is double the length of Gas, for non-overflowing multiplies.
101#[doc(hidden)]
102pub type DoubleGas = u128;
103
104/// A basic 256-bit data value.
105///
106/// This should generally not be used directly in the rich data types, but instead one of the
107/// rich opaque hash types to avoid accidental misuse and provide pretty-print facilities.
108pub type Hash = [u8; 32];
109
110opaque! {
111	/// Hash of an encoded block header.
112	pub struct HeaderHash(pub [u8; 32]);
113
114	/// Hash of PVM program code.
115	pub struct CodeHash(pub [u8; 32]);
116
117	/// Hash of an encoded Work Package.
118	pub struct WorkPackageHash(pub [u8; 32]);
119
120	/// Hash of an encoded Work Report.
121	#[doc(hidden)]
122	pub struct WorkReportHash(pub [u8; 32]);
123
124	/// Hash of a Work Item's [WorkPayload].
125	pub struct PayloadHash(pub [u8; 32]);
126
127	/// Hash of the JAM state root.
128	#[doc(hidden)]
129	pub struct StateRootHash(pub [u8; 32]);
130
131	/// Hash of an MMR peak.
132	#[doc(hidden)]
133	pub struct MmrPeakHash(pub [u8; 32]);
134
135	/// Hash of an accumulation tree root node.
136	#[doc(hidden)]
137	pub struct AccumulateRootHash(pub [u8; 32]);
138
139	/// Hash of a piece of extrinsic data.
140	pub struct ExtrinsicHash(pub [u8; 32]);
141
142	/// Hash of an encoded [Authorizer] value.
143	pub struct AuthorizerHash(pub [u8; 32]);
144
145	/// Hash of a segment tree root node.
146	pub struct SegmentTreeRoot(pub [u8; 32]);
147
148	/// Hash of a [Segment] value.
149	pub struct SegmentHash(pub [u8; 32]);
150
151	/// Hash of a Merkle tree node.
152	#[doc(hidden)]
153	pub struct MerkleNodeHash(pub [u8; 32]);
154
155	/// Non usage-specific hash.
156	///
157	/// This can be useful for pretty-printing [type@Hash] values.
158	#[doc(hidden)]
159	pub struct AnyHash(pub [u8; 32]);
160
161	/// Data constituting the Authorization Token in a Work Package.
162	pub struct Authorization(pub Vec<u8>);
163
164	/// PVM Program code.
165	#[doc(hidden)]
166	pub struct Code(pub Vec<u8>);
167
168	/// Payload data defining a Work Item.
169	pub struct WorkPayload(pub Vec<u8>);
170
171	/// Authorization parameter.
172	pub struct AuthParam(pub Vec<u8>);
173
174	/// Non usage-specific data.
175	///
176	/// This can be useful for pretty-printing `Vec<u8>` values.
177	#[doc(hidden)]
178	pub struct AnyVec(pub Vec<u8>);
179
180	/// Output data of Refinement operation, passed into Accumulation.
181	pub struct WorkOutput(pub Vec<u8>);
182
183	/// Output data of Is Authorized operation, passed into both Refinement and Accumulation.
184	pub struct AuthOutput(pub Vec<u8>);
185
186	/// A Work Package Bundle, the aggregation of the Work Package, extrinsics, imports and import
187	/// proofs.
188	#[doc(hidden)]
189	pub struct Bundle(pub Vec<u8>);
190
191	/// Transfer memo data, included with balance transfers between services.
192	pub struct Memo(pub [u8; MEMO_LEN]);
193
194	/// Plain-old-data struct of the same length as an encoded Ed25519 public key.
195	///
196	/// This has no cryptographic functionality or dependencies.
197	pub struct OpaqueEd25519Public(pub [u8; 32]);
198
199	/// Plain-old-data struct of the same length as an encoded Bandersnatch public key.
200	///
201	/// This has no cryptographic functionality or dependencies.
202	pub struct OpaqueBandersnatchPublic(pub [u8; 32]);
203
204	/// Plain-old-data struct of the same length as an encoded BLS public key.
205	///
206	/// This has no cryptographic functionality or dependencies.
207	pub struct OpaqueBlsPublic(pub [u8; 144]);
208
209	/// Additional information on a validator, opaque to the actual usage.
210	pub struct OpaqueValidatorMetadata(pub [u8; 128]);
211}
212
213/// A queue of [AuthorizerHash]s, each of which will be rotated into the authorizer pool for a core.
214pub type AuthQueue = FixedVec<AuthorizerHash, ConstU32<{ AUTH_QUEUE_LEN as u32 }>>;
215
216/// A segment of data.
217pub type Segment = FixedVec<u8, ConstU32<{ SEGMENT_LEN as u32 }>>;
218// TODO: ^^^ Measure performance penalty for this not being 4096.