From f83d02b394d7cc40e5ce5647c286d061bb2f9599 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sat, 16 Feb 2019 15:09:43 +1100 Subject: [PATCH] Update previous epoch function --- eth2/types/src/beacon_state.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/eth2/types/src/beacon_state.rs b/eth2/types/src/beacon_state.rs index 6a4033d5c..2e1df45f2 100644 --- a/eth2/types/src/beacon_state.rs +++ b/eth2/types/src/beacon_state.rs @@ -203,7 +203,12 @@ impl BeaconState { /// /// Spec v0.2.0 pub fn previous_epoch(&self, spec: &ChainSpec) -> Epoch { - self.current_epoch(spec).saturating_sub(1_u64) + let current_epoch = self.current_epoch(&spec); + if current_epoch == spec.genesis_epoch { + current_epoch + } else { + current_epoch - 1 + } } /// The epoch following `self.current_epoch()`.