Skip to content

Commit

Permalink
Merge pull request #5562 from stacks-network/fix/remove-stale-signers
Browse files Browse the repository at this point in the history
Remove signers older than the current reward cycle if they have no more blocks to process
  • Loading branch information
jferrant authored Dec 13, 2024
2 parents 9e9d97e + 209fb60 commit b3b7117
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
1 change: 1 addition & 0 deletions stacks-signer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
- Introduced the `block_proposal_max_age_secs` configuration option for signers, enabling them to automatically ignore block proposals that exceed the specified age in seconds.

## Changed
- Improvements to the stale signer cleanup logic: deletes the prior signer if it has no remaining unprocessed blocks in its database

## [3.1.0.0.1.0]

Expand Down
24 changes: 8 additions & 16 deletions stacks-signer/src/runloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,23 +424,15 @@ impl<Signer: SignerTrait<T>, T: StacksMessageCodec + Clone + Send + Debug> RunLo
let mut to_delete = Vec::new();
for (idx, signer) in &mut self.stacks_signers {
let reward_cycle = signer.reward_cycle();
let next_reward_cycle = reward_cycle.wrapping_add(1);
let stale = match next_reward_cycle.cmp(&current_reward_cycle) {
std::cmp::Ordering::Less => true, // We are more than one reward cycle behind, so we are stale
std::cmp::Ordering::Equal => {
// We are the next reward cycle, so check if we were registered and have any pending blocks to process
match signer {
ConfiguredSigner::RegisteredSigner(signer) => {
!signer.has_unprocessed_blocks()
}
_ => true,
}
if reward_cycle >= current_reward_cycle {
// We are either the current or a future reward cycle, so we are not stale.
continue;
}
if let ConfiguredSigner::RegisteredSigner(signer) = signer {
if !signer.has_unprocessed_blocks() {
debug!("{signer}: Signer's tenure has completed.");
to_delete.push(*idx);
}
std::cmp::Ordering::Greater => false, // We are the current reward cycle, so we are not stale
};
if stale {
debug!("{signer}: Signer's tenure has completed.");
to_delete.push(*idx);
}
}
for idx in to_delete {
Expand Down

0 comments on commit b3b7117

Please sign in to comment.