diff --git a/Cargo.lock b/Cargo.lock index 7a6d8dbc7e9..fc05e5f8203 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2001,7 +2001,7 @@ dependencies = [ [[package]] name = "mithril-aggregator" -version = "0.2.9" +version = "0.2.10" dependencies = [ "async-trait", "chrono", diff --git a/mithril-aggregator/Cargo.toml b/mithril-aggregator/Cargo.toml index 0a6251b9e08..22069b29fc2 100644 --- a/mithril-aggregator/Cargo.toml +++ b/mithril-aggregator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-aggregator" -version = "0.2.9" +version = "0.2.10" description = "A Mithril Aggregator server" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-aggregator/src/runtime/runner.rs b/mithril-aggregator/src/runtime/runner.rs index df1c794286a..a87576a979a 100644 --- a/mithril-aggregator/src/runtime/runner.rs +++ b/mithril-aggregator/src/runtime/runner.rs @@ -76,10 +76,13 @@ pub trait AggregatorRunnerTrait: Sync + Send { /// Read the stake distribution from the blockchain and store it. async fn update_stake_distribution(&self, new_beacon: &Beacon) -> Result<(), RuntimeError>; - /// Open the signer registration round for an epoch. + /// Open the signer registration round of an epoch. async fn open_signer_registration_round(&self, new_beacon: &Beacon) -> Result<(), RuntimeError>; + /// Close the signer registration round of an epoch. + async fn close_signer_registration_round(&self) -> Result<(), RuntimeError>; + /// Update the multisigner with the protocol parameters from configuration. async fn update_protocol_parameters_in_multisigner( &self, @@ -314,6 +317,17 @@ impl AggregatorRunnerTrait for AggregatorRunner { Ok(()) } + async fn close_signer_registration_round(&self) -> Result<(), RuntimeError> { + debug!("RUNNER: close signer registration round"); + + self.dependencies + .signer_registration_round_opener + .close_registration_round() + .await?; + + Ok(()) + } + async fn update_protocol_parameters_in_multisigner( &self, new_beacon: &Beacon, @@ -770,6 +784,32 @@ pub mod tests { ); } + #[tokio::test] + async fn test_close_signer_registration_round() { + let (mut deps, config) = initialize_dependencies().await; + let signer_registration_round_opener = Arc::new(MithrilSignerRegisterer::new( + deps.chain_observer.clone(), + deps.verification_key_store.clone(), + )); + deps.signer_registration_round_opener = signer_registration_round_opener.clone(); + let deps = Arc::new(deps); + let runner = AggregatorRunner::new(config, deps.clone()); + + let beacon = fake_data::beacon(); + runner + .open_signer_registration_round(&beacon) + .await + .expect("opening signer registration should not return an error"); + + runner + .close_signer_registration_round() + .await + .expect("closing signer registration should not return an error"); + + let saved_current_round = signer_registration_round_opener.get_current_round().await; + assert!(saved_current_round.is_none()); + } + #[tokio::test] async fn test_update_protocol_parameters_in_multisigner() { let (deps, config) = initialize_dependencies().await; diff --git a/mithril-aggregator/src/runtime/state_machine.rs b/mithril-aggregator/src/runtime/state_machine.rs index 92e12125e51..613aeb78af8 100644 --- a/mithril-aggregator/src/runtime/state_machine.rs +++ b/mithril-aggregator/src/runtime/state_machine.rs @@ -221,6 +221,7 @@ impl AggregatorRuntime { if maybe_current_beacon.is_none() || maybe_current_beacon.unwrap().epoch < new_beacon.epoch { + self.runner.close_signer_registration_round().await?; self.runner.update_stake_distribution(&new_beacon).await?; self.runner .open_signer_registration_round(&new_beacon) @@ -365,6 +366,10 @@ mod tests { .with(predicate::eq(fake_data::beacon())) .once() .returning(|_| Ok(())); + runner + .expect_close_signer_registration_round() + .once() + .returning(|| Ok(())); runner .expect_open_signer_registration_round() .once() @@ -408,6 +413,10 @@ mod tests { .with(predicate::eq(fake_data::beacon())) .once() .returning(|_| Ok(())); + runner + .expect_close_signer_registration_round() + .once() + .returning(|| Ok(())); runner .expect_open_signer_registration_round() .once() diff --git a/mithril-aggregator/src/signer_registerer.rs b/mithril-aggregator/src/signer_registerer.rs index 3310601482a..de1ac273ebb 100644 --- a/mithril-aggregator/src/signer_registerer.rs +++ b/mithril-aggregator/src/signer_registerer.rs @@ -79,6 +79,9 @@ pub trait SignerRegistrationRoundOpener: Sync + Send { registration_epoch: Epoch, stake_distribution: StakeDistribution, ) -> Result<(), SignerRegistrationError>; + + /// Close a signer registration round + async fn close_registration_round(&self) -> Result<(), SignerRegistrationError>; } /// Implementation of a [SignerRegisterer] @@ -127,6 +130,13 @@ impl SignerRegistrationRoundOpener for MithrilSignerRegisterer { Ok(()) } + + async fn close_registration_round(&self) -> Result<(), SignerRegistrationError> { + let mut current_round = self.current_round.write().await; + *current_round = None; + + Ok(()) + } } #[async_trait]