Skip to content

Commit 5b4a5ad

Browse files
authored
fix: Calculate the sleep duration in every iteration (#514)
Calling `sleep` in a loop means starting the sleep from the beginning on every iteration. When targeting a specific point in time, we must therefore recalculate the time until then every iteration, or start the sleep before the loop. Calculate the sleep duration in every iteration.
1 parent 60cb83f commit 5b4a5ad

File tree

1 file changed

+3
-5
lines changed
  • anchor/subnet_service/src

1 file changed

+3
-5
lines changed

anchor/subnet_service/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ async fn subnet_service<E: EthSpec>(
154154
HashSet::new()
155155
};
156156

157-
// Calculate duration until the first epoch boundary
158-
let mut next_epoch_delay = calculate_duration_to_next_epoch::<E>(&slot_clock);
159-
160157
loop {
158+
// Calculate duration until the next epoch boundary
159+
let next_epoch_delay = calculate_duration_to_next_epoch::<E>(&slot_clock);
160+
161161
tokio::select! {
162162
// Handle database changes for subnet join/leave (only if not subscribe_all_subnets)
163163
_ = db.changed(), if !subscribe_all_subnets => {
@@ -167,8 +167,6 @@ async fn subnet_service<E: EthSpec>(
167167
// Handle scheduled epoch boundaries (for both modes, but only if scoring is enabled)
168168
_ = sleep(next_epoch_delay), if !disable_gossipsub_topic_scoring => {
169169
handle_epoch_committee_update::<E>(&tx, &mut db, &previous_subnets, &chain_spec).await;
170-
// Recalculate the next epoch delay only after we've processed the epoch boundary
171-
next_epoch_delay = calculate_duration_to_next_epoch::<E>(&slot_clock);
172170
}
173171
}
174172
}

0 commit comments

Comments
 (0)