Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: always broadcast a BlockResponse, even if globally accepted #5454

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) => {
hstove marked this conversation as resolved.
Show resolved Hide resolved
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