Skip to content

Commit

Permalink
Merge pull request #5454 from stacks-network/feat/always-send-block-r…
Browse files Browse the repository at this point in the history
…esponse

feat: always broadcast a BlockResponse, even if globally accepted
  • Loading branch information
hstove authored Nov 19, 2024
2 parents c3fec9e + b34bf5f commit 7985b33
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
16 changes: 16 additions & 0 deletions stacks-signer/src/signerdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,22 @@ impl BlockInfo {
self.state = state;
Ok(())
}

/// Check if the block is globally accepted or rejected
pub fn has_reached_consensus(&self) -> bool {
matches!(
self.state,
BlockState::GloballyAccepted | BlockState::GloballyRejected
)
}

/// Check if the block is locally accepted or rejected
pub fn is_locally_finalized(&self) -> bool {
matches!(
self.state,
BlockState::LocallyAccepted | BlockState::LocallyRejected
)
}
}

/// This struct manages a SQLite database connection
Expand Down
21 changes: 11 additions & 10 deletions stacks-signer/src/v0/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,7 @@ impl Signer {
.block_lookup(self.reward_cycle, &signer_signature_hash)
{
Ok(Some(block_info)) => {
if block_info.state == BlockState::GloballyRejected
|| block_info.state == BlockState::GloballyAccepted
{
if block_info.is_locally_finalized() {
debug!("{self}: Received block validation for a block that is already marked as {}. Ignoring...", block_info.state);
return None;
}
Expand All @@ -559,8 +557,11 @@ impl Signer {
}
};
if let Err(e) = block_info.mark_locally_accepted(false) {
warn!("{self}: Failed to mark block as locally accepted: {e:?}",);
return None;
if !block_info.has_reached_consensus() {
warn!("{self}: Failed to mark block as locally accepted: {e:?}",);
return None;
}
block_info.signed_self.get_or_insert(get_epoch_time_secs());
}
let signature = self
.private_key
Expand Down Expand Up @@ -598,9 +599,7 @@ impl Signer {
.block_lookup(self.reward_cycle, &signer_signature_hash)
{
Ok(Some(block_info)) => {
if block_info.state == BlockState::GloballyRejected
|| block_info.state == BlockState::GloballyAccepted
{
if block_info.is_locally_finalized() {
debug!("{self}: Received block validation for a block that is already marked as {}. Ignoring...", block_info.state);
return None;
}
Expand All @@ -617,8 +616,10 @@ impl Signer {
}
};
if let Err(e) = block_info.mark_locally_rejected() {
warn!("{self}: Failed to mark block as locally rejected: {e:?}",);
return None;
if !block_info.has_reached_consensus() {
warn!("{self}: Failed to mark block as locally rejected: {e:?}",);
return None;
}
}
let block_rejection = BlockRejection::from_validate_rejection(
block_validate_reject.clone(),
Expand Down

0 comments on commit 7985b33

Please sign in to comment.