@@ -428,30 +428,8 @@ impl Signer {
428
428
} ;
429
429
430
430
#[ cfg( any( test, feature = "testing" ) ) ]
431
- let block_response = match & * TEST_REJECT_ALL_BLOCK_PROPOSAL . lock ( ) . unwrap ( ) {
432
- Some ( public_keys) => {
433
- if public_keys. contains (
434
- & stacks_common:: types:: chainstate:: StacksPublicKey :: from_private (
435
- & self . private_key ,
436
- ) ,
437
- ) {
438
- warn ! ( "{self}: Rejecting block proposal automatically due to testing directive" ;
439
- "block_id" => %block_proposal. block. block_id( ) ,
440
- "height" => block_proposal. block. header. chain_length,
441
- "consensus_hash" => %block_proposal. block. header. consensus_hash
442
- ) ;
443
- Some ( BlockResponse :: rejected (
444
- block_proposal. block . header . signer_signature_hash ( ) ,
445
- RejectCode :: TestingDirective ,
446
- & self . private_key ,
447
- self . mainnet ,
448
- ) )
449
- } else {
450
- None
451
- }
452
- }
453
- None => block_response,
454
- } ;
431
+ let block_response =
432
+ self . test_reject_block_proposal ( block_proposal, & mut block_info, block_response) ;
455
433
456
434
if let Some ( block_response) = block_response {
457
435
// We know proposal is invalid. Send rejection message, do not do further validation
@@ -935,6 +913,44 @@ impl Signer {
935
913
false
936
914
}
937
915
916
+ #[ cfg( any( test, feature = "testing" ) ) ]
917
+ fn test_reject_block_proposal (
918
+ & mut self ,
919
+ block_proposal : & BlockProposal ,
920
+ block_info : & mut BlockInfo ,
921
+ block_response : Option < BlockResponse > ,
922
+ ) -> Option < BlockResponse > {
923
+ let Some ( public_keys) = & * TEST_REJECT_ALL_BLOCK_PROPOSAL . lock ( ) . unwrap ( ) else {
924
+ return block_response;
925
+ } ;
926
+ if public_keys. contains (
927
+ & stacks_common:: types:: chainstate:: StacksPublicKey :: from_private ( & self . private_key ) ,
928
+ ) {
929
+ warn ! ( "{self}: Rejecting block proposal automatically due to testing directive" ;
930
+ "block_id" => %block_proposal. block. block_id( ) ,
931
+ "height" => block_proposal. block. header. chain_length,
932
+ "consensus_hash" => %block_proposal. block. header. consensus_hash
933
+ ) ;
934
+ if let Err ( e) = block_info. mark_locally_rejected ( ) {
935
+ warn ! ( "{self}: Failed to mark block as locally rejected: {e:?}" , ) ;
936
+ } ;
937
+ // We must insert the block into the DB to prevent subsequent repeat proposals being accepted (should reject
938
+ // as invalid since we rejected in a prior round if this crops up again)
939
+ // in case this is the first time we saw this block. Safe to do since this is testing case only.
940
+ self . signer_db
941
+ . insert_block ( block_info)
942
+ . unwrap_or_else ( |_| panic ! ( "{self}: Failed to insert block in DB" ) ) ;
943
+ Some ( BlockResponse :: rejected (
944
+ block_proposal. block . header . signer_signature_hash ( ) ,
945
+ RejectCode :: TestingDirective ,
946
+ & self . private_key ,
947
+ self . mainnet ,
948
+ ) )
949
+ } else {
950
+ None
951
+ }
952
+ }
953
+
938
954
/// Send a mock signature to stackerdb to prove we are still alive
939
955
fn mock_sign ( & mut self , mock_proposal : MockProposal ) {
940
956
info ! ( "{self}: Mock signing mock proposal: {mock_proposal:?}" ) ;
0 commit comments