Skip to content

Commit 78b715c

Browse files
committed
Ensure the last set cycle is set by putting it on an exponential backoff to prevent waiting needlessly for a burn block
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 02fe4cb commit 78b715c

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

stacks-signer/src/runloop.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,6 @@ impl<Signer: SignerTrait<T>, T: StacksMessageCodec + Clone + Send + Debug> RunLo
286286
&mut self,
287287
reward_cycle: u64,
288288
) -> Result<Option<SignerConfig>, ConfigurationError> {
289-
// We can only register for a reward cycle if its stackerdb has been updated
290-
let last_calculated_reward_cycle =
291-
self.stacks_client.get_last_set_cycle().inspect_err(|e| {
292-
warn!("Error while fetching last calculated reward cycle: {e:?}");
293-
})?;
294-
if last_calculated_reward_cycle < reward_cycle as u128 {
295-
return Err(ConfigurationError::StackerDBNotUpdated);
296-
}
297-
298289
// We can only register for a reward cycle if a reward set exists.
299290
let signer_entries = match self.get_parsed_reward_set(reward_cycle) {
300291
Ok(Some(x)) => x,
@@ -304,6 +295,25 @@ impl<Signer: SignerTrait<T>, T: StacksMessageCodec + Clone + Send + Debug> RunLo
304295
return Err(e.into());
305296
}
306297
};
298+
299+
// Ensure that the stackerdb has been updated for the reward cycle before proceeding
300+
retry_with_exponential_backoff(|| {
301+
let last_calculated_reward_cycle = self
302+
.stacks_client
303+
.get_last_set_cycle()
304+
.map_err(|e| backoff::Error::transient(e.into()))?;
305+
if last_calculated_reward_cycle < reward_cycle as u128 {
306+
warn!(
307+
"Stackerdb has not been updated for reward cycle {reward_cycle}. Last calculated reward cycle is {last_calculated_reward_cycle}."
308+
);
309+
Err(backoff::Error::transient(
310+
ConfigurationError::StackerDBNotUpdated,
311+
))
312+
} else {
313+
Ok(())
314+
}
315+
})?;
316+
307317
let signer_slot_ids = match self.get_parsed_signer_slots(&self.stacks_client, reward_cycle)
308318
{
309319
Ok(x) => x,

0 commit comments

Comments
 (0)