@@ -22,21 +22,19 @@ use polkadot_primitives::{node_features, ChunkIndex, CoreIndex, NodeFeatures, Va
22
22
/// Any modification to the output of the function needs to be coordinated via the runtime.
23
23
/// It's best to use minimal/no external dependencies.
24
24
pub fn availability_chunk_index (
25
- maybe_node_features : Option < & NodeFeatures > ,
25
+ node_features : & NodeFeatures ,
26
26
n_validators : usize ,
27
27
core_index : CoreIndex ,
28
28
validator_index : ValidatorIndex ,
29
29
) -> Result < ChunkIndex , polkadot_erasure_coding:: Error > {
30
- if let Some ( features) = maybe_node_features {
31
- if let Some ( & true ) = features
32
- . get ( usize:: from ( node_features:: FeatureIndex :: AvailabilityChunkMapping as u8 ) )
33
- . as_deref ( )
34
- {
35
- let systematic_threshold = systematic_recovery_threshold ( n_validators) ? as u32 ;
36
- let core_start_pos = core_index. 0 * systematic_threshold;
37
-
38
- return Ok ( ChunkIndex ( ( core_start_pos + validator_index. 0 ) % n_validators as u32 ) )
39
- }
30
+ if let Some ( & true ) = node_features
31
+ . get ( usize:: from ( node_features:: FeatureIndex :: AvailabilityChunkMapping as u8 ) )
32
+ . as_deref ( )
33
+ {
34
+ let systematic_threshold = systematic_recovery_threshold ( n_validators) ? as u32 ;
35
+ let core_start_pos = core_index. 0 * systematic_threshold;
36
+
37
+ return Ok ( ChunkIndex ( ( core_start_pos + validator_index. 0 ) % n_validators as u32 ) )
40
38
}
41
39
42
40
Ok ( validator_index. into ( ) )
@@ -48,26 +46,24 @@ pub fn availability_chunk_index(
48
46
/// Any modification to the output of the function needs to be coordinated via the
49
47
/// runtime. It's best to use minimal/no external dependencies.
50
48
pub fn availability_chunk_indices (
51
- maybe_node_features : Option < & NodeFeatures > ,
49
+ node_features : & NodeFeatures ,
52
50
n_validators : usize ,
53
51
core_index : CoreIndex ,
54
52
) -> Result < Vec < ChunkIndex > , polkadot_erasure_coding:: Error > {
55
53
let identity = ( 0 ..n_validators) . map ( |index| ChunkIndex ( index as u32 ) ) ;
56
- if let Some ( features) = maybe_node_features {
57
- if let Some ( & true ) = features
58
- . get ( usize:: from ( node_features:: FeatureIndex :: AvailabilityChunkMapping as u8 ) )
59
- . as_deref ( )
60
- {
61
- let systematic_threshold = systematic_recovery_threshold ( n_validators) ? as u32 ;
62
- let core_start_pos = core_index. 0 * systematic_threshold;
63
-
64
- return Ok ( identity
65
- . into_iter ( )
66
- . cycle ( )
67
- . skip ( core_start_pos as usize )
68
- . take ( n_validators)
69
- . collect ( ) )
70
- }
54
+ if let Some ( & true ) = node_features
55
+ . get ( usize:: from ( node_features:: FeatureIndex :: AvailabilityChunkMapping as u8 ) )
56
+ . as_deref ( )
57
+ {
58
+ let systematic_threshold = systematic_recovery_threshold ( n_validators) ? as u32 ;
59
+ let core_start_pos = core_index. 0 * systematic_threshold;
60
+
61
+ return Ok ( identity
62
+ . into_iter ( )
63
+ . cycle ( )
64
+ . skip ( core_start_pos as usize )
65
+ . take ( n_validators)
66
+ . collect ( ) )
71
67
}
72
68
73
69
Ok ( identity. collect ( ) )
@@ -102,9 +98,7 @@ mod tests {
102
98
103
99
// If the mapping feature is not enabled, it should always be the identity vector.
104
100
{
105
- for node_features in
106
- [ None , Some ( NodeFeatures :: EMPTY ) , Some ( node_features_with_other_bits_enabled ( ) ) ]
107
- {
101
+ for node_features in [ NodeFeatures :: EMPTY , node_features_with_other_bits_enabled ( ) ] {
108
102
for core_index in 0 ..n_cores {
109
103
let indices = availability_chunk_indices (
110
104
node_features. as_ref ( ) ,
@@ -141,7 +135,7 @@ mod tests {
141
135
142
136
for core_index in 0 ..n_cores {
143
137
let indices = availability_chunk_indices (
144
- Some ( & node_features) ,
138
+ & node_features,
145
139
n_validators as usize ,
146
140
CoreIndex ( core_index) ,
147
141
)
@@ -151,7 +145,7 @@ mod tests {
151
145
assert_eq ! (
152
146
indices[ validator_index as usize ] ,
153
147
availability_chunk_index(
154
- Some ( & node_features) ,
148
+ & node_features,
155
149
n_validators as usize ,
156
150
CoreIndex ( core_index) ,
157
151
ValidatorIndex ( validator_index)
@@ -184,39 +178,39 @@ mod tests {
184
178
let node_features = node_features_with_mapping_enabled ( ) ;
185
179
186
180
assert_eq ! (
187
- availability_chunk_indices( Some ( & node_features) , n_validators, CoreIndex ( 0 ) )
181
+ availability_chunk_indices( & node_features, n_validators, CoreIndex ( 0 ) )
188
182
. unwrap( )
189
183
. into_iter( )
190
184
. map( |i| i. 0 )
191
185
. collect:: <Vec <u32 >>( ) ,
192
186
vec![ 0 , 1 , 2 , 3 , 4 , 5 , 6 ]
193
187
) ;
194
188
assert_eq ! (
195
- availability_chunk_indices( Some ( & node_features) , n_validators, CoreIndex ( 1 ) )
189
+ availability_chunk_indices( & node_features, n_validators, CoreIndex ( 1 ) )
196
190
. unwrap( )
197
191
. into_iter( )
198
192
. map( |i| i. 0 )
199
193
. collect:: <Vec <u32 >>( ) ,
200
194
vec![ 2 , 3 , 4 , 5 , 6 , 0 , 1 ]
201
195
) ;
202
196
assert_eq ! (
203
- availability_chunk_indices( Some ( & node_features) , n_validators, CoreIndex ( 2 ) )
197
+ availability_chunk_indices( & node_features, n_validators, CoreIndex ( 2 ) )
204
198
. unwrap( )
205
199
. into_iter( )
206
200
. map( |i| i. 0 )
207
201
. collect:: <Vec <u32 >>( ) ,
208
202
vec![ 4 , 5 , 6 , 0 , 1 , 2 , 3 ]
209
203
) ;
210
204
assert_eq ! (
211
- availability_chunk_indices( Some ( & node_features) , n_validators, CoreIndex ( 3 ) )
205
+ availability_chunk_indices( & node_features, n_validators, CoreIndex ( 3 ) )
212
206
. unwrap( )
213
207
. into_iter( )
214
208
. map( |i| i. 0 )
215
209
. collect:: <Vec <u32 >>( ) ,
216
210
vec![ 6 , 0 , 1 , 2 , 3 , 4 , 5 ]
217
211
) ;
218
212
assert_eq ! (
219
- availability_chunk_indices( Some ( & node_features) , n_validators, CoreIndex ( 4 ) )
213
+ availability_chunk_indices( & node_features, n_validators, CoreIndex ( 4 ) )
220
214
. unwrap( )
221
215
. into_iter( )
222
216
. map( |i| i. 0 )
0 commit comments