diff --git a/CHANGELOG.md b/CHANGELOG.md index 90fdb24d1d2..344bc3215ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ As a minor extension, we have adopted a slightly different versioning convention | ----- | ------- | | N/A | `-` | -## Mithril Distribution [2543] - 2025-11-03 +## Mithril Distribution [2543.1] - 2025-11-03 - Client library, CLI and WASM: - **DEPRECATED**: The `with_aggregator_client` and `new` functions have been deprecated in the `ClientBuilder` struct of the library. @@ -60,10 +60,10 @@ As a minor extension, we have adopted a slightly different versioning convention | mithril-client-cli | `0.12.33` | | mithril-client-wasm | `0.9.7` | | mithril-common | `0.6.25` | -| mithril-signer | `0.2.273` | +| mithril-signer | `0.2.276` | | mithril-stm | `0.5.5` | -## Mithril Distribution [2537] - 2025-09-17 +## Mithril Distribution [2537.0] - 2025-09-17 - Client library, CLI and WASM: - Support for stable `cardano_database_v2` backend in the `mithril-client` library. diff --git a/Cargo.lock b/Cargo.lock index 1976d4de071..44ef9f6de80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4102,7 +4102,7 @@ dependencies = [ [[package]] name = "mithril-signer" -version = "0.2.275" +version = "0.2.277" dependencies = [ "anyhow", "async-trait", diff --git a/mithril-signer/Cargo.toml b/mithril-signer/Cargo.toml index c5ce5384531..6ba33861235 100644 --- a/mithril-signer/Cargo.toml +++ b/mithril-signer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-signer" -version = "0.2.275" +version = "0.2.277" description = "A Mithril Signer" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-signer/src/runtime/runner.rs b/mithril-signer/src/runtime/runner.rs index 11b3bc560ea..a3390e9332e 100644 --- a/mithril-signer/src/runtime/runner.rs +++ b/mithril-signer/src/runtime/runner.rs @@ -207,37 +207,41 @@ impl Runner for SignerRunner { ), None => None, }; - let protocol_initializer = MithrilProtocolInitializerBuilder::build( - stake, - &protocol_parameters, - self.services.kes_signer.clone(), - kes_period, - )?; - self.services - .protocol_initializer_store - .save_protocol_initializer(epoch_offset_to_recording_epoch, protocol_initializer) - .await?; let protocol_initializer = self .services .protocol_initializer_store .get_protocol_initializer(epoch_offset_to_recording_epoch) - .await?.ok_or(RunnerError::NoValueError( - format!("no protocol_initializer available in store for epoch {epoch_offset_to_recording_epoch}"), - )).with_context( + .await + .with_context( || "register_signer_to_aggregator can not retrieve protocol initializer from store", )?; - let signer = Signer::new( - self.services.single_signer.get_party_id(), - protocol_initializer.verification_key().into(), - protocol_initializer.verification_key_signature(), - protocol_operational_certificate, - kes_period, - ); - self.services - .certificate_handler - .register_signer(epoch_offset_to_recording_epoch, &signer) - .await?; + + if protocol_initializer.is_none() { + let protocol_initializer = MithrilProtocolInitializerBuilder::build( + stake, + &protocol_parameters, + self.services.kes_signer.clone(), + kes_period, + )?; + + let signer = Signer::new( + self.services.single_signer.get_party_id(), + protocol_initializer.verification_key().into(), + protocol_initializer.verification_key_signature(), + protocol_operational_certificate, + kes_period, + ); + self.services + .certificate_handler + .register_signer(epoch_offset_to_recording_epoch, &signer) + .await?; + + self.services + .protocol_initializer_store + .save_protocol_initializer(epoch_offset_to_recording_epoch, protocol_initializer) + .await?; + } Ok(()) } @@ -705,6 +709,9 @@ mod tests { "A protocol initializer should have been registered at the 'Recording' epoch" ); + let total_registered_signers = certificate_handler.get_total_registered_signers().await; + assert_eq!(1, total_registered_signers); + runner .register_signer_to_aggregator() .await @@ -725,6 +732,9 @@ mod tests { serde_json::to_string(&last_registered_signer_second_registration).unwrap(), "The signer registration should be the same and should have been registered twice" ); + + let total_registered_signers = certificate_handler.get_total_registered_signers().await; + assert_eq!(1, total_registered_signers); } #[tokio::test] diff --git a/mithril-signer/src/services/aggregator_client.rs b/mithril-signer/src/services/aggregator_client.rs index 9a77a0db619..01578642511 100644 --- a/mithril-signer/src/services/aggregator_client.rs +++ b/mithril-signer/src/services/aggregator_client.rs @@ -99,6 +99,7 @@ pub(crate) mod dumb { epoch_settings: RwLock>, last_registered_signer: RwLock>, aggregator_features: RwLock, + total_registered_signers: RwLock, } impl DumbAggregatorClient { @@ -106,6 +107,11 @@ pub(crate) mod dumb { pub async fn get_last_registered_signer(&self) -> Option { self.last_registered_signer.read().await.clone() } + + /// Return the total number of signers that called with the `register` method. + pub async fn get_total_registered_signers(&self) -> u32 { + *self.total_registered_signers.read().await + } } impl Default for DumbAggregatorClient { @@ -114,6 +120,7 @@ pub(crate) mod dumb { epoch_settings: RwLock::new(Some(SignerEpochSettings::dummy())), last_registered_signer: RwLock::new(None), aggregator_features: RwLock::new(AggregatorFeaturesMessage::dummy()), + total_registered_signers: RwLock::new(0), } } } @@ -132,6 +139,9 @@ pub(crate) mod dumb { let signer = signer.clone(); *last_registered_signer = Some(signer); + let mut total_registered_signers = self.total_registered_signers.write().await; + *total_registered_signers += 1; + Ok(()) }