21
21
22
22
use frame_support:: pallet_prelude:: * ;
23
23
use primitives:: v1:: { CandidateHash , CoreIndex , SessionIndex , ValidatorId , ValidatorIndex } ;
24
- use sp_std:: vec:: Vec ;
25
24
use sp_runtime:: traits:: { One , Zero } ;
25
+ use sp_std:: vec:: Vec ;
26
26
27
27
use rand:: { seq:: SliceRandom , SeedableRng } ;
28
28
use rand_chacha:: ChaCha20Rng ;
@@ -72,8 +72,10 @@ pub mod pallet {
72
72
#[ pallet:: getter( fn included_candidates) ]
73
73
pub ( super ) type IncludedCandidates < T : Config > = StorageDoubleMap <
74
74
_ ,
75
- Twox64Concat , SessionIndex ,
76
- Blake2_128Concat , CandidateHash ,
75
+ Twox64Concat ,
76
+ SessionIndex ,
77
+ Blake2_128Concat ,
78
+ CandidateHash ,
77
79
( T :: BlockNumber , CoreIndex ) ,
78
80
> ;
79
81
@@ -136,7 +138,9 @@ impl<T: Config> Pallet<T> {
136
138
included_in : T :: BlockNumber ,
137
139
core_index : CoreIndex ,
138
140
) -> Option < T :: BlockNumber > {
139
- if included_in. is_zero ( ) { return None }
141
+ if included_in. is_zero ( ) {
142
+ return None
143
+ }
140
144
141
145
let revert_to = included_in - One :: one ( ) ;
142
146
<IncludedCandidates < T > >:: insert ( & session, & candidate_hash, ( revert_to, core_index) ) ;
@@ -168,7 +172,7 @@ impl<T: Config> Pallet<T> {
168
172
#[ cfg( test) ]
169
173
pub ( crate ) fn included_candidates_iter_prefix (
170
174
session : SessionIndex ,
171
- ) -> impl Iterator < Item = ( CandidateHash , ( T :: BlockNumber , CoreIndex ) ) > {
175
+ ) -> impl Iterator < Item = ( CandidateHash , ( T :: BlockNumber , CoreIndex ) ) > {
172
176
<IncludedCandidates < T > >:: iter_prefix ( session)
173
177
}
174
178
@@ -291,7 +295,8 @@ mod tests {
291
295
new_test_ext ( MockGenesisConfig :: default ( ) ) . execute_with ( || {
292
296
let session = 1 ;
293
297
let candidate_hash = CandidateHash ( sp_core:: H256 :: repeat_byte ( 1 ) ) ;
294
- assert ! ( ParasShared :: note_included_candidate( session, candidate_hash, 0 , CoreIndex ( 0 ) ) . is_none( ) ) ;
298
+ assert ! ( ParasShared :: note_included_candidate( session, candidate_hash, 0 , CoreIndex ( 0 ) )
299
+ . is_none( ) ) ;
295
300
assert ! ( !ParasShared :: is_included_candidate( & session, & candidate_hash) ) ;
296
301
assert ! ( ParasShared :: get_included_candidate( & session, & candidate_hash) . is_none( ) ) ;
297
302
} ) ;
@@ -305,7 +310,12 @@ mod tests {
305
310
let block_number = 1 ;
306
311
let core_index = CoreIndex ( 2 ) ;
307
312
assert_eq ! (
308
- ParasShared :: note_included_candidate( session, candidate_hash, block_number, core_index) ,
313
+ ParasShared :: note_included_candidate(
314
+ session,
315
+ candidate_hash,
316
+ block_number,
317
+ core_index
318
+ ) ,
309
319
Some ( block_number - 1 ) ,
310
320
) ;
311
321
assert ! ( ParasShared :: is_included_candidate( & session, & candidate_hash) ) ;
@@ -323,9 +333,15 @@ mod tests {
323
333
let candidate_hash2 = CandidateHash ( sp_core:: H256 :: repeat_byte ( 2 ) ) ;
324
334
let candidate_hash3 = CandidateHash ( sp_core:: H256 :: repeat_byte ( 3 ) ) ;
325
335
326
- assert ! ( ParasShared :: note_included_candidate( 1 , candidate_hash1, 1 , CoreIndex ( 0 ) ) . is_some( ) ) ;
327
- assert ! ( ParasShared :: note_included_candidate( 1 , candidate_hash2, 1 , CoreIndex ( 0 ) ) . is_some( ) ) ;
328
- assert ! ( ParasShared :: note_included_candidate( 2 , candidate_hash3, 2 , CoreIndex ( 0 ) ) . is_some( ) ) ;
336
+ assert ! (
337
+ ParasShared :: note_included_candidate( 1 , candidate_hash1, 1 , CoreIndex ( 0 ) ) . is_some( )
338
+ ) ;
339
+ assert ! (
340
+ ParasShared :: note_included_candidate( 1 , candidate_hash2, 1 , CoreIndex ( 0 ) ) . is_some( )
341
+ ) ;
342
+ assert ! (
343
+ ParasShared :: note_included_candidate( 2 , candidate_hash3, 2 , CoreIndex ( 0 ) ) . is_some( )
344
+ ) ;
329
345
330
346
assert_eq ! ( ParasShared :: included_candidates_iter_prefix( 1 ) . count( ) , 2 ) ;
331
347
assert_eq ! ( ParasShared :: included_candidates_iter_prefix( 2 ) . count( ) , 1 ) ;
0 commit comments