@@ -678,6 +678,24 @@ impl BlockMinerThread {
678
678
Ok ( filtered_transactions. into_values ( ) . collect ( ) )
679
679
}
680
680
681
+ /// Fault injection -- possibly fail to broadcast
682
+ /// Return true to drop the block
683
+ fn fault_injection_broadcast_fail ( & self ) -> bool {
684
+ let drop_prob = self
685
+ . config
686
+ . node
687
+ . fault_injection_block_push_fail_probability
688
+ . unwrap_or ( 0 )
689
+ . min ( 100 ) ;
690
+ let will_drop = if drop_prob > 0 {
691
+ let throw: u8 = thread_rng ( ) . gen_range ( 0 ..100 ) ;
692
+ throw < drop_prob
693
+ } else {
694
+ false
695
+ } ;
696
+ will_drop
697
+ }
698
+
681
699
/// Store a block to the chainstate, and if successful (it should be since we mined it),
682
700
/// broadcast it via the p2p network.
683
701
fn broadcast_p2p (
@@ -717,25 +735,12 @@ impl BlockMinerThread {
717
735
}
718
736
719
737
// forward to p2p thread, but do fault injection
720
- let block_id = block. block_id ( ) ;
721
- let drop_prob = self
722
- . config
723
- . node
724
- . fault_injection_block_push_fail_probability
725
- . unwrap_or ( 0 )
726
- . min ( 100 ) ;
727
- let will_drop = if drop_prob > 0 {
728
- let throw: u8 = thread_rng ( ) . gen_range ( 0 ..100 ) ;
729
- throw < drop_prob
730
- } else {
731
- false
732
- } ;
733
-
734
- if will_drop {
735
- info ! ( "Fault injection: drop block {}" , & block_id) ;
738
+ if self . fault_injection_broadcast_fail ( ) {
739
+ info ! ( "Fault injection: drop block {}" , & block. block_id( ) ) ;
736
740
return Ok ( ( ) ) ;
737
741
}
738
742
743
+ let block_id = block. block_id ( ) ;
739
744
debug ! ( "Broadcasting block {}" , & block_id) ;
740
745
if let Err ( e) = self . p2p_handle . broadcast_message (
741
746
vec ! [ ] ,
0 commit comments