Skip to content

Commit 658e051

Browse files
committed
refactor: improve flow deciding whether to reevaluate block
1 parent 9e655a2 commit 658e051

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

stacks-signer/src/v0/signer.rs

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -559,38 +559,19 @@ impl Signer {
559559
// TODO: should add a check to ignore an old burn block height if we know its outdated. Would require us to store the burn block height we last saw on the side.
560560
// the signer needs to be able to determine whether or not the block they're about to sign would conflict with an already-signed Stacks block
561561
let signer_signature_hash = block_proposal.block.header.signer_signature_hash();
562-
if let Some(block_info) = self.block_lookup_by_reward_cycle(&signer_signature_hash) {
563-
if should_reevaluate_block(&block_info) {
564-
// Treat this case the same as if no block info was found
562+
let prior_evaluation = self
563+
.block_lookup_by_reward_cycle(&signer_signature_hash)
564+
.and_then(|block_info| if should_reevaluate_block(&block_info) {
565+
debug!("Received a proposal for this block before, but our rejection reason allows us to reconsider";
566+
"reject_reason" => ?block_info.reject_reason);
567+
None
565568
} else {
566-
let Some(block_response) = self.determine_response(&block_info) else {
567-
// We are still waiting for a response for this block. Do nothing.
568-
debug!(
569-
"{self}: Received a block proposal for a block we are already validating.";
570-
"signer_sighash" => %signer_signature_hash,
571-
"block_id" => %block_proposal.block.block_id()
572-
);
573-
return;
574-
};
575-
576-
// Submit a proposal response to the .signers contract for miners
577-
debug!("{self}: Broadcasting a block response to stacks node: {block_response:?}");
578-
579-
let accepted = matches!(block_response, BlockResponse::Accepted(..));
580-
if let Err(e) = self
581-
.stackerdb
582-
.send_message_with_retry::<SignerMessage>(block_response.into())
583-
{
584-
warn!("{self}: Failed to send block response to stacker-db: {e:?}");
585-
} else {
586-
crate::monitoring::actions::increment_block_responses_sent(accepted);
587-
crate::monitoring::actions::record_block_response_latency(
588-
&block_proposal.block,
589-
);
590-
}
569+
Some(block_info)
570+
});
591571

592-
return;
593-
}
572+
// we previously considered this proposal, handle the status here
573+
if let Some(block_info) = prior_evaluation {
574+
return self.handle_prior_proposal_eval(&block_info);
594575
}
595576

596577
info!(
@@ -675,6 +656,32 @@ impl Signer {
675656
}
676657
}
677658

659+
fn handle_prior_proposal_eval(&mut self, block_info: &BlockInfo) {
660+
let Some(block_response) = self.determine_response(&block_info) else {
661+
// We are still waiting for a response for this block. Do nothing.
662+
debug!(
663+
"{self}: Received a block proposal for a block we are already validating.";
664+
"signer_sighash" => %block_info.signer_signature_hash(),
665+
"block_id" => %block_info.block.block_id()
666+
);
667+
return;
668+
};
669+
670+
// Submit a proposal response to the .signers contract for miners
671+
debug!("{self}: Broadcasting a block response to stacks node: {block_response:?}");
672+
673+
let accepted = matches!(block_response, BlockResponse::Accepted(..));
674+
if let Err(e) = self
675+
.stackerdb
676+
.send_message_with_retry::<SignerMessage>(block_response.into())
677+
{
678+
warn!("{self}: Failed to send block response to stacker-db: {e:?}");
679+
} else {
680+
crate::monitoring::actions::increment_block_responses_sent(accepted);
681+
crate::monitoring::actions::record_block_response_latency(&block_info.block);
682+
}
683+
}
684+
678685
/// Handle block response messages from a signer
679686
fn handle_block_response(
680687
&mut self,

0 commit comments

Comments
 (0)