Skip to content

Commit 7985b33

Browse files
authored
Merge pull request #5454 from stacks-network/feat/always-send-block-response
feat: always broadcast a BlockResponse, even if globally accepted
2 parents c3fec9e + b34bf5f commit 7985b33

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

stacks-signer/src/signerdb.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,22 @@ impl BlockInfo {
258258
self.state = state;
259259
Ok(())
260260
}
261+
262+
/// Check if the block is globally accepted or rejected
263+
pub fn has_reached_consensus(&self) -> bool {
264+
matches!(
265+
self.state,
266+
BlockState::GloballyAccepted | BlockState::GloballyRejected
267+
)
268+
}
269+
270+
/// Check if the block is locally accepted or rejected
271+
pub fn is_locally_finalized(&self) -> bool {
272+
matches!(
273+
self.state,
274+
BlockState::LocallyAccepted | BlockState::LocallyRejected
275+
)
276+
}
261277
}
262278

263279
/// This struct manages a SQLite database connection

stacks-signer/src/v0/signer.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,7 @@ impl Signer {
540540
.block_lookup(self.reward_cycle, &signer_signature_hash)
541541
{
542542
Ok(Some(block_info)) => {
543-
if block_info.state == BlockState::GloballyRejected
544-
|| block_info.state == BlockState::GloballyAccepted
545-
{
543+
if block_info.is_locally_finalized() {
546544
debug!("{self}: Received block validation for a block that is already marked as {}. Ignoring...", block_info.state);
547545
return None;
548546
}
@@ -559,8 +557,11 @@ impl Signer {
559557
}
560558
};
561559
if let Err(e) = block_info.mark_locally_accepted(false) {
562-
warn!("{self}: Failed to mark block as locally accepted: {e:?}",);
563-
return None;
560+
if !block_info.has_reached_consensus() {
561+
warn!("{self}: Failed to mark block as locally accepted: {e:?}",);
562+
return None;
563+
}
564+
block_info.signed_self.get_or_insert(get_epoch_time_secs());
564565
}
565566
let signature = self
566567
.private_key
@@ -598,9 +599,7 @@ impl Signer {
598599
.block_lookup(self.reward_cycle, &signer_signature_hash)
599600
{
600601
Ok(Some(block_info)) => {
601-
if block_info.state == BlockState::GloballyRejected
602-
|| block_info.state == BlockState::GloballyAccepted
603-
{
602+
if block_info.is_locally_finalized() {
604603
debug!("{self}: Received block validation for a block that is already marked as {}. Ignoring...", block_info.state);
605604
return None;
606605
}
@@ -617,8 +616,10 @@ impl Signer {
617616
}
618617
};
619618
if let Err(e) = block_info.mark_locally_rejected() {
620-
warn!("{self}: Failed to mark block as locally rejected: {e:?}",);
621-
return None;
619+
if !block_info.has_reached_consensus() {
620+
warn!("{self}: Failed to mark block as locally rejected: {e:?}",);
621+
return None;
622+
}
622623
}
623624
let block_rejection = BlockRejection::from_validate_rejection(
624625
block_validate_reject.clone(),

0 commit comments

Comments
 (0)