@@ -35,8 +35,9 @@ use clarity::util::sleep_ms;
35
35
#[ cfg( any( test, feature = "testing" ) ) ]
36
36
use clarity:: util:: tests:: TestFlag ;
37
37
use libsigner:: v0:: messages:: {
38
- BlockAccepted , BlockRejection , BlockResponse , MessageSlotID , MockProposal , MockSignature ,
39
- RejectReason , RejectReasonPrefix , SignerMessage , StateMachineUpdate ,
38
+ BlockAccepted , BlockRejection , BlockResponse , BlockResponseData , MessageSlotID , MockProposal ,
39
+ MockSignature , RejectReason , RejectReasonPrefix , SignerMessage , SignerMessageMetadata ,
40
+ StateMachineUpdate ,
40
41
} ;
41
42
use libsigner:: v0:: signer_state:: GlobalStateEvaluator ;
42
43
use libsigner:: { BlockProposal , SignerEvent , SignerSession } ;
@@ -452,31 +453,36 @@ impl Signer {
452
453
let valid = block_info. valid ?;
453
454
let response = if valid {
454
455
debug ! ( "{self}: Accepting block {}" , block_info. block. block_id( ) ) ;
455
- self . create_block_acceptance ( & block_info. block )
456
+ self . create_block_acceptance ( & block_info. block ) . into ( )
456
457
} else {
457
458
debug ! ( "{self}: Rejecting block {}" , block_info. block. block_id( ) ) ;
458
459
self . create_block_rejection ( RejectReason :: RejectedInPriorRound , & block_info. block )
460
+ . into ( )
459
461
} ;
460
462
Some ( response)
461
463
}
462
464
463
- /// Create a block acceptance response for a block
464
- pub fn create_block_acceptance ( & self , block : & NakamotoBlock ) -> BlockResponse {
465
+ /// Create a block acceptance for a block
466
+ pub fn create_block_acceptance ( & self , block : & NakamotoBlock ) -> BlockAccepted {
465
467
let signature = self
466
468
. private_key
467
469
. sign ( block. header . signer_signature_hash ( ) . bits ( ) )
468
470
. expect ( "Failed to sign block" ) ;
469
- BlockResponse :: accepted (
470
- block. header . signer_signature_hash ( ) ,
471
+ BlockAccepted {
472
+ signer_signature_hash : block. header . signer_signature_hash ( ) ,
471
473
signature,
472
- self . signer_db . calculate_tenure_extend_timestamp (
473
- self . proposal_config
474
- . tenure_idle_timeout
475
- . saturating_add ( self . proposal_config . tenure_idle_timeout_buffer ) ,
476
- block,
477
- true ,
474
+ metadata : SignerMessageMetadata :: default ( ) ,
475
+ response_data : BlockResponseData :: new (
476
+ self . signer_db . calculate_tenure_extend_timestamp (
477
+ self . proposal_config
478
+ . tenure_idle_timeout
479
+ . saturating_add ( self . proposal_config . tenure_idle_timeout_buffer ) ,
480
+ block,
481
+ true ,
482
+ ) ,
483
+ RejectReason :: NotRejected ,
478
484
) ,
479
- )
485
+ }
480
486
}
481
487
482
488
/// The actual switch-on-event processing of an event.
@@ -676,8 +682,8 @@ impl Signer {
676
682
& self ,
677
683
reject_reason : RejectReason ,
678
684
block : & NakamotoBlock ,
679
- ) -> BlockResponse {
680
- BlockResponse :: rejected (
685
+ ) -> BlockRejection {
686
+ BlockRejection :: new (
681
687
block. header . signer_signature_hash ( ) ,
682
688
reject_reason,
683
689
& self . private_key ,
@@ -716,13 +722,13 @@ impl Signer {
716
722
}
717
723
718
724
/// Check if block should be rejected based on the appropriate state (either local or global)
719
- /// Will return a BlockResponse::Rejection if the block is invalid, none otherwise.
725
+ /// Will return a BlockRejection if the block is invalid, none otherwise.
720
726
fn check_block_against_state (
721
727
& mut self ,
722
728
stacks_client : & StacksClient ,
723
729
sortition_state : & mut Option < SortitionsView > ,
724
730
block : & NakamotoBlock ,
725
- ) -> Option < BlockResponse > {
731
+ ) -> Option < BlockRejection > {
726
732
let Some ( latest_version) = self
727
733
. global_state_evaluator
728
734
. determine_latest_supported_signer_protocol_version ( )
@@ -743,14 +749,14 @@ impl Signer {
743
749
}
744
750
745
751
/// Check if block should be rejected based on the local view of the sortition state
746
- /// Will return a BlockResponse::Rejection if the block is invalid, none otherwise.
752
+ /// Will return a BlockRejection if the block is invalid, none otherwise.
747
753
/// This is the pre-global signer state activation path.
748
754
fn check_block_against_local_state (
749
755
& mut self ,
750
756
stacks_client : & StacksClient ,
751
757
sortition_state : & mut Option < SortitionsView > ,
752
758
block : & NakamotoBlock ,
753
- ) -> Option < BlockResponse > {
759
+ ) -> Option < BlockRejection > {
754
760
let signer_signature_hash = block. header . signer_signature_hash ( ) ;
755
761
let block_id = block. block_id ( ) ;
756
762
// Get sortition view if we don't have it
@@ -804,13 +810,13 @@ impl Signer {
804
810
}
805
811
806
812
/// Check if block should be rejected based on global signer state
807
- /// Will return a BlockResponse::Rejection if the block is invalid, none otherwise.
813
+ /// Will return a BlockRejection if the block is invalid, none otherwise.
808
814
/// This is the Post-global signer state activation path
809
815
fn check_block_against_global_state (
810
816
& mut self ,
811
817
stacks_client : & StacksClient ,
812
818
block : & NakamotoBlock ,
813
- ) -> Option < BlockResponse > {
819
+ ) -> Option < BlockRejection > {
814
820
let signer_signature_hash = block. header . signer_signature_hash ( ) ;
815
821
let block_id = block. block_id ( ) ;
816
822
// First update our global state evaluator with our local state if we have one
@@ -1053,12 +1059,10 @@ impl Signer {
1053
1059
self . signer_db
1054
1060
. insert_block ( & block_info)
1055
1061
. unwrap_or_else ( |e| self . handle_insert_block_error ( e) ) ;
1056
- let block_response = self . create_block_acceptance ( & block_info. block ) ;
1057
- if let Some ( accepted) = block_response. as_block_accepted ( ) {
1058
- // have to save the signature _after_ the block info
1059
- self . handle_block_signature ( stacks_client, accepted) ;
1060
- }
1061
- self . impl_send_block_response ( & block_info. block , block_response) ;
1062
+ let accepted = self . create_block_acceptance ( & block_info. block ) ;
1063
+ // have to save the signature _after_ the block info
1064
+ self . handle_block_signature ( stacks_client, & accepted) ;
1065
+ self . impl_send_block_response ( & block_info. block , accepted. into ( ) ) ;
1062
1066
}
1063
1067
1064
1068
/// Handle block proposal messages submitted to signers stackerdb
@@ -1149,16 +1153,16 @@ impl Signer {
1149
1153
}
1150
1154
1151
1155
// Check if proposal can be rejected now if not valid against sortition view
1152
- let block_response =
1156
+ let block_rejection =
1153
1157
self . check_block_against_state ( stacks_client, sortition_state, & block_proposal. block ) ;
1154
1158
1155
1159
#[ cfg( any( test, feature = "testing" ) ) ]
1156
- let block_response =
1157
- self . test_reject_block_proposal ( block_proposal, & mut block_info, block_response ) ;
1160
+ let block_rejection =
1161
+ self . test_reject_block_proposal ( block_proposal, & mut block_info, block_rejection ) ;
1158
1162
1159
- if let Some ( block_response ) = block_response {
1163
+ if let Some ( block_rejection ) = block_rejection {
1160
1164
// We know proposal is invalid. Send rejection message, do not do further validation and do not store it.
1161
- self . send_block_response ( & block_info. block , block_response ) ;
1165
+ self . send_block_response ( & block_info. block , block_rejection . into ( ) ) ;
1162
1166
} else {
1163
1167
// Just in case check if the last block validation submission timed out.
1164
1168
self . check_submitted_block_proposal ( ) ;
@@ -1240,7 +1244,7 @@ impl Signer {
1240
1244
& mut self ,
1241
1245
stacks_client : & StacksClient ,
1242
1246
proposed_block : & NakamotoBlock ,
1243
- ) -> Option < BlockResponse > {
1247
+ ) -> Option < BlockRejection > {
1244
1248
let signer_signature_hash = proposed_block. header . signer_signature_hash ( ) ;
1245
1249
// If this is a tenure change block, ensure that it confirms the correct number of blocks from the parent tenure.
1246
1250
if let Some ( tenure_change) = proposed_block. get_tenure_change_tx_payload ( ) {
@@ -1357,12 +1361,9 @@ impl Signer {
1357
1361
return ;
1358
1362
}
1359
1363
1360
- if let Some ( block_response ) =
1364
+ if let Some ( block_rejection ) =
1361
1365
self . check_block_against_signer_db_state ( stacks_client, & block_info. block )
1362
1366
{
1363
- let Some ( block_rejection) = block_response. as_block_rejection ( ) else {
1364
- return ;
1365
- } ;
1366
1367
// The signer db state has changed. We no longer view this block as valid. Override the validation response.
1367
1368
if let Err ( e) = block_info. mark_locally_rejected ( ) {
1368
1369
if !block_info. has_reached_consensus ( ) {
@@ -1372,11 +1373,8 @@ impl Signer {
1372
1373
self . signer_db
1373
1374
. insert_block ( & block_info)
1374
1375
. unwrap_or_else ( |e| self . handle_insert_block_error ( e) ) ;
1375
- self . handle_block_rejection ( block_rejection, sortition_state) ;
1376
- self . impl_send_block_response (
1377
- & block_info. block ,
1378
- BlockResponse :: Rejected ( block_rejection. clone ( ) ) ,
1379
- ) ;
1376
+ self . handle_block_rejection ( & block_rejection, sortition_state) ;
1377
+ self . impl_send_block_response ( & block_info. block , block_rejection. into ( ) ) ;
1380
1378
} else {
1381
1379
if let Err ( e) = block_info. mark_locally_accepted ( false ) {
1382
1380
if !block_info. has_reached_consensus ( ) {
@@ -1450,7 +1448,7 @@ impl Signer {
1450
1448
. insert_block ( & block_info)
1451
1449
. unwrap_or_else ( |e| self . handle_insert_block_error ( e) ) ;
1452
1450
self . handle_block_rejection ( & block_rejection, sortition_state) ;
1453
- self . impl_send_block_response ( & block_info. block , BlockResponse :: Rejected ( block_rejection) ) ;
1451
+ self . impl_send_block_response ( & block_info. block , block_rejection. into ( ) ) ;
1454
1452
}
1455
1453
1456
1454
/// Handle the block validate response returned from our prior calls to submit a block for validation
@@ -1562,13 +1560,13 @@ impl Signer {
1562
1560
) ,
1563
1561
& block_info. block ,
1564
1562
) ;
1565
- block_info. reject_reason = Some ( rejection. get_response_data ( ) . reject_reason . clone ( ) ) ;
1563
+ block_info. reject_reason = Some ( rejection. response_data . reject_reason . clone ( ) ) ;
1566
1564
if let Err ( e) = block_info. mark_locally_rejected ( ) {
1567
1565
if !block_info. has_reached_consensus ( ) {
1568
1566
warn ! ( "{self}: Failed to mark block as locally rejected: {e:?}" ) ;
1569
1567
}
1570
1568
} ;
1571
- self . impl_send_block_response ( & block_info. block , rejection) ;
1569
+ self . impl_send_block_response ( & block_info. block , rejection. into ( ) ) ;
1572
1570
1573
1571
self . signer_db
1574
1572
. insert_block ( & block_info)
0 commit comments