@@ -64,6 +64,11 @@ pub static TEST_PAUSE_BLOCK_BROADCAST: std::sync::Mutex<Option<bool>> = std::syn
64
64
/// Skip broadcasting the block to the network
65
65
pub static TEST_SKIP_BLOCK_BROADCAST : std:: sync:: Mutex < Option < bool > > = std:: sync:: Mutex :: new ( None ) ;
66
66
67
+ #[ cfg( any( test, feature = "testing" ) ) ]
68
+ /// Skip any block responses from other signers
69
+ pub static TEST_IGNORE_BLOCK_RESPONSES : std:: sync:: Mutex < Option < bool > > =
70
+ std:: sync:: Mutex :: new ( None ) ;
71
+
67
72
/// The stacks signer registered for the reward cycle
68
73
#[ derive( Debug ) ]
69
74
pub struct Signer {
@@ -476,10 +481,7 @@ impl Signer {
476
481
self . test_reject_block_proposal ( block_proposal, & mut block_info, block_response) ;
477
482
478
483
if let Some ( block_response) = block_response {
479
- // We know proposal is invalid. Send rejection message, do not do further validation
480
- if let Err ( e) = block_info. mark_locally_rejected ( ) {
481
- warn ! ( "{self}: Failed to mark block as locally rejected: {e:?}" , ) ;
482
- } ;
484
+ // We know proposal is invalid. Send rejection message, do not do further validation and do not store it.
483
485
debug ! ( "{self}: Broadcasting a block response to stacks node: {block_response:?}" ) ;
484
486
let res = self
485
487
. stackerdb
@@ -535,6 +537,10 @@ impl Signer {
535
537
stacks_client : & StacksClient ,
536
538
block_response : & BlockResponse ,
537
539
) {
540
+ #[ cfg( any( test, feature = "testing" ) ) ]
541
+ if self . test_ignore_block_responses ( block_response) {
542
+ return ;
543
+ }
538
544
match block_response {
539
545
BlockResponse :: Accepted ( accepted) => {
540
546
self . handle_block_signature ( stacks_client, accepted) ;
@@ -870,7 +876,7 @@ impl Signer {
870
876
// Not enough rejection signatures to make a decision
871
877
return ;
872
878
}
873
- debug ! ( "{self}: {total_reject_weight}/{total_weight} signers voteed to reject the block {block_hash}" ) ;
879
+ debug ! ( "{self}: {total_reject_weight}/{total_weight} signers voted to reject the block {block_hash}" ) ;
874
880
if let Err ( e) = block_info. mark_globally_rejected ( ) {
875
881
warn ! ( "{self}: Failed to mark block as globally rejected: {e:?}" , ) ;
876
882
}
@@ -999,7 +1005,7 @@ impl Signer {
999
1005
return ;
1000
1006
} ;
1001
1007
// move block to LOCALLY accepted state.
1002
- // We only mark this GLOBALLY accepted if we manage to broadcast it.. .
1008
+ // It is only considered globally accepted IFF we receive a new block event confirming it OR see the chain tip of the node advance to it .
1003
1009
if let Err ( e) = block_info. mark_locally_accepted ( true ) {
1004
1010
// Do not abort as we should still try to store the block signature threshold
1005
1011
warn ! ( "{self}: Failed to mark block as locally accepted: {e:?}" ) ;
@@ -1012,22 +1018,8 @@ impl Signer {
1012
1018
panic ! ( "{self} Failed to write block to signerdb: {e}" ) ;
1013
1019
} ) ;
1014
1020
#[ cfg( any( test, feature = "testing" ) ) ]
1015
- {
1016
- if * TEST_PAUSE_BLOCK_BROADCAST . lock ( ) . unwrap ( ) == Some ( true ) {
1017
- // Do an extra check just so we don't log EVERY time.
1018
- warn ! ( "Block broadcast is stalled due to testing directive." ;
1019
- "block_id" => %block_info. block. block_id( ) ,
1020
- "height" => block_info. block. header. chain_length,
1021
- ) ;
1022
- while * TEST_PAUSE_BLOCK_BROADCAST . lock ( ) . unwrap ( ) == Some ( true ) {
1023
- std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) ;
1024
- }
1025
- info ! ( "Block validation is no longer stalled due to testing directive." ;
1026
- "block_id" => %block_info. block. block_id( ) ,
1027
- "height" => block_info. block. header. chain_length,
1028
- ) ;
1029
- }
1030
- }
1021
+ self . test_pause_block_broadcast ( & block_info) ;
1022
+
1031
1023
self . broadcast_signed_block ( stacks_client, block_info. block , & addrs_to_sigs) ;
1032
1024
if self
1033
1025
. submitted_block_proposal
@@ -1137,6 +1129,36 @@ impl Signer {
1137
1129
}
1138
1130
}
1139
1131
1132
+ #[ cfg( any( test, feature = "testing" ) ) ]
1133
+ fn test_ignore_block_responses ( & self , block_response : & BlockResponse ) -> bool {
1134
+ if * TEST_IGNORE_BLOCK_RESPONSES . lock ( ) . unwrap ( ) == Some ( true ) {
1135
+ warn ! (
1136
+ "{self}: Ignoring block response due to testing directive" ;
1137
+ "block_response" => %block_response
1138
+ ) ;
1139
+ return true ;
1140
+ }
1141
+ false
1142
+ }
1143
+
1144
+ #[ cfg( any( test, feature = "testing" ) ) ]
1145
+ fn test_pause_block_broadcast ( & self , block_info : & BlockInfo ) {
1146
+ if * TEST_PAUSE_BLOCK_BROADCAST . lock ( ) . unwrap ( ) == Some ( true ) {
1147
+ // Do an extra check just so we don't log EVERY time.
1148
+ warn ! ( "{self}: Block broadcast is stalled due to testing directive." ;
1149
+ "block_id" => %block_info. block. block_id( ) ,
1150
+ "height" => block_info. block. header. chain_length,
1151
+ ) ;
1152
+ while * TEST_PAUSE_BLOCK_BROADCAST . lock ( ) . unwrap ( ) == Some ( true ) {
1153
+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) ;
1154
+ }
1155
+ info ! ( "{self}: Block validation is no longer stalled due to testing directive." ;
1156
+ "block_id" => %block_info. block. block_id( ) ,
1157
+ "height" => block_info. block. header. chain_length,
1158
+ ) ;
1159
+ }
1160
+ }
1161
+
1140
1162
/// Send a mock signature to stackerdb to prove we are still alive
1141
1163
fn mock_sign ( & mut self , mock_proposal : MockProposal ) {
1142
1164
info ! ( "{self}: Mock signing mock proposal: {mock_proposal:?}" ) ;
0 commit comments