@@ -128,6 +128,17 @@ impl SignerTrait<SignerMessage> for Signer {
128
128
debug ! ( "{self}: No event received" ) ;
129
129
return ;
130
130
} ;
131
+ if self . reward_cycle > current_reward_cycle
132
+ && !matches ! (
133
+ event,
134
+ SignerEvent :: StatusCheck | SignerEvent :: NewBurnBlock { .. }
135
+ )
136
+ {
137
+ // The reward cycle has not yet started for this signer instance
138
+ // Do not process any events other than status checks or new burn blocks
139
+ debug ! ( "{self}: Signer reward cycle has not yet started. Ignoring event." ) ;
140
+ return ;
141
+ }
131
142
match event {
132
143
SignerEvent :: BlockValidationResponse ( block_validate_response) => {
133
144
debug ! ( "{self}: Received a block proposal result from the stacks node..." ) ;
@@ -449,6 +460,15 @@ impl Signer {
449
460
. block_lookup ( & signer_signature_hash)
450
461
. expect ( "Failed to connect to signer DB" )
451
462
{
463
+ // Redundant check, but just in case the block proposal reward cycle was incorrectly overwritten, check again
464
+ if block_info. reward_cycle != self . reward_cycle {
465
+ // We are not signing for this reward cycle. Ignore the block.
466
+ debug ! (
467
+ "{self}: Received a block proposal for a different reward cycle. Ignore it." ;
468
+ "requested_reward_cycle" => block_proposal. reward_cycle
469
+ ) ;
470
+ return ;
471
+ }
452
472
let Some ( block_response) = self . determine_response ( & block_info) else {
453
473
// We are still waiting for a response for this block. Do nothing.
454
474
debug ! ( "{self}: Received a block proposal for a block we are already validating." ;
@@ -659,6 +679,14 @@ impl Signer {
659
679
// For mutability reasons, we need to take the block_info out of the map and add it back after processing
660
680
let mut block_info = match self . signer_db . block_lookup ( & signer_signature_hash) {
661
681
Ok ( Some ( block_info) ) => {
682
+ if block_info. reward_cycle != self . reward_cycle {
683
+ // We are not signing for this reward cycle. Ignore the block.
684
+ debug ! (
685
+ "{self}: Received a block validation for a block from a different reward cycle. Ignore it." ;
686
+ "requested_reward_cycle" => block_info. reward_cycle
687
+ ) ;
688
+ return None ;
689
+ }
662
690
if block_info. is_locally_finalized ( ) {
663
691
debug ! ( "{self}: Received block validation for a block that is already marked as {}. Ignoring..." , block_info. state) ;
664
692
return None ;
@@ -744,6 +772,14 @@ impl Signer {
744
772
}
745
773
let mut block_info = match self . signer_db . block_lookup ( & signer_signature_hash) {
746
774
Ok ( Some ( block_info) ) => {
775
+ if block_info. reward_cycle != self . reward_cycle {
776
+ // We are not signing for this reward cycle. Ignore the block.
777
+ debug ! (
778
+ "{self}: Received a block validation for a block from a different reward cycle. Ignore it." ;
779
+ "requested_reward_cycle" => block_info. reward_cycle
780
+ ) ;
781
+ return None ;
782
+ }
747
783
if block_info. is_locally_finalized ( ) {
748
784
debug ! ( "{self}: Received block validation for a block that is already marked as {}. Ignoring..." , block_info. state) ;
749
785
return None ;
@@ -916,6 +952,14 @@ impl Signer {
916
952
917
953
let mut block_info = match self . signer_db . block_lookup ( block_hash) {
918
954
Ok ( Some ( block_info) ) => {
955
+ if block_info. reward_cycle != self . reward_cycle {
956
+ // We are not signing for this reward cycle. Ignore the block.
957
+ debug ! (
958
+ "{self}: Received a block rejection for a block from a different reward cycle. Ignore it." ;
959
+ "requested_reward_cycle" => block_info. reward_cycle
960
+ ) ;
961
+ return ;
962
+ }
919
963
if block_info. state == BlockState :: GloballyRejected
920
964
|| block_info. state == BlockState :: GloballyAccepted
921
965
{
@@ -1018,14 +1062,23 @@ impl Signer {
1018
1062
"{self}: Received a block-accept signature: ({block_hash}, {signature}, {})" ,
1019
1063
metadata. server_version
1020
1064
) ;
1021
-
1022
- // Have we already processed this block?
1023
- match self . signer_db . get_block_state ( block_hash) {
1024
- Ok ( Some ( state) ) => {
1025
- if state == BlockState :: GloballyAccepted || state == BlockState :: GloballyRejected {
1026
- debug ! ( "{self}: Received block signature for a block that is already marked as {}. Ignoring..." , state) ;
1065
+ let mut block_info = match self . signer_db . block_lookup ( block_hash) {
1066
+ Ok ( Some ( block_info) ) => {
1067
+ if block_info. reward_cycle != self . reward_cycle {
1068
+ // We are not signing for this reward cycle. Ignore the block.
1069
+ debug ! (
1070
+ "{self}: Received a block signature for a block from a different reward cycle. Ignore it." ;
1071
+ "requested_reward_cycle" => block_info. reward_cycle
1072
+ ) ;
1027
1073
return ;
1028
1074
}
1075
+ if block_info. state == BlockState :: GloballyRejected
1076
+ || block_info. state == BlockState :: GloballyAccepted
1077
+ {
1078
+ debug ! ( "{self}: Received block signature for a block that is already marked as {}. Ignoring..." , block_info. state) ;
1079
+ return ;
1080
+ }
1081
+ block_info
1029
1082
}
1030
1083
Ok ( None ) => {
1031
1084
debug ! ( "{self}: Received block signature for a block we have not seen before. Ignoring..." ) ;
@@ -1035,7 +1088,7 @@ impl Signer {
1035
1088
warn ! ( "{self}: Failed to load block state: {e:?}" , ) ;
1036
1089
return ;
1037
1090
}
1038
- }
1091
+ } ;
1039
1092
1040
1093
// recover public key
1041
1094
let Ok ( public_key) = Secp256k1PublicKey :: recover_to_pubkey ( block_hash. bits ( ) , signature)
@@ -1102,12 +1155,6 @@ impl Signer {
1102
1155
}
1103
1156
1104
1157
// have enough signatures to broadcast!
1105
- let Ok ( Some ( mut block_info) ) = self . signer_db . block_lookup ( block_hash) . inspect_err ( |e| {
1106
- warn ! ( "{self}: Failed to load block {block_hash}: {e:?})" ) ;
1107
- } ) else {
1108
- warn ! ( "{self}: No such block {block_hash}" ) ;
1109
- return ;
1110
- } ;
1111
1158
// move block to LOCALLY accepted state.
1112
1159
// 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.
1113
1160
if let Err ( e) = block_info. mark_locally_accepted ( true ) {
0 commit comments