jam_types/
simple.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#[allow(unused_imports)]
use super::Authorizer;
use crate::{opaque, FixedVec};
use bounded_collections::ConstU32;
pub use config::*;

#[cfg(not(feature = "tiny"))]
mod config {
	/// Total number of validators.
	pub const VAL_COUNT: super::ValIndex = 1023;

	/// Number of points in a chunk.
	pub const CHUNK_POINTS: usize = 342;

	/// Number of chunks in a segment.
	pub const CHUNKS_PER_SEGMENT: usize = 6;
}

#[cfg(feature = "tiny")]
mod config {
	/// Total number of validators.
	pub const VAL_COUNT: super::ValIndex = 6;

	/// Number of points in a chunk.
	pub const CHUNK_POINTS: usize = 2;

	/// Number of chunks in a segment.
	pub const CHUNKS_PER_SEGMENT: usize = 1026;
}

/// Minimum period in blocks between going from becoming `Available` to `Zombie`, and then
/// again from `Zombie` to non-existent.
///
/// This ensures firstly that any data added and referenced in a Work Report's lookup anchor
/// block will remain on-chain right up until the latest possible time a dispute might
/// conclude. Secondly, it ensure that we only need to record one "flip-flop" of the data's
/// availability in order to be able to determine whether it's available or not at any block
/// within this period.
pub const MIN_TURNAROUND_PERIOD: Slot = 28_800;

/// Number of bytes in an erasure-coding point.
pub const POINT_LEN: usize = 2;

/// Number of bytes in a segment slice.
#[doc(hidden)]
pub const SEGMENT_SLICE_LEN: usize = CHUNKS_PER_SEGMENT * POINT_LEN;

/// Number of bytes in a chunk.
pub const CHUNK_LEN: usize = CHUNK_POINTS * POINT_LEN;

/// Number of bytes in a segment.
pub const SEGMENT_LEN: usize = CHUNK_LEN * CHUNKS_PER_SEGMENT;

/// Validators super-majority.
#[doc(hidden)]
pub const VAL_SUPER_MAJORITY: u32 = VAL_COUNT as u32 / 3 * 2 + 1;

/// Maximum number of Work Items in a Work Package.
pub const MAX_WORK_ITEMS: u32 = 4;

/// Maximum number of imports in a Work Package.
pub const MAX_IMPORTS: u32 = 2048;

/// Maximum number of exports in a Work Package.
#[doc(hidden)]
pub const MAX_EXPORTS: u32 = 2048;

/// Maximum number of dependencies (total of prerequisites and SR lookup entries).
#[doc(hidden)]
pub const MAX_DEPENDENCIES: usize = 8;

/// Maximum size of a Work Package together with all extrinsic data and imported segments.
#[doc(hidden)]
pub const MAX_INPUT: u32 = 12 * 1024 * 1024;

/// Size of memo in transfers.
pub const MEMO_LEN: usize = 64;

/// Number of authorizations in a queue allocated to a core.
pub const AUTH_QUEUE_LEN: usize = 80;

/// Type that represents a time slot of six seconds.
///
/// This can be either in a relative sense or as a period which has elapsed from the Polkadot
/// Common Era, beginning 1200 UTC, 1 January 2025.
pub type Slot = u32;
/// Type to represent the index of a validator.
pub type ValIndex = u16;
/// Type to represent the index of a compute core.
pub type CoreIndex = u16;
/// Type to represent the index of a service.
pub type ServiceId = u32;
/// Type to represent a balance.
pub type Balance = u64;
/// Type which is double the length of Balance, for non-overflowing multiplies.
#[doc(hidden)]
pub type DoubleBalance = u128;
/// Type to represent some gas.
pub type Gas = i64;
/// Type which is double the length of Gas, for non-overflowing multiplies.
#[doc(hidden)]
pub type DoubleGas = u128;

/// A basic 256-bit data value.
///
/// This should generally not be used directly in the rich data types, but instead one of the
/// rich opaque hash types to avoid accidental misuse and provide pretty-print facilities.
pub type Hash = [u8; 32];

opaque! {
	/// Hash of an encoded block header.
	pub struct HeaderHash(pub [u8; 32]);

	/// Hash of PVM program code.
	pub struct CodeHash(pub [u8; 32]);

	/// Hash of an encoded Work Package.
	pub struct WorkPackageHash(pub [u8; 32]);

	/// Hash of an encoded Work Report.
	#[doc(hidden)]
	pub struct WorkReportHash(pub [u8; 32]);

	/// Hash of a Work Item's [WorkPayload].
	pub struct PayloadHash(pub [u8; 32]);

	/// Hash of the JAM state root.
	#[doc(hidden)]
	pub struct StateRootHash(pub [u8; 32]);

	/// Hash of an MMR peak.
	#[doc(hidden)]
	pub struct MmrPeakHash(pub [u8; 32]);

	/// Hash of an accumulation tree root node.
	#[doc(hidden)]
	pub struct AccumulateRootHash(pub [u8; 32]);

	/// Hash of a piece of extrinsic data.
	pub struct ExtrinsicHash(pub [u8; 32]);

	/// Hash of an encoded [Authorizer] value.
	pub struct AuthorizerHash(pub [u8; 32]);

	/// Hash of a segment tree root node.
	pub struct SegmentTreeRoot(pub [u8; 32]);

	/// Hash of a [Segment] value.
	pub struct SegmentHash(pub [u8; 32]);

	/// Hash of a Merkle tree node.
	#[doc(hidden)]
	pub struct MerkleNodeHash(pub [u8; 32]);

	/// Non usage-specific hash.
	///
	/// This can be useful for pretty-printing [type@Hash] values.
	#[doc(hidden)]
	pub struct AnyHash(pub [u8; 32]);

	/// Data constituting the Authorization Token in a Work Package.
	pub struct Authorization(pub Vec<u8>);

	/// PVM Program code.
	#[doc(hidden)]
	pub struct Code(pub Vec<u8>);

	/// Payload data defining a Work Item.
	pub struct WorkPayload(pub Vec<u8>);

	/// Authorization parameter.
	pub struct AuthParam(pub Vec<u8>);

	/// Non usage-specific data.
	///
	/// This can be useful for pretty-printing `Vec<u8>` values.
	#[doc(hidden)]
	pub struct AnyVec(pub Vec<u8>);

	/// Output data of Refinement operation, passed into Accumulation.
	pub struct WorkOutput(pub Vec<u8>);

	/// Output data of Is Authorized operation, passed into both Refinement and Accumulation.
	pub struct AuthOutput(pub Vec<u8>);

	/// A Work Package Bundle, the aggregation of the Work Package, extrinsics, imports and import
	/// proofs.
	#[doc(hidden)]
	pub struct Bundle(pub Vec<u8>);

	/// Transfer memo data, included with balance transfers between services.
	pub struct Memo(pub [u8; MEMO_LEN]);

	/// Plain-old-data struct of the same length as an encoded Ed25519 public key.
	///
	/// This has no cryptographic functionality or dependencies.
	pub struct OpaqueEd25519Public(pub [u8; 32]);

	/// Plain-old-data struct of the same length as an encoded Bandersnatch public key.
	///
	/// This has no cryptographic functionality or dependencies.
	pub struct OpaqueBandersnatchPublic(pub [u8; 32]);

	/// Plain-old-data struct of the same length as an encoded BLS public key.
	///
	/// This has no cryptographic functionality or dependencies.
	pub struct OpaqueBlsPublic(pub [u8; 144]);

	/// Additional information on a validator, opaque to the actual usage.
	pub struct OpaqueValidatorMetadata(pub [u8; 128]);
}

/// A queue of [AuthorizerHash]s, each of which will be rotated into the authorizer pool for a core.
pub type AuthQueue = FixedVec<AuthorizerHash, ConstU32<{ AUTH_QUEUE_LEN as u32 }>>;

/// A segment of data.
pub type Segment = FixedVec<u8, ConstU32<{ SEGMENT_LEN as u32 }>>;
// TODO: ^^^ Measure performance penalty for this not being 4096.