|
| 1 | +use anyhow::anyhow; |
| 2 | +use async_trait::async_trait; |
1 | 3 | #[cfg(test)] |
2 | 4 | use std::collections::HashMap; |
3 | | - |
4 | | -use async_trait::async_trait; |
5 | | -use mithril_common::StdResult; |
6 | 5 | #[cfg(test)] |
7 | 6 | use tokio::sync::RwLock; |
8 | 7 |
|
| 8 | +use mithril_common::StdResult; |
9 | 9 | use mithril_common::entities::{Epoch, ProtocolParameters}; |
| 10 | +use mithril_protocol_config::model::MithrilNetworkConfiguration; |
10 | 11 |
|
11 | 12 | use crate::{entities::AggregatorEpochSettings, services::EpochPruningTask}; |
12 | 13 |
|
@@ -43,14 +44,37 @@ pub trait EpochSettingsStorer: |
43 | 44 | /// call and the epoch service call. |
44 | 45 | async fn handle_discrepancies_at_startup( |
45 | 46 | &self, |
46 | | - current_epoch: Epoch, |
47 | | - epoch_settings_configuration: &AggregatorEpochSettings, |
| 47 | + network_configuration: &MithrilNetworkConfiguration, |
48 | 48 | ) -> StdResult<()> { |
49 | | - for epoch_offset in 0..=3 { |
50 | | - let epoch = current_epoch + epoch_offset; |
| 49 | + for (epoch, epoch_configuration) in [ |
| 50 | + ( |
| 51 | + network_configuration.epoch.offset_to_signer_retrieval_epoch()?, |
| 52 | + &network_configuration.configuration_for_aggregation, |
| 53 | + ), |
| 54 | + ( |
| 55 | + network_configuration.epoch, |
| 56 | + &network_configuration.configuration_for_next_aggregation, |
| 57 | + ), |
| 58 | + ( |
| 59 | + network_configuration.epoch.offset_to_recording_epoch(), |
| 60 | + &network_configuration.configuration_for_registration, |
| 61 | + ), |
| 62 | + ] { |
51 | 63 | if self.get_epoch_settings(epoch).await?.is_none() { |
52 | | - self.save_epoch_settings(epoch, epoch_settings_configuration.clone()) |
53 | | - .await?; |
| 64 | + self.save_epoch_settings( |
| 65 | + epoch, |
| 66 | + AggregatorEpochSettings { |
| 67 | + protocol_parameters: epoch_configuration.protocol_parameters.clone(), |
| 68 | + cardano_transactions_signing_config: epoch_configuration |
| 69 | + .signed_entity_types_config |
| 70 | + .cardano_transactions |
| 71 | + .clone() |
| 72 | + .ok_or(anyhow!( |
| 73 | + "missing cardano transactions signing config for epoch {epoch}" |
| 74 | + ))?, |
| 75 | + }, |
| 76 | + ) |
| 77 | + .await?; |
54 | 78 | } |
55 | 79 | } |
56 | 80 |
|
@@ -116,7 +140,8 @@ impl EpochPruningTask for FakeEpochSettingsStorer { |
116 | 140 |
|
117 | 141 | #[cfg(test)] |
118 | 142 | mod tests { |
119 | | - use mithril_common::entities::CardanoTransactionsSigningConfig; |
| 143 | + use std::collections::BTreeSet; |
| 144 | + |
120 | 145 | use mithril_common::test::double::Dummy; |
121 | 146 |
|
122 | 147 | use super::*; |
@@ -178,40 +203,43 @@ mod tests { |
178 | 203 | #[tokio::test] |
179 | 204 | async fn test_handle_discrepancies_at_startup_should_complete_at_least_four_epochs() { |
180 | 205 | let epoch_settings = AggregatorEpochSettings::dummy(); |
181 | | - let epoch_settings_new = AggregatorEpochSettings { |
182 | | - protocol_parameters: ProtocolParameters { |
183 | | - k: epoch_settings.protocol_parameters.k + 1, |
184 | | - ..epoch_settings.protocol_parameters |
185 | | - }, |
186 | | - cardano_transactions_signing_config: CardanoTransactionsSigningConfig { |
187 | | - step: epoch_settings.cardano_transactions_signing_config.step + 1, |
188 | | - ..epoch_settings.cardano_transactions_signing_config |
189 | | - }, |
190 | | - }; |
191 | | - let epoch = Epoch(1); |
192 | | - let store = FakeEpochSettingsStorer::new(vec![ |
193 | | - (epoch, epoch_settings.clone()), |
194 | | - (epoch + 1, epoch_settings.clone()), |
195 | | - ]); |
| 206 | + let mut aggregation_epoch_settings = epoch_settings.clone(); |
| 207 | + aggregation_epoch_settings.protocol_parameters.k += 15; |
196 | 208 |
|
| 209 | + let mut next_aggregation_epoch_settings = epoch_settings.clone(); |
| 210 | + next_aggregation_epoch_settings.protocol_parameters.k += 26; |
| 211 | + |
| 212 | + let mut registration_epoch_settings = epoch_settings.clone(); |
| 213 | + registration_epoch_settings.protocol_parameters.k += 37; |
| 214 | + |
| 215 | + let epoch = Epoch(5); |
| 216 | + let store = FakeEpochSettingsStorer::new(vec![]); |
197 | 217 | store |
198 | | - .handle_discrepancies_at_startup(epoch, &epoch_settings_new) |
| 218 | + .handle_discrepancies_at_startup(&MithrilNetworkConfiguration { |
| 219 | + epoch, |
| 220 | + configuration_for_aggregation: aggregation_epoch_settings |
| 221 | + .clone() |
| 222 | + .into_network_configuration_for_epoch(BTreeSet::new()), |
| 223 | + configuration_for_next_aggregation: next_aggregation_epoch_settings |
| 224 | + .clone() |
| 225 | + .into_network_configuration_for_epoch(BTreeSet::new()), |
| 226 | + configuration_for_registration: registration_epoch_settings |
| 227 | + .clone() |
| 228 | + .into_network_configuration_for_epoch(BTreeSet::new()), |
| 229 | + }) |
199 | 230 | .await |
200 | 231 | .unwrap(); |
201 | 232 |
|
| 233 | + let epoch_settings_stored = store.get_epoch_settings(epoch - 1).await.unwrap(); |
| 234 | + assert_eq!(Some(aggregation_epoch_settings), epoch_settings_stored); |
| 235 | + |
202 | 236 | let epoch_settings_stored = store.get_epoch_settings(epoch).await.unwrap(); |
203 | | - assert_eq!(Some(epoch_settings.clone()), epoch_settings_stored); |
| 237 | + assert_eq!(Some(next_aggregation_epoch_settings), epoch_settings_stored); |
204 | 238 |
|
205 | 239 | let epoch_settings_stored = store.get_epoch_settings(epoch + 1).await.unwrap(); |
206 | | - assert_eq!(Some(epoch_settings.clone()), epoch_settings_stored); |
| 240 | + assert_eq!(Some(registration_epoch_settings), epoch_settings_stored); |
207 | 241 |
|
208 | 242 | let epoch_settings_stored = store.get_epoch_settings(epoch + 2).await.unwrap(); |
209 | | - assert_eq!(Some(epoch_settings_new.clone()), epoch_settings_stored); |
210 | | - |
211 | | - let epoch_settings_stored = store.get_epoch_settings(epoch + 3).await.unwrap(); |
212 | | - assert_eq!(Some(epoch_settings_new.clone()), epoch_settings_stored); |
213 | | - |
214 | | - let epoch_settings_stored = store.get_epoch_settings(epoch + 4).await.unwrap(); |
215 | 243 | assert!(epoch_settings_stored.is_none()); |
216 | 244 | } |
217 | 245 | } |
0 commit comments