@@ -65,11 +65,20 @@ use crate::run_loop::RegisteredKey;
65
65
pub static TEST_MINE_STALL : LazyLock < TestFlag < bool > > = LazyLock :: new ( TestFlag :: default) ;
66
66
#[ cfg( test) ]
67
67
/// Test flag to stall block proposal broadcasting
68
- pub static TEST_BROADCAST_STALL : LazyLock < TestFlag < bool > > = LazyLock :: new ( TestFlag :: default) ;
68
+ pub static TEST_BROADCAST_PROPOSAL_STALL : LazyLock < TestFlag < bool > > =
69
+ LazyLock :: new ( TestFlag :: default) ;
69
70
#[ cfg( test) ]
71
+ // Test flag to stall the miner from announcing a block while this flag is true
70
72
pub static TEST_BLOCK_ANNOUNCE_STALL : LazyLock < TestFlag < bool > > = LazyLock :: new ( TestFlag :: default) ;
71
73
#[ cfg( test) ]
72
- pub static TEST_SKIP_P2P_BROADCAST : LazyLock < TestFlag < bool > > = LazyLock :: new ( TestFlag :: default) ;
74
+ // Test flag to skip broadcasting blocks over the p2p network
75
+ pub static TEST_P2P_BROADCAST_SKIP : LazyLock < TestFlag < bool > > = LazyLock :: new ( TestFlag :: default) ;
76
+ #[ cfg( test) ]
77
+ // Test flag to stall broadcasting blocks over the p2p network
78
+ pub static TEST_P2P_BROADCAST_STALL : LazyLock < TestFlag < bool > > = LazyLock :: new ( TestFlag :: default) ;
79
+ #[ cfg( test) ]
80
+ // Test flag to skip pushing blocks to the signers
81
+ pub static TEST_BLOCK_PUSH_SKIP : LazyLock < TestFlag < bool > > = LazyLock :: new ( TestFlag :: default) ;
73
82
74
83
/// If the miner was interrupted while mining a block, how long should the
75
84
/// miner thread sleep before trying again?
@@ -252,19 +261,19 @@ impl BlockMinerThread {
252
261
}
253
262
254
263
#[ cfg( test) ]
255
- fn fault_injection_block_broadcast_stall ( new_block : & NakamotoBlock ) {
256
- if TEST_BROADCAST_STALL . get ( ) {
264
+ fn fault_injection_block_proposal_stall ( new_block : & NakamotoBlock ) {
265
+ if TEST_BROADCAST_PROPOSAL_STALL . get ( ) {
257
266
// Do an extra check just so we don't log EVERY time.
258
- warn ! ( "Fault injection: Broadcasting is stalled due to testing directive." ;
267
+ warn ! ( "Fault injection: Block proposal broadcast is stalled due to testing directive." ;
259
268
"stacks_block_id" => %new_block. block_id( ) ,
260
269
"stacks_block_hash" => %new_block. header. block_hash( ) ,
261
270
"height" => new_block. header. chain_length,
262
271
"consensus_hash" => %new_block. header. consensus_hash
263
272
) ;
264
- while TEST_BROADCAST_STALL . get ( ) {
273
+ while TEST_BROADCAST_PROPOSAL_STALL . get ( ) {
265
274
std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) ;
266
275
}
267
- info ! ( "Fault injection: Broadcasting is no longer stalled due to testing directive." ;
276
+ info ! ( "Fault injection: Block proposal broadcast is no longer stalled due to testing directive." ;
268
277
"block_id" => %new_block. block_id( ) ,
269
278
"height" => new_block. header. chain_length,
270
279
"consensus_hash" => %new_block. header. consensus_hash
@@ -273,7 +282,7 @@ impl BlockMinerThread {
273
282
}
274
283
275
284
#[ cfg( not( test) ) ]
276
- fn fault_injection_block_broadcast_stall ( _ignored : & NakamotoBlock ) { }
285
+ fn fault_injection_block_proposal_stall ( _ignored : & NakamotoBlock ) { }
277
286
278
287
#[ cfg( test) ]
279
288
fn fault_injection_block_announce_stall ( new_block : & NakamotoBlock ) {
@@ -301,17 +310,48 @@ impl BlockMinerThread {
301
310
302
311
#[ cfg( test) ]
303
312
fn fault_injection_skip_block_broadcast ( ) -> bool {
304
- if TEST_SKIP_P2P_BROADCAST . get ( ) {
305
- return true ;
306
- }
307
- false
313
+ TEST_P2P_BROADCAST_SKIP . get ( )
308
314
}
309
315
310
316
#[ cfg( not( test) ) ]
311
317
fn fault_injection_skip_block_broadcast ( ) -> bool {
312
318
false
313
319
}
314
320
321
+ #[ cfg( test) ]
322
+ fn fault_injection_block_broadcast_stall ( new_block : & NakamotoBlock ) {
323
+ if TEST_P2P_BROADCAST_STALL . get ( ) {
324
+ // Do an extra check just so we don't log EVERY time.
325
+ warn ! ( "Fault injection: P2P block broadcast is stalled due to testing directive." ;
326
+ "stacks_block_id" => %new_block. block_id( ) ,
327
+ "stacks_block_hash" => %new_block. header. block_hash( ) ,
328
+ "height" => new_block. header. chain_length,
329
+ "consensus_hash" => %new_block. header. consensus_hash
330
+ ) ;
331
+ while TEST_P2P_BROADCAST_STALL . get ( ) {
332
+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) ;
333
+ }
334
+ info ! ( "Fault injection: P2P block broadcast is no longer stalled due to testing directive." ;
335
+ "block_id" => %new_block. block_id( ) ,
336
+ "height" => new_block. header. chain_length,
337
+ "consensus_hash" => %new_block. header. consensus_hash
338
+ ) ;
339
+ }
340
+ }
341
+
342
+ #[ cfg( not( test) ) ]
343
+ fn fault_injection_block_broadcast_stall ( _ignored : & NakamotoBlock ) { }
344
+
345
+ #[ cfg( test) ]
346
+ fn fault_injection_skip_block_push ( ) -> bool {
347
+ TEST_BLOCK_PUSH_SKIP . get ( )
348
+ }
349
+
350
+ #[ cfg( not( test) ) ]
351
+ fn fault_injection_skip_block_push ( ) -> bool {
352
+ false
353
+ }
354
+
315
355
/// Stop a miner tenure by blocking the miner and then joining the tenure thread
316
356
#[ cfg( test) ]
317
357
fn fault_injection_stall_miner ( ) {
@@ -516,7 +556,7 @@ impl BlockMinerThread {
516
556
} ;
517
557
518
558
if let Some ( mut new_block) = new_block {
519
- Self :: fault_injection_block_broadcast_stall ( & new_block) ;
559
+ Self :: fault_injection_block_proposal_stall ( & new_block) ;
520
560
521
561
let signer_signature = match self . propose_block (
522
562
coordinator,
@@ -532,7 +572,7 @@ impl BlockMinerThread {
532
572
"block_height" => new_block. header. chain_length,
533
573
"consensus_hash" => %new_block. header. consensus_hash,
534
574
) ;
535
- return Err ( e ) ;
575
+ return Ok ( ( ) ) ;
536
576
}
537
577
NakamotoNodeError :: BurnchainTipChanged => {
538
578
info ! ( "Burnchain tip changed while waiting for signatures" ;
@@ -739,6 +779,7 @@ impl BlockMinerThread {
739
779
) ;
740
780
return Ok ( ( ) ) ;
741
781
}
782
+ Self :: fault_injection_block_broadcast_stall ( block) ;
742
783
743
784
let parent_block_info =
744
785
NakamotoChainState :: get_block_header ( chain_state. db ( ) , & block. header . parent_block_id ) ?
@@ -834,6 +875,14 @@ impl BlockMinerThread {
834
875
let miners_contract_id = boot_code_id ( MINERS_NAME , chain_state. mainnet ) ;
835
876
let mut miners_session = StackerDBSession :: new ( & rpc_socket. to_string ( ) , miners_contract_id) ;
836
877
878
+ if Self :: fault_injection_skip_block_push ( ) {
879
+ warn ! (
880
+ "Fault injection: Skipping block push for {}" ,
881
+ block. block_id( )
882
+ ) ;
883
+ return Ok ( ( ) ) ;
884
+ }
885
+
837
886
SignerCoordinator :: send_miners_message (
838
887
miner_privkey,
839
888
& sort_db,
0 commit comments