Skip to content

Commit af235d0

Browse files
committed
fix: only attempt to refresh the signer during the next prepare phase
This handles the case where for the first block in a cycle (height % cycle_length == 0), it will report that it is in cycle N, but it will also report that it is in the prepare phase. This was resulting in refreshing the signer config too early. For example, with a cycle length of 20, at block 160, we would see a log: ``` Received a new burnchain block height (160) in the prepare phase of the next reward cycle (9). Checking for signer registration... ``` This is incorrect, because block 160 is not in the prepare phase for cycle 9.
1 parent b410197 commit af235d0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

stacks-signer/src/runloop.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ impl RewardCycleInfo {
8989
burnchain_block_height,
9090
)
9191
}
92+
93+
/// Check if the provided burnchain block height is in the prepare phase of the next cycle
94+
pub fn is_in_next_prepare_phase(&self, burnchain_block_height: u64) -> bool {
95+
let next_reward_cycle = self.reward_cycle.saturating_add(1);
96+
97+
self.is_in_prepare_phase(burnchain_block_height)
98+
&& self.get_reward_cycle(burnchain_block_height) == next_reward_cycle
99+
}
92100
}
93101

94102
/// The runloop for the stacks signer
@@ -299,7 +307,7 @@ impl RunLoop {
299307
}
300308
let current_reward_cycle = reward_cycle_info.reward_cycle;
301309
// We should only attempt to refresh the signer if we are not configured for the next reward cycle yet and we received a new burn block for its prepare phase
302-
if reward_cycle_info.is_in_prepare_phase(current_burn_block_height) {
310+
if reward_cycle_info.is_in_next_prepare_phase(current_burn_block_height) {
303311
let next_reward_cycle = current_reward_cycle.saturating_add(1);
304312
if self
305313
.stacks_signers

0 commit comments

Comments
 (0)