From daf21f6b9ffbbe952ce082cfd2df68870e065736 Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Wed, 11 Dec 2024 10:43:18 -0500 Subject: [PATCH 1/3] Remove signers older than the current reward cycle if they have no more blocks to process Signed-off-by: Jacinta Ferrant --- stacks-signer/src/runloop.rs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/stacks-signer/src/runloop.rs b/stacks-signer/src/runloop.rs index 11faadf871..e6dc4be85e 100644 --- a/stacks-signer/src/runloop.rs +++ b/stacks-signer/src/runloop.rs @@ -423,23 +423,15 @@ impl, 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(¤t_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 current_reward_cycle >= 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 { From 236716aa5ce16e0bd3e3659b28d4938cd99340ae Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Wed, 11 Dec 2024 17:00:47 -0500 Subject: [PATCH 2/3] Fix equality check for current_reward_cycle in cleanup_stale_signers Signed-off-by: Jacinta Ferrant --- stacks-signer/src/runloop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stacks-signer/src/runloop.rs b/stacks-signer/src/runloop.rs index e6dc4be85e..6d226a2592 100644 --- a/stacks-signer/src/runloop.rs +++ b/stacks-signer/src/runloop.rs @@ -423,7 +423,7 @@ impl, 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(); - if current_reward_cycle >= reward_cycle { + if reward_cycle >= current_reward_cycle { // We are either the current or a future reward cycle, so we are not stale. continue; } From a81f7199bb7db3f2d14c50a7018f4db4dee4d2ea Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Thu, 12 Dec 2024 09:26:08 -0500 Subject: [PATCH 3/3] Update changelog Signed-off-by: Jacinta Ferrant --- stacks-signer/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/stacks-signer/CHANGELOG.md b/stacks-signer/CHANGELOG.md index 2f1187de51..73d374f1be 100644 --- a/stacks-signer/CHANGELOG.md +++ b/stacks-signer/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE ## Added ## 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]