@@ -21,7 +21,11 @@ impl SlotBlockData {
2121 if let Some ( block) = self . blocks . iter_mut ( ) . find ( |b| b. header . hash == header. hash ) {
2222 block. announced_by . push ( id) ;
2323 } else {
24- self . blocks . push ( BlockData { header, announced_by : vec ! [ id] , body : None } ) ;
24+ self . blocks . push ( BlockData {
25+ header,
26+ announced_by : vec ! [ id] ,
27+ body : None ,
28+ } ) ;
2529 }
2630 }
2731
@@ -50,7 +54,7 @@ impl SlotBlockData {
5054 fn announcers ( & self , hash : BlockHash ) -> Vec < PeerId > {
5155 match self . blocks . iter ( ) . find ( |b| b. header . hash == hash) {
5256 Some ( b) => b. announced_by . clone ( ) ,
53- None => vec ! [ ]
57+ None => vec ! [ ] ,
5458 }
5559 }
5660
@@ -180,7 +184,7 @@ impl ChainState {
180184 // queue them to be published as soon as we have their bodies
181185 let head_slot = self . published_blocks . back ( ) . map ( |( s, _) | * s) ;
182186 if let Some ( slot) = head_slot {
183- for ( slot, blocks) in self . blocks . range ( slot+ 1 ..) {
187+ for ( slot, blocks) in self . blocks . range ( slot + 1 ..) {
184188 if let Some ( hash) = blocks. find_announced_hash ( id) {
185189 self . unpublished_blocks . push_back ( ( * slot, hash) ) ;
186190 }
@@ -251,7 +255,7 @@ impl ChainState {
251255 pub fn block_announcers ( & self , slot : u64 , hash : BlockHash ) -> Vec < PeerId > {
252256 match self . blocks . get ( & slot) {
253257 Some ( slot_blocks) => slot_blocks. announcers ( hash) ,
254- None => vec ! [ ]
258+ None => vec ! [ ] ,
255259 }
256260 }
257261}
@@ -298,7 +302,10 @@ mod tests {
298302 state. handle_body_fetched ( header. slot , header. hash , body. clone ( ) ) ;
299303
300304 // NOW we have a new block to report
301- assert_eq ! ( state. next_unpublished_block( ) , Some ( ( & header, body. as_slice( ) , false ) ) ) ;
305+ assert_eq ! (
306+ state. next_unpublished_block( ) ,
307+ Some ( ( & header, body. as_slice( ) , false ) )
308+ ) ;
302309 state. handle_block_published ( ) ;
303310 assert_eq ! ( state. next_unpublished_block( ) , None ) ;
304311 }
@@ -329,9 +336,15 @@ mod tests {
329336 state. handle_body_fetched ( h1. slot , h1. hash , b1. clone ( ) ) ;
330337
331338 // NOW we have TWO new blocks to report
332- assert_eq ! ( state. next_unpublished_block( ) , Some ( ( & h1, b1. as_slice( ) , false ) ) ) ;
339+ assert_eq ! (
340+ state. next_unpublished_block( ) ,
341+ Some ( ( & h1, b1. as_slice( ) , false ) )
342+ ) ;
333343 state. handle_block_published ( ) ;
334- assert_eq ! ( state. next_unpublished_block( ) , Some ( ( & h2, b2. as_slice( ) , false ) ) ) ;
344+ assert_eq ! (
345+ state. next_unpublished_block( ) ,
346+ Some ( ( & h2, b2. as_slice( ) , false ) )
347+ ) ;
335348 state. handle_block_published ( ) ;
336349 assert_eq ! ( state. next_unpublished_block( ) , None ) ;
337350 }
@@ -350,13 +363,19 @@ mod tests {
350363 // publish the first block
351364 assert_eq ! ( state. handle_roll_forward( p1, h1. clone( ) ) , vec![ p1] ) ;
352365 state. handle_body_fetched ( h1. slot , h1. hash , b1. clone ( ) ) ;
353- assert_eq ! ( state. next_unpublished_block( ) , Some ( ( & h1, b1. as_slice( ) , false ) ) ) ;
366+ assert_eq ! (
367+ state. next_unpublished_block( ) ,
368+ Some ( ( & h1, b1. as_slice( ) , false ) )
369+ ) ;
354370 state. handle_block_published ( ) ;
355371
356372 // publish the second block
357373 assert_eq ! ( state. handle_roll_forward( p1, h2. clone( ) ) , vec![ p1] ) ;
358374 state. handle_body_fetched ( h2. slot , h2. hash , b2. clone ( ) ) ;
359- assert_eq ! ( state. next_unpublished_block( ) , Some ( ( & h2, b2. as_slice( ) , false ) ) ) ;
375+ assert_eq ! (
376+ state. next_unpublished_block( ) ,
377+ Some ( ( & h2, b2. as_slice( ) , false ) )
378+ ) ;
360379 state. handle_block_published ( ) ;
361380 assert_eq ! ( state. next_unpublished_block( ) , None ) ;
362381
@@ -367,13 +386,19 @@ mod tests {
367386 // and when we advance to the new second block, the system should report it as a rollback
368387 assert_eq ! ( state. handle_roll_forward( p1, h3. clone( ) ) , vec![ p1] ) ;
369388 state. handle_body_fetched ( h3. slot , h3. hash , b3. clone ( ) ) ;
370- assert_eq ! ( state. next_unpublished_block( ) , Some ( ( & h3, b3. as_slice( ) , true ) ) ) ;
389+ assert_eq ! (
390+ state. next_unpublished_block( ) ,
391+ Some ( ( & h3, b3. as_slice( ) , true ) )
392+ ) ;
371393 state. handle_block_published ( ) ;
372394
373395 // and the new third block should not be a rollback
374396 assert_eq ! ( state. handle_roll_forward( p1, h4. clone( ) ) , vec![ p1] ) ;
375397 state. handle_body_fetched ( h4. slot , h4. hash , b4. clone ( ) ) ;
376- assert_eq ! ( state. next_unpublished_block( ) , Some ( ( & h4, b4. as_slice( ) , false ) ) ) ;
398+ assert_eq ! (
399+ state. next_unpublished_block( ) ,
400+ Some ( ( & h4, b4. as_slice( ) , false ) )
401+ ) ;
377402 state. handle_block_published ( ) ;
378403 }
379404
@@ -390,7 +415,10 @@ mod tests {
390415 // publish the first block
391416 assert_eq ! ( state. handle_roll_forward( p1, h1. clone( ) ) , vec![ p1] ) ;
392417 state. handle_body_fetched ( h1. slot , h1. hash , b1. clone ( ) ) ;
393- assert_eq ! ( state. next_unpublished_block( ) , Some ( ( & h1, b1. as_slice( ) , false ) ) ) ;
418+ assert_eq ! (
419+ state. next_unpublished_block( ) ,
420+ Some ( ( & h1, b1. as_slice( ) , false ) )
421+ ) ;
394422 state. handle_block_published ( ) ;
395423
396424 // roll forward to the second block, but pretend the body is taking a while to download
@@ -408,7 +436,10 @@ mod tests {
408436 // and when we advance to the new second block, the system should not report it as a rollback
409437 assert_eq ! ( state. handle_roll_forward( p1, h3. clone( ) ) , vec![ p1] ) ;
410438 state. handle_body_fetched ( h3. slot , h3. hash , b3. clone ( ) ) ;
411- assert_eq ! ( state. next_unpublished_block( ) , Some ( ( & h3, b3. as_slice( ) , false ) ) ) ;
439+ assert_eq ! (
440+ state. next_unpublished_block( ) ,
441+ Some ( ( & h3, b3. as_slice( ) , false ) )
442+ ) ;
412443 state. handle_block_published ( ) ;
413444 assert_eq ! ( state. next_unpublished_block( ) , None ) ;
414445 }
@@ -429,17 +460,26 @@ mod tests {
429460 // publish three blocks on our current chain
430461 assert_eq ! ( state. handle_roll_forward( p1, h1. clone( ) ) , vec![ p1] ) ;
431462 state. handle_body_fetched ( h1. slot , h1. hash , b1. clone ( ) ) ;
432- assert_eq ! ( state. next_unpublished_block( ) , Some ( ( & h1, b1. as_slice( ) , false ) ) ) ;
463+ assert_eq ! (
464+ state. next_unpublished_block( ) ,
465+ Some ( ( & h1, b1. as_slice( ) , false ) )
466+ ) ;
433467 state. handle_block_published ( ) ;
434468
435469 assert_eq ! ( state. handle_roll_forward( p1, p1h2. clone( ) ) , vec![ p1] ) ;
436470 state. handle_body_fetched ( p1h2. slot , p1h2. hash , p1b2. clone ( ) ) ;
437- assert_eq ! ( state. next_unpublished_block( ) , Some ( ( & p1h2, p1b2. as_slice( ) , false ) ) ) ;
471+ assert_eq ! (
472+ state. next_unpublished_block( ) ,
473+ Some ( ( & p1h2, p1b2. as_slice( ) , false ) )
474+ ) ;
438475 state. handle_block_published ( ) ;
439476
440477 assert_eq ! ( state. handle_roll_forward( p1, p1h3. clone( ) ) , vec![ p1] ) ;
441478 state. handle_body_fetched ( p1h3. slot , p1h3. hash , p1b3. clone ( ) ) ;
442- assert_eq ! ( state. next_unpublished_block( ) , Some ( ( & p1h3, p1b3. as_slice( ) , false ) ) ) ;
479+ assert_eq ! (
480+ state. next_unpublished_block( ) ,
481+ Some ( ( & p1h3, p1b3. as_slice( ) , false ) )
482+ ) ;
443483 state. handle_block_published ( ) ;
444484
445485 // that other chain forked
@@ -454,11 +494,16 @@ mod tests {
454494 state. handle_new_preferred_upstream ( p2) ;
455495
456496 // now we should publish two blocks, and the first should be marked as "rollback"
457- assert_eq ! ( state. next_unpublished_block( ) , Some ( ( & p2h2, p2b2. as_slice( ) , true ) ) ) ;
497+ assert_eq ! (
498+ state. next_unpublished_block( ) ,
499+ Some ( ( & p2h2, p2b2. as_slice( ) , true ) )
500+ ) ;
458501 state. handle_block_published ( ) ;
459- assert_eq ! ( state. next_unpublished_block( ) , Some ( ( & p2h3, p2b3. as_slice( ) , false ) ) ) ;
502+ assert_eq ! (
503+ state. next_unpublished_block( ) ,
504+ Some ( ( & p2h3, p2b3. as_slice( ) , false ) )
505+ ) ;
460506 state. handle_block_published ( ) ;
461507 assert_eq ! ( state. next_unpublished_block( ) , None ) ;
462-
463508 }
464- }
509+ }
0 commit comments