From cc63c2b76930a82f79676bb6edb8823a1194d3ce Mon Sep 17 00:00:00 2001 From: realbigsean Date: Fri, 3 Apr 2020 21:09:50 -0400 Subject: [PATCH] order of operations fix in the duration_to_next_slot calculation (#981) * order of operations fix in the duration_to_next_slot calculation * use slot_clock.duration_to_slot() to simplify the duration_to_subscribe calculation * fix error message --- .../network/src/attestation_service/mod.rs | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/beacon_node/network/src/attestation_service/mod.rs b/beacon_node/network/src/attestation_service/mod.rs index aa792d5dbc..e4c3195129 100644 --- a/beacon_node/network/src/attestation_service/mod.rs +++ b/beacon_node/network/src/attestation_service/mod.rs @@ -303,24 +303,14 @@ impl AttestationService { .expect("ADVANCE_SUBSCRIPTION_TIME cannot be too large"); // calculate the time to subscribe to the subnet - let duration_to_subscribe = { - // The -1 is done here to exclude the current slot duration, as we will use - // `duration_to_next_slot`. - let slots_until_subscribe = exact_subnet - .slot - .saturating_sub(current_slot) - .saturating_sub(1u64); + let duration_to_subscribe = self + .beacon_chain + .slot_clock + .duration_to_slot(exact_subnet.slot) + .ok_or_else(|| "Unable to determine duration to subscription slot")? + .checked_sub(advance_subscription_duration) + .unwrap_or_else(|| Duration::from_secs(0)); - duration_to_next_slot - .checked_add(slot_duration) - .ok_or_else(|| "Overflow in adding slot_duration attestation time")? - .checked_mul(slots_until_subscribe.as_u64() as u32) - .ok_or_else(|| { - "Overflow in multiplying number of slots in attestation time" - })? - .checked_sub(advance_subscription_duration) - .unwrap_or_else(|| Duration::from_secs(0)) - }; // the duration until we no longer need this subscription. We assume a single slot is // sufficient. let expected_end_subscription_duration = duration_to_subscribe