Repository: input-output-hk/mithril
Pull request #661 (2022-12-19 11:38:58)

Simplify epoch offset computations
## Content

This PR includes enhance epoch offsetting computations by only use a Result when the resulting epoch can be negative.

## Pre-submit checklist

- Branch
  - [x] Tests are provided (if possible)
  - [x] Commit sequence broadly makes sense
  - [x] Key commits have useful messages
- PR
  - [x] No clippy warnings in the CI
  - [x] Self-reviewed the diff
  - [x] Useful pull request description
  - [x] Reviewer requested

## Issue(s)
Relates to #662 



Patch:
diff --git a/mithril-aggregator/src/command_args.rs b/mithril-aggregator/src/command_args.rs
index ba1139b73..de917effe 100644
--- a/mithril-aggregator/src/command_args.rs
+++ b/mithril-aggregator/src/command_args.rs
@@ -110,7 +110,7 @@ async fn do_first_launch_initialization_if_needed(
         Epoch(0) => (Epoch(0), Epoch(1)),
         epoch => (
             epoch.offset_to_signer_retrieval_epoch()?,
-            epoch.offset_to_next_signer_retrieval_epoch()?,
+            epoch.offset_to_next_signer_retrieval_epoch(),
         ),
     };
 
diff --git a/mithril-aggregator/src/dependency.rs b/mithril-aggregator/src/dependency.rs
index 7536d5472..44e4ac6bd 100644
--- a/mithril-aggregator/src/dependency.rs
+++ b/mithril-aggregator/src/dependency.rs
@@ -104,9 +104,7 @@ impl DependencyManager {
         let work_epoch = current_epoch
             .offset_to_signer_retrieval_epoch()
             .expect("epoch.offset_by SIGNER_EPOCH_RETRIEVAL_OFFSET should not fail");
-        let epoch_to_sign = current_epoch
-            .offset_to_next_signer_retrieval_epoch()
-            .expect("epoch.offset_by NEXT_SIGNER_EPOCH_RETRIEVAL_OFFSET should not fail");
+        let epoch_to_sign = current_epoch.offset_to_next_signer_retrieval_epoch();
 
         (work_epoch, epoch_to_sign)
     }
diff --git a/mithril-aggregator/src/multi_signer.rs b/mithril-aggregator/src/multi_signer.rs
index 7bbb8094c..39b406279 100644
--- a/mithril-aggregator/src/multi_signer.rs
+++ b/mithril-aggregator/src/multi_signer.rs
@@ -1,27 +1,23 @@
-use std::collections::HashMap;
-use std::sync::Arc;
-
 use async_trait::async_trait;
 use chrono::prelude::*;
 use hex::ToHex;
 use slog_scope::{debug, trace, warn};
+use std::{collections::HashMap, sync::Arc};
 use thiserror::Error;
 
-use mithril_common::crypto_helper::{
-    key_decode_hex, key_encode_hex, ProtocolAggregateVerificationKey, ProtocolAggregationError,
-    ProtocolClerk, ProtocolKeyRegistration, ProtocolMultiSignature, ProtocolParameters,
-    ProtocolPartyId, ProtocolRegistrationError, ProtocolSignerVerificationKey,
-    ProtocolSingleSignature, ProtocolStakeDistribution,
-};
-use mithril_common::entities::{self, SignerWithStake};
-use mithril_common::store::{StakeStore, StakeStorer, StoreError};
 use mithril_common::{
-    NEXT_SIGNER_EPOCH_RETRIEVAL_OFFSET, SIGNER_EPOCH_RECORDING_OFFSET,
-    SIGNER_EPOCH_RETRIEVAL_OFFSET,
+    crypto_helper::{
+        key_decode_hex, key_encode_hex, ProtocolAggregateVerificationKey, ProtocolAggregationError,
+        ProtocolClerk, ProtocolKeyRegistration, ProtocolMultiSignature, ProtocolParameters,
+        ProtocolPartyId, ProtocolRegistrationError, ProtocolSignerVerificationKey,
+        ProtocolSingleSignature, ProtocolStakeDistribution,
+    },
+    entities::{self, Epoch, SignerWithStake},
+    store::{StakeStore, StakeStorer, StoreError},
 };
 
-use crate::store::{SingleSignatureStorer, VerificationKeyStorer};
 use crate::{
+    store::{SingleSignatureStorer, VerificationKeyStorer},
     ProtocolParametersStore, ProtocolParametersStorer, SingleSignatureStore, VerificationKeyStore,
 };
 
@@ -191,13 +187,10 @@ pub trait MultiSigner: Sync + Send {
     }
 
     /// Get signers with stake
-    async fn get_signers_with_stake(&self)
-        -> Result<Vec<entities::SignerWithStake>, ProtocolError>;
+    async fn get_signers_with_stake(&self) -> Result<Vec<SignerWithStake>, ProtocolError>;
 
     /// Get signers for the next epoch with their stake
-    async fn get_next_signers_with_stake(
-        &self,
-    ) -> Result<Vec<entities::SignerWithStake>, ProtocolError>;
+    async fn get_next_signers_with_stake(&self) -> Result<Vec<SignerWithStake>, ProtocolError>;
 
     /// Registers a single signature
     async fn register_single_signature(
@@ -322,18 +315,12 @@ impl MultiSignerImpl {
         }
     }
 
-    /// Get stake distribution with epoch offset
-    async fn get_stake_distribution_with_epoch_offset(
+    /// Get the [stake distribution][ProtocolStakeDistribution] for the given `epoch`
+    async fn get_stake_distribution_at_epoch(
         &self,
-        epoch_offset: i64,
+        epoch: Epoch,
     ) -> Result<ProtocolStakeDistribution, ProtocolError> {
-        debug!("Get stake distribution with epoch offset"; "epoch_offset"=>epoch_offset);
-        let epoch = self
-            .current_beacon
-            .as_ref()
-            .ok_or_else(ProtocolError::UnavailableBeacon)?
-            .epoch
-            .offset_by(epoch_offset)?;
+        debug!("Get stake distribution at epoch"; "epoch"=> #?epoch);
 
         let stakes = self
             .stake_store
@@ -343,18 +330,12 @@ impl MultiSignerImpl {
         Ok(stakes.into_iter().collect::<ProtocolStakeDistribution>())
     }
 
-    /// Get protocol parameters with epoch offset
-    async fn get_protocol_parameters_with_epoch_offset(
+    /// Get the [protocol parameters][ProtocolParameters] for the given `epoch`
+    async fn get_protocol_parameters_at_epoch(
         &self,
-        epoch_offset: i64,
+        epoch: Epoch,
     ) -> Result<Option<ProtocolParameters>, ProtocolError> {
-        debug!("Get protocol parameters with epoch offset"; "epoch_offset"=>epoch_offset);
-        let epoch = self
-            .current_beacon
-            .as_ref()
-            .ok_or_else(ProtocolError::UnavailableBeacon)?
-            .epoch
-            .offset_by(epoch_offset)?;
+        debug!("Get protocol parameters at epoch"; "epoch"=> #?epoch);
 
         match self
             .protocol_parameters_store
@@ -431,8 +412,13 @@ impl MultiSigner for MultiSignerImpl {
     /// Get protocol parameters
     async fn get_protocol_parameters(&self) -> Result<Option<ProtocolParameters>, ProtocolError> {
         debug!("Get protocol parameters");
-        self.get_protocol_parameters_with_epoch_offset(SIGNER_EPOCH_RETRIEVAL_OFFSET)
-            .await
+        let epoch = self
+            .current_beacon
+            .as_ref()
+            .ok_or_else(ProtocolError::UnavailableBeacon)?
+            .epoch
+            .offset_to_signer_retrieval_epoch()?;
+        self.get_protocol_parameters_at_epoch(epoch).await
     }
 
     /// Update protocol parameters
@@ -446,7 +432,7 @@ impl MultiSigner for MultiSignerImpl {
             .as_ref()
             .ok_or_else(ProtocolError::UnavailableBeacon)?
             .epoch
-            .offset_by(SIGNER_EPOCH_RECORDING_OFFSET)?;
+            .offset_to_recording_epoch();
 
         self.protocol_parameters_store
             .save_protocol_parameters(epoch, protocol_parameters.to_owned().into())
@@ -459,15 +445,25 @@ impl MultiSigner for MultiSignerImpl {
         &self,
     ) -> Result<Option<ProtocolParameters>, ProtocolError> {
         debug!("Get next protocol parameters");
-        self.get_protocol_parameters_with_epoch_offset(NEXT_SIGNER_EPOCH_RETRIEVAL_OFFSET)
-            .await
+        let epoch = self
+            .current_beacon
+            .as_ref()
+            .ok_or_else(ProtocolError::UnavailableBeacon)?
+            .epoch
+            .offset_to_next_signer_retrieval_epoch();
+        self.get_protocol_parameters_at_epoch(epoch).await
     }
 
     /// Get stake distribution
     async fn get_stake_distribution(&self) -> Result<ProtocolStakeDistribution, ProtocolError> {
         debug!("Get stake distribution");
-        self.get_stake_distribution_with_epoch_offset(SIGNER_EPOCH_RETRIEVAL_OFFSET)
-            .await
+        let epoch = self
+            .current_beacon
+            .as_ref()
+            .ok_or_else(ProtocolError::UnavailableBeacon)?
+            .epoch
+            .offset_to_signer_retrieval_epoch()?;
+        self.get_stake_distribution_at_epoch(epoch).await
     }
 
     /// Get next stake distribution
@@ -475,8 +471,13 @@ impl MultiSigner for MultiSignerImpl {
         &self,
     ) -> Result<ProtocolStakeDistribution, ProtocolError> {
         debug!("Get next stake distribution");
-        self.get_stake_distribution_with_epoch_offset(NEXT_SIGNER_EPOCH_RETRIEVAL_OFFSET)
-            .await
+        let epoch = self
+            .current_beacon
+            .as_ref()
+            .ok_or_else(ProtocolError::UnavailableBeacon)?
+            .epoch
+            .offset_to_next_signer_retrieval_epoch();
+        self.get_stake_distribution_at_epoch(epoch).await
     }
 
     /// Update stake distribution
@@ -490,7 +491,7 @@ impl MultiSigner for MultiSignerImpl {
             .as_ref()
             .ok_or_else(ProtocolError::UnavailableBeacon)?
             .epoch
-            .offset_by(SIGNER_EPOCH_RECORDING_OFFSET)?;
+            .offset_to_recording_epoch();
         let stakes = HashMap::from_iter(stakes.iter().cloned());
         self.stake_store.save_stakes(epoch, stakes).await?;
 
@@ -523,7 +524,7 @@ impl MultiSigner for MultiSignerImpl {
             .as_ref()
             .ok_or_else(ProtocolError::UnavailableBeacon)?
             .epoch
-            .offset_by(SIGNER_EPOCH_RETRIEVAL_OFFSET)?;
+            .offset_to_signer_retrieval_epoch()?;
         let signers = self
             .verification_key_store
             .get_verification_keys(epoch)
@@ -537,16 +538,14 @@ impl MultiSigner for MultiSignerImpl {
         }
     }
 
-    async fn get_signers_with_stake(
-        &self,
-    ) -> Result<Vec<entities::SignerWithStake>, ProtocolError> {
+    async fn get_signers_with_stake(&self) -> Result<Vec<SignerWithStake>, ProtocolError> {
         debug!("Get signers with stake");
         let epoch = self
             .current_beacon
             .as_ref()
             .ok_or_else(ProtocolError::UnavailableBeacon)?
             .epoch
-            .offset_by(SIGNER_EPOCH_RETRIEVAL_OFFSET)?;
+            .offset_to_signer_retrieval_epoch()?;
         let signers = self
             .verification_key_store
             .get_verification_keys(epoch)
@@ -558,7 +557,7 @@ impl MultiSigner for MultiSignerImpl {
             .iter()
             .filter_map(|(party_id, stake)| {
                 signers.get(party_id).map(|signer| {
-                    entities::SignerWithStake::new(
+                    SignerWithStake::new(
                         party_id.to_owned(),
                         signer.verification_key.to_owned(),
                         signer.verification_key_signature.to_owned(),
@@ -571,16 +570,14 @@ impl MultiSigner for MultiSignerImpl {
             .collect())
     }
 
-    async fn get_next_signers_with_stake(
-        &self,
-    ) -> Result<Vec<entities::SignerWithStake>, ProtocolError> {
+    async fn get_next_signers_with_stake(&self) -> Result<Vec<SignerWithStake>, ProtocolError> {
         debug!("Get next signers with stake");
         let epoch = self
             .current_beacon
             .as_ref()
             .ok_or_else(ProtocolError::UnavailableBeacon)?
             .epoch
-            .offset_by(NEXT_SIGNER_EPOCH_RETRIEVAL_OFFSET)?;
+            .offset_to_next_signer_retrieval_epoch();
         let signers = self
             .verification_key_store
             .get_verification_keys(epoch)
@@ -592,7 +589,7 @@ impl MultiSigner for MultiSignerImpl {
             .iter()
             .filter_map(|(party_id, stake)| {
                 signers.get(party_id).map(|signer| {
-                    entities::SignerWithStake::new(
+                    SignerWithStake::new(
                         party_id.to_owned(),
                         signer.verification_key.to_owned(),
                         signer.verification_key_signature.to_owned(),
@@ -724,31 +721,30 @@ impl MultiSigner for MultiSignerImpl {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::store::{SingleSignatureStore, VerificationKeyStore};
-    use crate::ProtocolParametersStore;
-
-    use mithril_common::crypto_helper::tests_setup::*;
-    use mithril_common::fake_data;
-    use mithril_common::store::adapter::MemoryAdapter;
-    use mithril_common::store::StakeStore;
-
-    use std::collections::HashMap;
-    use std::sync::Arc;
+    use crate::{
+        store::{SingleSignatureStore, VerificationKeyStore},
+        ProtocolParametersStore,
+    };
+    use mithril_common::{
+        crypto_helper::tests_setup::*,
+        fake_data,
+        store::{adapter::MemoryAdapter, StakeStore},
+    };
+    use std::{collections::HashMap, sync::Arc};
 
     async fn setup_multi_signer() -> MultiSignerImpl {
         let beacon = fake_data::beacon();
-        let verification_key_store = VerificationKeyStore::new(Box::new(
-            MemoryAdapter::<entities::Epoch, HashMap<entities::PartyId, entities::Signer>>::new(
-                None,
-            )
-            .unwrap(),
-        ), None);
+        let verification_key_store = VerificationKeyStore::new(
+            Box::new(
+                MemoryAdapter::<Epoch, HashMap<entities::PartyId, entities::Signer>>::new(None)
+                    .unwrap(),
+            ),
+            None,
+        );
         let stake_store = StakeStore::new(
             Box::new(
-                MemoryAdapter::<entities::Epoch, HashMap<entities::PartyId, entities::Stake>>::new(
-                    None,
-                )
-                .unwrap(),
+                MemoryAdapter::<Epoch, HashMap<entities::PartyId, entities::Stake>>::new(None)
+                    .unwrap(),
             ),
             None,
         );
@@ -764,16 +760,13 @@ mod tests {
         );
         let protocol_parameters_store = ProtocolParametersStore::new(
             Box::new(
-                MemoryAdapter::<entities::Epoch, entities::ProtocolParameters>::new(Some(vec![
+                MemoryAdapter::<Epoch, entities::ProtocolParameters>::new(Some(vec![
                     (
                         beacon.epoch.offset_to_signer_retrieval_epoch().unwrap(),
                         fake_data::protocol_parameters(),
                     ),
                     (
-                        beacon
-                            .epoch
-                            .offset_to_next_signer_retrieval_epoch()
-                            .unwrap(),
+                        beacon.epoch.offset_to_next_signer_retrieval_epoch(),
                         fake_data::protocol_parameters(),
                     ),
                 ]))
@@ -851,7 +844,7 @@ mod tests {
 
         offset_epoch(
             &mut multi_signer,
-            SIGNER_EPOCH_RECORDING_OFFSET - SIGNER_EPOCH_RETRIEVAL_OFFSET,
+            Epoch::SIGNER_RECORDING_OFFSET as i64 - Epoch::SIGNER_RETRIEVAL_OFFSET,
         )
         .await;
 
@@ -887,7 +880,7 @@ mod tests {
 
         offset_epoch(
             &mut multi_signer,
-            SIGNER_EPOCH_RECORDING_OFFSET - SIGNER_EPOCH_RETRIEVAL_OFFSET,
+            Epoch::SIGNER_RECORDING_OFFSET as i64 - Epoch::SIGNER_RETRIEVAL_OFFSET,
         )
         .await;
 
@@ -943,7 +936,7 @@ mod tests {
         for (signer_with_stake, _, _) in &signers {
             verification_key_store
                 .save_verification_key(
-                    start_epoch.offset_to_recording_epoch().unwrap(),
+                    start_epoch.offset_to_recording_epoch(),
                     signer_with_stake.to_owned().into(),
                 )
                 .await
@@ -952,7 +945,7 @@ mod tests {
 
         offset_epoch(
             &mut multi_signer,
-            SIGNER_EPOCH_RECORDING_OFFSET - SIGNER_EPOCH_RETRIEVAL_OFFSET,
+            Epoch::SIGNER_RECORDING_OFFSET as i64 - Epoch::SIGNER_RETRIEVAL_OFFSET,
         )
         .await;
         // We have to update the current message AFTER we reached the epoch for
diff --git a/mithril-aggregator/src/runtime/runner.rs b/mithril-aggregator/src/runtime/runner.rs
index d58b089a9..b77d441c5 100644
--- a/mithril-aggregator/src/runtime/runner.rs
+++ b/mithril-aggregator/src/runtime/runner.rs
@@ -297,9 +297,7 @@ impl AggregatorRunnerTrait for AggregatorRunner {
         new_beacon: &Beacon,
     ) -> Result<(), RuntimeError> {
         debug!("RUNNER: open signer registration round"; "beacon" => #?new_beacon);
-        let registration_epoch = new_beacon.epoch.offset_to_recording_epoch().map_err(|e| {
-            RuntimeError::General(format!("could not deduce recording epoch: {}", e).into())
-        })?;
+        let registration_epoch = new_beacon.epoch.offset_to_recording_epoch();
 
         let stakes = self
             .dependencies
@@ -716,12 +714,7 @@ pub mod tests {
 
         let saved_stake_distribution = deps
             .stake_store
-            .get_stakes(
-                beacon
-                    .epoch
-                    .offset_to_recording_epoch()
-                    .expect("offset_to_recording_epoch should not fail"),
-            )
+            .get_stakes(beacon.epoch.offset_to_recording_epoch())
             .await
             .unwrap()
             .unwrap_or_else(|| {
@@ -753,7 +746,7 @@ pub mod tests {
         let runner = AggregatorRunner::new(config, deps.clone());
 
         let beacon = fake_data::beacon();
-        let recording_epoch = beacon.epoch.offset_to_recording_epoch().unwrap();
+        let recording_epoch = beacon.epoch.offset_to_recording_epoch();
         let stake_distribution: StakeDistribution =
             HashMap::from([("a".to_string(), 5), ("b".to_string(), 10)]);
 
@@ -961,10 +954,7 @@ pub mod tests {
         runner.update_beacon(&beacon).await.unwrap();
         for epoch in [
             beacon.epoch.offset_to_signer_retrieval_epoch().unwrap(),
-            beacon
-                .epoch
-                .offset_to_next_signer_retrieval_epoch()
-                .unwrap(),
+            beacon.epoch.offset_to_next_signer_retrieval_epoch(),
         ] {
             deps.protocol_parameters_store
                 .save_protocol_parameters(epoch, fake_data::protocol_parameters())
diff --git a/mithril-common/src/entities/epoch.rs b/mithril-common/src/entities/epoch.rs
index db8ee0f6b..acb73839a 100644
--- a/mithril-common/src/entities/epoch.rs
+++ b/mithril-common/src/entities/epoch.rs
@@ -1,11 +1,8 @@
-use crate::{
-    NEXT_SIGNER_EPOCH_RETRIEVAL_OFFSET, SIGNER_EPOCH_RECORDING_OFFSET,
-    SIGNER_EPOCH_RETRIEVAL_OFFSET,
-};
 use serde::{Deserialize, Serialize};
-use std::fmt::Display;
-use std::fmt::Formatter;
-use std::ops::{Add, AddAssign, Sub, SubAssign};
+use std::{
+    fmt::{Display, Formatter},
+    ops::{Add, AddAssign, Sub, SubAssign},
+};
 use thiserror::Error;
 
 /// Epoch represents a Cardano epoch
@@ -15,7 +12,19 @@ use thiserror::Error;
 pub struct Epoch(pub u64);
 
 impl Epoch {
-    /// Computes a new Epoch by applying an epoch offset
+    /// The epoch offset used for signers stake distribution and verification keys retrieval.
+    pub const SIGNER_RETRIEVAL_OFFSET: i64 = -1;
+
+    /// The epoch offset used to retrieve the signers stake distribution and verification keys that's
+    /// currently being signed so it can be used in the next epoch.
+    pub const NEXT_SIGNER_RETRIEVAL_OFFSET: u64 = 0;
+
+    /// The epoch offset used for signers stake distribution and verification keys recording.
+    pub const SIGNER_RECORDING_OFFSET: u64 = 1;
+
+    /// Computes a new Epoch by applying an epoch offset.
+    ///
+    /// Will fail if the computed epoch is negative.
     pub fn offset_by(&self, epoch_offset: i64) -> Result<Self, EpochError> {
         let epoch_new = self.0 as i64 + epoch_offset;
         if epoch_new < 0 {
@@ -24,19 +33,19 @@ impl Epoch {
         Ok(Epoch(epoch_new as u64))
     }
 
-    /// Apply the [SIGNER_EPOCH_RETRIEVAL_OFFSET] to this epoch
+    /// Apply the [Self::SIGNER_EPOCH_RETRIEVAL_OFFSET] to this epoch
     pub fn offset_to_signer_retrieval_epoch(&self) -> Result<Self, EpochError> {
-        self.offset_by(SIGNER_EPOCH_RETRIEVAL_OFFSET)
+        self.offset_by(Self::SIGNER_RETRIEVAL_OFFSET)
     }
 
-    /// Apply the [NEXT_SIGNER_EPOCH_RETRIEVAL_OFFSET] to this epoch
-    pub fn offset_to_next_signer_retrieval_epoch(&self) -> Result<Self, EpochError> {
-        self.offset_by(NEXT_SIGNER_EPOCH_RETRIEVAL_OFFSET)
+    /// Apply the [Self::NEXT_SIGNER_EPOCH_RETRIEVAL_OFFSET] to this epoch
+    pub fn offset_to_next_signer_retrieval_epoch(&self) -> Self {
+        *self + Self::NEXT_SIGNER_RETRIEVAL_OFFSET
     }
 
-    /// Apply the [SIGNER_EPOCH_RECORDING_OFFSET] to this epoch
-    pub fn offset_to_recording_epoch(&self) -> Result<Self, EpochError> {
-        self.offset_by(SIGNER_EPOCH_RECORDING_OFFSET)
+    /// Apply the [Self::SIGNER_EPOCH_RECORDING_OFFSET] to this epoch
+    pub fn offset_to_recording_epoch(&self) -> Self {
+        *self + Self::SIGNER_RECORDING_OFFSET
     }
 }
 
@@ -56,22 +65,6 @@ impl Add<u64> for Epoch {
     }
 }
 
-impl Add<i32> for Epoch {
-    type Output = Self;
-
-    fn add(self, rhs: i32) -> Self::Output {
-        Self(self.0 + rhs as u64)
-    }
-}
-
-impl Add<i64> for Epoch {
-    type Output = Self;
-
-    fn add(self, rhs: i64) -> Self::Output {
-        Self(self.0 + rhs as u64)
-    }
-}
-
 impl AddAssign for Epoch {
     fn add_assign(&mut self, rhs: Self) {
         *self = self.add(rhs);
@@ -84,18 +77,6 @@ impl AddAssign<u64> for Epoch {
     }
 }
 
-impl AddAssign<i32> for Epoch {
-    fn add_assign(&mut self, rhs: i32) {
-        *self = self.add(rhs);
-    }
-}
-
-impl AddAssign<i64> for Epoch {
-    fn add_assign(&mut self, rhs: i64) {
-        *self = self.add(rhs);
-    }
-}
-
 impl Sub for Epoch {
     type Output = Self;
 
@@ -112,22 +93,6 @@ impl Sub<u64> for Epoch {
     }
 }
 
-impl Sub<i32> for Epoch {
-    type Output = Self;
-
-    fn sub(self, rhs: i32) -> Self::Output {
-        Self(self.0 - rhs as u64)
-    }
-}
-
-impl Sub<i64> for Epoch {
-    type Output = Self;
-
-    fn sub(self, rhs: i64) -> Self::Output {
-        Self(self.0 - rhs as u64)
-    }
-}
-
 impl SubAssign for Epoch {
     fn sub_assign(&mut self, rhs: Self) {
         *self = self.sub(rhs);
@@ -140,18 +105,6 @@ impl SubAssign<u64> for Epoch {
     }
 }
 
-impl SubAssign<i32> for Epoch {
-    fn sub_assign(&mut self, rhs: i32) {
-        *self = self.sub(rhs);
-    }
-}
-
-impl SubAssign<i64> for Epoch {
-    fn sub_assign(&mut self, rhs: i64) {
-        *self = self.sub(rhs);
-    }
-}
-
 impl PartialEq<u64> for Epoch {
     fn eq(&self, other: &u64) -> bool {
         self.0.eq(other)
@@ -186,8 +139,6 @@ mod tests {
     fn test_add() {
         assert_eq!(Epoch(4), Epoch(1) + Epoch(3));
         assert_eq!(Epoch(4), Epoch(1) + 3_u64);
-        assert_eq!(Epoch(4), Epoch(1) + 3_i32);
-        assert_eq!(Epoch(4), Epoch(1) + 3_i64);
 
         let mut epoch = Epoch(1);
         epoch += Epoch(3);
@@ -196,22 +147,12 @@ mod tests {
         let mut epoch = Epoch(1);
         epoch += 3_u64;
         assert_eq!(Epoch(4), epoch);
-
-        let mut epoch = Epoch(1);
-        epoch += 3_i32;
-        assert_eq!(Epoch(4), epoch);
-
-        let mut epoch = Epoch(1);
-        epoch += 3_i64;
-        assert_eq!(Epoch(4), epoch);
     }
 
     #[test]
     fn test_sub() {
         assert_eq!(Epoch(8), Epoch(14) - Epoch(6));
         assert_eq!(Epoch(8), Epoch(14) - 6_u64);
-        assert_eq!(Epoch(8), Epoch(14) - 6_i32);
-        assert_eq!(Epoch(8), Epoch(14) - 6_i64);
 
         let mut epoch = Epoch(14);
         epoch -= Epoch(6);
@@ -220,13 +161,5 @@ mod tests {
         let mut epoch = Epoch(14);
         epoch -= 6_u64;
         assert_eq!(Epoch(8), epoch);
-
-        let mut epoch = Epoch(14);
-        epoch -= 6_i32;
-        assert_eq!(Epoch(8), epoch);
-
-        let mut epoch = Epoch(14);
-        epoch -= 6_i64;
-        assert_eq!(Epoch(8), epoch);
     }
 }
diff --git a/mithril-common/src/lib.rs b/mithril-common/src/lib.rs
index 87e77023e..b31c59615 100644
--- a/mithril-common/src/lib.rs
+++ b/mithril-common/src/lib.rs
@@ -27,17 +27,6 @@ pub mod store;
 pub use beacon_provider::{BeaconProvider, BeaconProviderError, BeaconProviderImpl};
 pub use entities::{CardanoNetwork, MagicId};
 
-// TODO: Investigate as why signers can't sign until epoch 3 (in the e2e) when set to -1
-/// The epoch offset used for signers stake distribution and verification keys retrieval.
-pub const SIGNER_EPOCH_RETRIEVAL_OFFSET: i64 = -1;
-
-/// The epoch offset used to retrieve the signers stake distribution and verification keys that's
-/// currently being signed so it can be used in the next epoch.
-pub const NEXT_SIGNER_EPOCH_RETRIEVAL_OFFSET: i64 = 0;
-
-/// The epoch offset used for signers stake distribution and verification keys recording.
-pub const SIGNER_EPOCH_RECORDING_OFFSET: i64 = 1;
-
 /// Mithril API protocol version
 /// this is the same as the one in openapi.yml file.
 /// If you want to update this version to reflect changes in the protocol,
diff --git a/mithril-signer/src/runtime/runner.rs b/mithril-signer/src/runtime/runner.rs
index f920c0184..d16c8ab3a 100644
--- a/mithril-signer/src/runtime/runner.rs
+++ b/mithril-signer/src/runtime/runner.rs
@@ -165,7 +165,7 @@ impl Runner for SignerRunner {
     ) -> Result<(), Box<dyn StdError + Sync + Send>> {
         debug!("RUNNER: register_signer_to_aggregator");
 
-        let epoch_offset_to_recording_epoch = epoch.offset_to_recording_epoch()?;
+        let epoch_offset_to_recording_epoch = epoch.offset_to_recording_epoch();
         let stake_distribution = self
             .services
             .stake_store
@@ -228,7 +228,7 @@ impl Runner for SignerRunner {
             .await?;
         self.services
             .protocol_initializer_store
-            .save_protocol_initializer(epoch.offset_to_recording_epoch()?, protocol_initializer)
+            .save_protocol_initializer(epoch.offset_to_recording_epoch(), protocol_initializer)
             .await?;
 
         Ok(())
@@ -248,7 +248,7 @@ impl Runner for SignerRunner {
             .ok_or_else(|| RuntimeError::NoValueError("current_stake_distribution".to_string()))?;
         self.services
             .stake_store
-            .save_stakes(epoch.offset_to_recording_epoch()?, stake_distribution)
+            .save_stakes(epoch.offset_to_recording_epoch(), stake_distribution)
             .await?;
 
         Ok(())
@@ -353,7 +353,7 @@ impl Runner for SignerRunner {
         message.set_message_part(ProtocolMessagePartKey::SnapshotDigest, digest);
 
         // 2 set the next signers keys and stakes in the message
-        let next_signer_retrieval_epoch = beacon.epoch.offset_to_next_signer_retrieval_epoch()?;
+        let next_signer_retrieval_epoch = beacon.epoch.offset_to_next_signer_retrieval_epoch();
         let next_protocol_initializer = self
             .services
             .protocol_initializer_store
@@ -562,11 +562,7 @@ mod tests {
             .expect("update_stake_distribution should not fail.");
 
         let stake_distribution = stake_store
-            .get_stakes(
-                current_epoch
-                    .offset_to_recording_epoch()
-                    .expect("offset_to_recording_epoch should not fail"),
-            )
+            .get_stakes(current_epoch.offset_to_recording_epoch())
             .await
             .expect("getting stakes from store should not fail")
             .expect("there should be stakes for this epoch");
@@ -588,8 +584,7 @@ mod tests {
             .await
             .unwrap()
             .epoch
-            .offset_to_recording_epoch()
-            .unwrap();
+            .offset_to_recording_epoch();
         let stakes = chain_observer
             .get_current_stake_distribution()
             .await
@@ -624,11 +619,7 @@ mod tests {
             .await
             .is_some());
         let maybe_protocol_initializer = protocol_initializer_store
-            .get_protocol_initializer(
-                epoch
-                    .offset_to_recording_epoch()
-                    .expect("offset_to_recording_epoch should not fail"),
-            )
+            .get_protocol_initializer(epoch.offset_to_recording_epoch())
             .await
             .expect("get_protocol_initializer should not fail");
         assert!(
@@ -711,10 +702,7 @@ mod tests {
         services
             .protocol_initializer_store
             .save_protocol_initializer(
-                current_beacon
-                    .epoch
-                    .offset_to_next_signer_retrieval_epoch()
-                    .expect("offset_to_signer_retrieval_epoch should not fail"),
+                current_beacon.epoch.offset_to_next_signer_retrieval_epoch(),
                 protocol_initializer.clone(),
             )
             .await
diff --git a/mithril-signer/src/runtime/state_machine.rs b/mithril-signer/src/runtime/state_machine.rs
index 96476d88c..50764ff49 100644
--- a/mithril-signer/src/runtime/state_machine.rs
+++ b/mithril-signer/src/runtime/state_machine.rs
@@ -229,9 +229,7 @@ impl StateMachine {
         let current_beacon = &pending_certificate.beacon;
         let (retrieval_epoch, next_retrieval_epoch) = (
             current_beacon.epoch.offset_to_signer_retrieval_epoch()?,
-            current_beacon
-                .epoch
-                .offset_to_next_signer_retrieval_epoch()?,
+            current_beacon.epoch.offset_to_next_signer_retrieval_epoch(),
         );
 
         debug!(


Test patch:
diff --git a/mithril-aggregator/tests/test_extensions/runtime_tester.rs b/mithril-aggregator/tests/test_extensions/runtime_tester.rs
index db23b74b5..1813a7dac 100644
--- a/mithril-aggregator/tests/test_extensions/runtime_tester.rs
+++ b/mithril-aggregator/tests/test_extensions/runtime_tester.rs
@@ -267,20 +267,18 @@ impl RuntimeTester {
             .get_current_beacon()
             .await
             .map_err(|e| format!("Querying the current beacon should not fail: {:?}", e))?;
-        let protocol_parameters =
-            self.deps
-                .protocol_parameters_store
-                .get_protocol_parameters(beacon.epoch.offset_to_recording_epoch().map_err(|e| {
-                    format!("Offsetting to recording epoch should not fail: {:?}", e)
-                })?)
-                .await
-                .map_err(|e| {
-                    format!(
-                        "Querying the recording epoch protocol_parameters should not fail: {:?}",
-                        e
-                    )
-                })?
-                .ok_or("A protocol parameters for the recording epoch should be available")?;
+        let protocol_parameters = self
+            .deps
+            .protocol_parameters_store
+            .get_protocol_parameters(beacon.epoch.offset_to_recording_epoch())
+            .await
+            .map_err(|e| {
+                format!(
+                    "Querying the recording epoch protocol_parameters should not fail: {:?}",
+                    e
+                )
+            })?
+            .ok_or("A protocol parameters for the recording epoch should be available")?;
 
         Ok(setup_signers_from_stake_distribution(
             &signers_with_stake
diff --git a/mithril-signer/tests/test_extensions/certificate_handler.rs b/mithril-signer/tests/test_extensions/certificate_handler.rs
index eae00e9fe..f0ebeebb1 100644
--- a/mithril-signer/tests/test_extensions/certificate_handler.rs
+++ b/mithril-signer/tests/test_extensions/certificate_handler.rs
@@ -81,12 +81,7 @@ impl CertificateHandler for FakeAggregator {
             .cloned()
             .unwrap_or_default();
         certificate_pending.next_signers = store
-            .get(
-                &beacon
-                    .epoch
-                    .offset_to_next_signer_retrieval_epoch()
-                    .unwrap(),
-            )
+            .get(&beacon.epoch.offset_to_next_signer_retrieval_epoch())
             .cloned()
             .unwrap_or_default();
 
@@ -95,12 +90,7 @@ impl CertificateHandler for FakeAggregator {
 
     /// Registers signer with the aggregator
     async fn register_signer(&self, signer: &Signer) -> Result<(), CertificateHandlerError> {
-        let epoch = self
-            .get_beacon()
-            .await?
-            .epoch
-            .offset_to_recording_epoch()
-            .unwrap();
+        let epoch = self.get_beacon().await?.epoch.offset_to_recording_epoch();
 
         let mut store = self.registered_signers.write().await;
         let mut signers = store.get(&epoch).cloned().unwrap_or_default();
@@ -156,7 +146,7 @@ mod tests {
             .await
             .expect("certificate handler should not fail while registering a user");
         let signers = fake_aggregator
-            .get_registered_signers(&Epoch(1).offset_to_recording_epoch().unwrap())
+            .get_registered_signers(&Epoch(1).offset_to_recording_epoch())
             .await
             .expect("we should have a result, None found!");
 
@@ -167,7 +157,7 @@ mod tests {
             .await
             .expect("certificate handler should not fail while registering a user");
         let signers = fake_aggregator
-            .get_registered_signers(&Epoch(1).offset_to_recording_epoch().unwrap())
+            .get_registered_signers(&Epoch(1).offset_to_recording_epoch())
             .await
             .expect("we should have a result, None found!");