diff --git a/mithril-aggregator/src/dependency_injection/builder.rs b/mithril-aggregator/src/dependency_injection/builder.rs index 65c7da97bef..ac888e04d14 100644 --- a/mithril-aggregator/src/dependency_injection/builder.rs +++ b/mithril-aggregator/src/dependency_injection/builder.rs @@ -1401,7 +1401,7 @@ impl DependenciesBuilder { Some(socket_path) => { let consumer = SignatureConsumer::new( socket_path, - Duration::from_millis(10), + Duration::from_millis(50), self.get_certifier_service().await?, &self.get_logger()?, ); diff --git a/mithril-aggregator/src/http_server/routes/signatures_routes.rs b/mithril-aggregator/src/http_server/routes/signatures_routes.rs index 029f2f758af..73ba80f1f4e 100644 --- a/mithril-aggregator/src/http_server/routes/signatures_routes.rs +++ b/mithril-aggregator/src/http_server/routes/signatures_routes.rs @@ -46,7 +46,12 @@ mod handlers { certifier_service: Arc, single_signer_authenticator: Arc, ) -> Result { - debug!("⇄ HTTP SERVER: register_signatures/{:?}", message); + // debug!("⇄ HTTP SERVER: register_signatures/{:?}", message); + debug!( + "⇄ HTTP SERVER: register_signatures"; + "party_id" => &message.party_id, + "signed_entity_type" => ?message.signed_entity_type, + ); trace!("⇄ HTTP SERVER: register_signatures"; "complete_message" => #?message ); let signed_entity_type = message.signed_entity_type.clone(); diff --git a/mithril-aggregator/src/runtime/state_machine.rs b/mithril-aggregator/src/runtime/state_machine.rs index aa59ab076e0..565e17acbec 100644 --- a/mithril-aggregator/src/runtime/state_machine.rs +++ b/mithril-aggregator/src/runtime/state_machine.rs @@ -201,7 +201,10 @@ impl AggregatorRuntime { .with_context(|| "AggregatorRuntime can not get the current open message")? { // transition READY > SIGNING - info!("→ transitioning to SIGNING"); + info!( + "→ transitioning to SIGNING"; + "signed_entity_type" => ?open_message.signed_entity_type + ); let new_state = self .transition_from_ready_to_signing(last_time_point.clone(), open_message.clone()) .await.with_context(|| format!("AggregatorRuntime can not perform a transition from READY state to SIGNING with entity_type: '{:?}'", open_message.signed_entity_type))?; @@ -258,10 +261,14 @@ impl AggregatorRuntime { self.state = AggregatorState::Ready(new_state); } else { // SIGNING > READY + let signed_entity_type = state.open_message.signed_entity_type.clone(); let new_state = self .transition_from_signing_to_ready_multisignature(state) .await?; - info!("→ a multi-signature has been created, build an artifact & a certificate and transitioning back to READY"); + info!( + "→ a multi-signature has been created, build an artifact & a certificate and transitioning back to READY"; + "signed_entity_type" => ?signed_entity_type + ); self.state = AggregatorState::Ready(new_state); } } diff --git a/mithril-aggregator/src/services/signature_consumer.rs b/mithril-aggregator/src/services/signature_consumer.rs index 9fc1b3268ac..e3ac98e69dc 100644 --- a/mithril-aggregator/src/services/signature_consumer.rs +++ b/mithril-aggregator/src/services/signature_consumer.rs @@ -1,4 +1,4 @@ -use slog::{error, trace, Logger}; +use slog::{debug, error, trace, Logger}; use std::path::Path; use std::sync::Arc; use std::time::Duration; @@ -8,7 +8,7 @@ use mithril_common::socket_client::HttpUnixSocketClient; use mithril_common::StdResult; use crate::message_adapters::FromRegisterSingleSignatureAdapter; -use crate::services::CertifierService; +use crate::services::{CertifierService, CertifierServiceError}; /// A service that consumes signatures from a network through a Unix socket. pub struct SignatureConsumer { @@ -56,13 +56,54 @@ impl SignatureConsumer { let signatures_message: Vec = self.unix_socket_client.read(Self::PULL_SIGNATURES_ROUTE)?; + if !signatures_message.is_empty() { + let mut signatures_pools: Vec = signatures_message + .iter() + .map(|s| s.party_id.clone()) + .collect(); + signatures_pools.dedup(); + let mut sign_entity_types: Vec = signatures_message + .iter() + .map(|s| s.signed_entity_type.to_string()) + .collect(); + sign_entity_types.dedup(); + debug!( + self.logger, + "{} signatures pulled from the decentralized network", + signatures_message.len(); + "pools_ids" => signatures_pools.as_slice().join(", "), + "signed_entity_types" => sign_entity_types.as_slice().join(", "), + ); + } + for signature_message in signatures_message { let signed_entity_type = signature_message.signed_entity_type.clone(); let signature = FromRegisterSingleSignatureAdapter::try_adapt(signature_message)?; - self.certifier_service + if let Err(error) = self + .certifier_service .register_single_signature(&signed_entity_type, &signature) - .await?; + .await + { + match error.downcast_ref::() { + Some(CertifierServiceError::Expired(se)) + | Some(CertifierServiceError::AlreadyCertified(se)) => { + trace!( + self.logger, + "Certificate already created for '{se:?}', no need to register this signature"; + "party_id" => &signature.party_id, + ); + // Removing this line may trigger the following error: + // "UNIQUE constraint failed: signed_entity.signed_entity_id (code 19)" + // 12: database::repository::SignedEntityStore::store_signed_entity::... + // 13: services::SignedEntityService::create_artifact::... + break; + } + _ => { + anyhow::bail!(error); + } + }; + } } Ok(()) diff --git a/mithril-explorer/src/components/Artifacts/CertificatesList/index.js b/mithril-explorer/src/components/Artifacts/CertificatesList/index.js index 9a9a5a9650d..ec319d63ed1 100644 --- a/mithril-explorer/src/components/Artifacts/CertificatesList/index.js +++ b/mithril-explorer/src/components/Artifacts/CertificatesList/index.js @@ -5,6 +5,7 @@ import CertificateModal from "#/CertificateModal"; import RawJsonButton from "#/RawJsonButton"; import LocalDateTime from "#/LocalDateTime"; import { selectedAggregator } from "@/store/settingsSlice"; +import SignedEntityType from "#/SignedEntityType"; export default function CertificatesList(props) { const [certificates, setCertificates] = useState([]); @@ -79,10 +80,14 @@ export default function CertificatesList(props) { Epoch: {certificate.beacon.epoch} - Immutable file number: {certificate.beacon.immutable_file_number} + Number of signers: {certificate.metadata.total_signers} - Number of signers: {certificate.metadata.total_signers} + Signed entity:{" "} + Initiated at:{" "} diff --git a/mithril-test-lab/mithril-end-to-end/src/mithril/infrastructure.rs b/mithril-test-lab/mithril-end-to-end/src/mithril/infrastructure.rs index a8b06ae5e45..5cc1929149d 100644 --- a/mithril-test-lab/mithril-end-to-end/src/mithril/infrastructure.rs +++ b/mithril-test-lab/mithril-end-to-end/src/mithril/infrastructure.rs @@ -280,14 +280,18 @@ impl MithrilInfrastructure { } else { aggregator_endpoint.clone() }; + // First signer will use "old" aggregator http endpoint to send single signatures. + let signature_network_node_socket = if index > 0 { + signature_network_nodes.get(index).map(|s| s.socket_path()) + } else { + None + }; let mut signer = Signer::new(&SignerConfig { aggregator_endpoint, pool_node, cardano_cli_path: &config.devnet.cardano_cli_path(), - signature_network_node_socket: signature_network_nodes - .get(index) - .map(|s| s.socket_path()), + signature_network_node_socket, work_dir: &config.work_dir, bin_dir: &config.bin_dir, mithril_run_interval: config.mithril_run_interval,