diff --git a/mithril-aggregator/src/beacon_provider.rs b/mithril-aggregator/src/beacon_provider.rs index 97e0a20629a..0acb714aab7 100644 --- a/mithril-aggregator/src/beacon_provider.rs +++ b/mithril-aggregator/src/beacon_provider.rs @@ -116,6 +116,12 @@ impl DumbImmutableFileObserver { } } +impl Default for DumbImmutableFileObserver { + fn default() -> Self { + Self::new() + } +} + #[async_trait] impl ImmutableFileObserver for DumbImmutableFileObserver { async fn get_last_immutable_number(&self) -> Result> { diff --git a/mithril-aggregator/src/multi_signer.rs b/mithril-aggregator/src/multi_signer.rs index 91af51a7ecd..658e60b726f 100644 --- a/mithril-aggregator/src/multi_signer.rs +++ b/mithril-aggregator/src/multi_signer.rs @@ -1,7 +1,7 @@ use async_trait::async_trait; use chrono::prelude::*; use hex::ToHex; -use slog_scope::{debug, warn}; +use slog_scope::debug; use thiserror::Error; use mithril_common::crypto_helper::{ @@ -12,6 +12,7 @@ use mithril_common::crypto_helper::{ }; use mithril_common::entities; use mithril_common::store::stake_store::{StakeStoreError, StakeStorer}; +use mithril_common::SIGNER_EPOCH_RETRIEVAL_OFFSET; use super::beacon_store::BeaconStoreError; use super::dependency::{ @@ -259,7 +260,6 @@ impl MultiSigner for MultiSignerImpl { /// Get stake distribution async fn get_stake_distribution(&self) -> Result { debug!("Get stake distribution"); - #[allow(unused_variables, clippy::identity_op)] let epoch = self .beacon_store .read() @@ -268,11 +268,7 @@ impl MultiSigner for MultiSignerImpl { .await? .ok_or_else(ProtocolError::UnavailableBeacon)? .epoch - - 0; // TODO: Should be -1 or -2 - warn!( - "Epoch computation is not final and needs to be fixed: {}", - epoch - ); + - SIGNER_EPOCH_RETRIEVAL_OFFSET; let signers = self .stake_store .read() @@ -297,7 +293,6 @@ impl MultiSigner for MultiSignerImpl { stakes: &ProtocolStakeDistribution, ) -> Result<(), ProtocolError> { debug!("Update stake distribution to {:?}", stakes); - #[allow(unused_variables)] let epoch = self .beacon_store .read() @@ -325,7 +320,6 @@ impl MultiSigner for MultiSignerImpl { party_id: ProtocolPartyId, ) -> Result, ProtocolError> { debug!("Get signer {}", party_id); - #[allow(clippy::identity_op)] let epoch = self .beacon_store .read() @@ -334,11 +328,7 @@ impl MultiSigner for MultiSignerImpl { .await? .ok_or_else(ProtocolError::UnavailableBeacon)? .epoch - - 0; // TODO: Should be -1 or -2 - warn!( - "Epoch computation is not final and needs to be fixed: {}", - epoch - ); + - SIGNER_EPOCH_RETRIEVAL_OFFSET; let signers = self .verification_key_store .read() @@ -359,7 +349,6 @@ impl MultiSigner for MultiSignerImpl { &self, ) -> Result, ProtocolError> { debug!("Get signers with stake"); - #[allow(clippy::identity_op)] let epoch = self .beacon_store .read() @@ -368,11 +357,7 @@ impl MultiSigner for MultiSignerImpl { .await? .ok_or_else(ProtocolError::UnavailableBeacon)? .epoch - - 0; // TODO: Should be -1 or -2 - warn!( - "Epoch computation is not final and needs to be fixed: {}", - epoch - ); + - SIGNER_EPOCH_RETRIEVAL_OFFSET; let signers = self .verification_key_store .read() @@ -428,10 +413,7 @@ impl MultiSigner for MultiSignerImpl { Some(_) => Err(ProtocolError::ExistingSigner()), None => Ok(()), }; - // TODO: to remove once epoch offset is activated - if result.as_ref().ok().is_some() { - self.clerk = self.create_clerk().await?; - } + result } @@ -447,6 +429,11 @@ impl MultiSigner for MultiSignerImpl { party_id, index ); + // TODO: to remove once epoch offset is activated + if self.clerk.as_ref().is_none() { + self.clerk = self.create_clerk().await?; + } + let message = &self .get_current_message() .await @@ -641,6 +628,14 @@ mod tests { ) } + async fn offset_epoch(multi_signer: &MultiSignerImpl, offset: i64) { + let mut beacon_store = multi_signer.beacon_store.write().await; + let mut beacon = beacon_store.get_current_beacon().await.unwrap().unwrap(); + let epoch_new = beacon.epoch as i64 + offset; + beacon.epoch = epoch_new as u64; + beacon_store.set_current_beacon(beacon).await.unwrap(); + } + #[tokio::test] async fn test_multi_signer_current_message_ok() { let mut multi_signer = setup_multi_signer().await; @@ -689,6 +684,8 @@ mod tests { .await .expect("update stake distribution failed"); + offset_epoch(&multi_signer, SIGNER_EPOCH_RETRIEVAL_OFFSET as i64).await; + let mut stake_distribution = multi_signer .get_stake_distribution() .await @@ -725,6 +722,8 @@ mod tests { .expect("register should have succeeded") } + offset_epoch(&multi_signer, SIGNER_EPOCH_RETRIEVAL_OFFSET as i64).await; + let mut signers_with_stake_all_expected = Vec::new(); for (party_id, stake, verification_key_expected, _, _) in &signers { let verification_key = multi_signer.get_signer(party_id.to_owned()).await; @@ -798,6 +797,8 @@ mod tests { .expect("register should have succeeded") } + offset_epoch(&multi_signer, SIGNER_EPOCH_RETRIEVAL_OFFSET as i64).await; + let mut signatures = Vec::new(); for (party_id, _, _, protocol_signer, _) in &signers { for i in 1..=protocol_parameters.m { diff --git a/mithril-common/src/lib.rs b/mithril-common/src/lib.rs index 4b580d32e0f..442969ff0bf 100644 --- a/mithril-common/src/lib.rs +++ b/mithril-common/src/lib.rs @@ -7,3 +7,6 @@ pub mod fake_data; pub mod store; pub use entities::{CardanoNetwork, MagicId}; + +/// The epoch offset used for signers stake distribution and verification keys retrieval +pub const SIGNER_EPOCH_RETRIEVAL_OFFSET: u64 = 0; // TODO: Reactivate proper epoch offset with deployment of new certificate chain diff --git a/mithril-signer/src/runtime.rs b/mithril-signer/src/runtime.rs index a46ce70cc79..5d079ba5df3 100644 --- a/mithril-signer/src/runtime.rs +++ b/mithril-signer/src/runtime.rs @@ -1,4 +1,4 @@ -use slog_scope::{error, info, warn}; +use slog_scope::{error, info}; use std::collections::HashMap; use std::sync::Arc; use std::time::Duration; @@ -11,6 +11,7 @@ use mithril_common::crypto_helper::{key_encode_hex, Bytes}; use mithril_common::digesters::{Digester, DigesterError}; use mithril_common::entities::{self, Beacon, CertificatePending, Epoch, PartyId, SignerWithStake}; use mithril_common::store::stake_store::{StakeStore, StakeStoreError, StakeStorer}; +use mithril_common::SIGNER_EPOCH_RETRIEVAL_OFFSET; use super::certificate_handler::CertificateHandler; use super::single_signer::SingleSigner; @@ -201,12 +202,7 @@ impl Runtime { .iter() .map(|signer| (signer.party_id.to_owned(), signer.verification_key.as_str())) .collect::>(); - #[allow(clippy::identity_op)] - let epoch = pending_certificate.beacon.epoch - 0; // TODO: Should be -1 or -2 - warn!( - "Epoch computation is not final and needs to be fixed: {}", - epoch - ); + let epoch = pending_certificate.beacon.epoch - SIGNER_EPOCH_RETRIEVAL_OFFSET; let stake_store = self.stake_store.read().await; let stake_distribution = stake_store .get_stakes(epoch)