Skip to content

Remove signers older than the current reward cycle if they have no more blocks to process #5562

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

Merged
merged 4 commits into from
Dec 13, 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
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