@@ -348,7 +348,7 @@ impl Signer {
348
348
crate :: monitoring:: increment_block_responses_sent ( accepted) ;
349
349
}
350
350
Err ( e) => {
351
- warn ! ( "{self}: Failed to send block rejection to stacker-db: {e:?}" , ) ;
351
+ warn ! ( "{self}: Failed to send block response to stacker-db: {e:?}" , ) ;
352
352
}
353
353
}
354
354
return ;
@@ -434,30 +434,8 @@ impl Signer {
434
434
} ;
435
435
436
436
#[ cfg( any( test, feature = "testing" ) ) ]
437
- let block_response = match & * TEST_REJECT_ALL_BLOCK_PROPOSAL . lock ( ) . unwrap ( ) {
438
- Some ( public_keys) => {
439
- if public_keys. contains (
440
- & stacks_common:: types:: chainstate:: StacksPublicKey :: from_private (
441
- & self . private_key ,
442
- ) ,
443
- ) {
444
- warn ! ( "{self}: Rejecting block proposal automatically due to testing directive" ;
445
- "block_id" => %block_proposal. block. block_id( ) ,
446
- "height" => block_proposal. block. header. chain_length,
447
- "consensus_hash" => %block_proposal. block. header. consensus_hash
448
- ) ;
449
- Some ( BlockResponse :: rejected (
450
- block_proposal. block . header . signer_signature_hash ( ) ,
451
- RejectCode :: TestingDirective ,
452
- & self . private_key ,
453
- self . mainnet ,
454
- ) )
455
- } else {
456
- None
457
- }
458
- }
459
- None => block_response,
460
- } ;
437
+ let block_response =
438
+ self . test_reject_block_proposal ( block_proposal, & mut block_info, block_response) ;
461
439
462
440
if let Some ( block_response) = block_response {
463
441
// We know proposal is invalid. Send rejection message, do not do further validation
@@ -526,9 +504,8 @@ impl Signer {
526
504
{
527
505
debug ! ( "{self}: Received block validation for a block that is already marked as {}. Ignoring..." , block_info. state) ;
528
506
return None ;
529
- } else {
530
- block_info
531
507
}
508
+ block_info
532
509
}
533
510
Ok ( None ) => {
534
511
// We have not seen this block before. Why are we getting a response for it?
@@ -569,7 +546,15 @@ impl Signer {
569
546
. signer_db
570
547
. block_lookup ( self . reward_cycle , & signer_signature_hash)
571
548
{
572
- Ok ( Some ( block_info) ) => block_info,
549
+ Ok ( Some ( block_info) ) => {
550
+ if block_info. state == BlockState :: GloballyRejected
551
+ || block_info. state == BlockState :: GloballyAccepted
552
+ {
553
+ debug ! ( "{self}: Received block validation for a block that is already marked as {}. Ignoring..." , block_info. state) ;
554
+ return None ;
555
+ }
556
+ block_info
557
+ }
573
558
Ok ( None ) => {
574
559
// We have not seen this block before. Why are we getting a response for it?
575
560
debug ! ( "{self}: Received a block validate response for a block we have not seen before. Ignoring..." ) ;
@@ -941,6 +926,44 @@ impl Signer {
941
926
false
942
927
}
943
928
929
+ #[ cfg( any( test, feature = "testing" ) ) ]
930
+ fn test_reject_block_proposal (
931
+ & mut self ,
932
+ block_proposal : & BlockProposal ,
933
+ block_info : & mut BlockInfo ,
934
+ block_response : Option < BlockResponse > ,
935
+ ) -> Option < BlockResponse > {
936
+ let Some ( public_keys) = & * TEST_REJECT_ALL_BLOCK_PROPOSAL . lock ( ) . unwrap ( ) else {
937
+ return block_response;
938
+ } ;
939
+ if public_keys. contains (
940
+ & stacks_common:: types:: chainstate:: StacksPublicKey :: from_private ( & self . private_key ) ,
941
+ ) {
942
+ warn ! ( "{self}: Rejecting block proposal automatically due to testing directive" ;
943
+ "block_id" => %block_proposal. block. block_id( ) ,
944
+ "height" => block_proposal. block. header. chain_length,
945
+ "consensus_hash" => %block_proposal. block. header. consensus_hash
946
+ ) ;
947
+ if let Err ( e) = block_info. mark_locally_rejected ( ) {
948
+ warn ! ( "{self}: Failed to mark block as locally rejected: {e:?}" , ) ;
949
+ } ;
950
+ // We must insert the block into the DB to prevent subsequent repeat proposals being accepted (should reject
951
+ // as invalid since we rejected in a prior round if this crops up again)
952
+ // in case this is the first time we saw this block. Safe to do since this is testing case only.
953
+ self . signer_db
954
+ . insert_block ( block_info)
955
+ . unwrap_or_else ( |_| panic ! ( "{self}: Failed to insert block in DB" ) ) ;
956
+ Some ( BlockResponse :: rejected (
957
+ block_proposal. block . header . signer_signature_hash ( ) ,
958
+ RejectCode :: TestingDirective ,
959
+ & self . private_key ,
960
+ self . mainnet ,
961
+ ) )
962
+ } else {
963
+ None
964
+ }
965
+ }
966
+
944
967
/// Send a mock signature to stackerdb to prove we are still alive
945
968
fn mock_sign ( & mut self , mock_proposal : MockProposal ) {
946
969
info ! ( "{self}: Mock signing mock proposal: {mock_proposal:?}" ) ;
0 commit comments