Skip to content

Commit

Permalink
Demo Adjustments:
Browse files Browse the repository at this point in the history
* Make the first `mithril-signer` use 'old' http endpoint to send single
  signatures
* Adjusts aggregator logs to make the process more apparent
* Slow down aggregator signature pulling interval so more signatures are
  pulled in batch
* Adjust explorer `Certificates` tab list to show in card the full signed
  entity type instead of the immutable file number
* Fix an error in aggregator when pulling signatures from the simulated
  network
  • Loading branch information
Alenar committed Sep 25, 2024
1 parent ce12b3b commit 7a47c7f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 13 deletions.
2 changes: 1 addition & 1 deletion mithril-aggregator/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ mod handlers {
certifier_service: Arc<dyn CertifierService>,
single_signer_authenticator: Arc<SingleSignatureAuthenticator>,
) -> Result<impl warp::Reply, Infallible> {
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();
Expand Down
11 changes: 9 additions & 2 deletions mithril-aggregator/src/runtime/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?;
Expand Down Expand Up @@ -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);
}
}
Expand Down
49 changes: 45 additions & 4 deletions mithril-aggregator/src/services/signature_consumer.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -56,13 +56,54 @@ impl SignatureConsumer {
let signatures_message: Vec<RegisterSignatureMessage> =
self.unix_socket_client.read(Self::PULL_SIGNATURES_ROUTE)?;

if !signatures_message.is_empty() {
let mut signatures_pools: Vec<String> = signatures_message
.iter()
.map(|s| s.party_id.clone())
.collect();
signatures_pools.dedup();
let mut sign_entity_types: Vec<String> = 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::<CertifierServiceError>() {
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(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand Down Expand Up @@ -79,10 +80,14 @@ export default function CertificatesList(props) {
</ListGroup.Item>
<ListGroup.Item>Epoch: {certificate.beacon.epoch}</ListGroup.Item>
<ListGroup.Item>
Immutable file number: {certificate.beacon.immutable_file_number}
Number of signers: {certificate.metadata.total_signers}
</ListGroup.Item>
<ListGroup.Item>
Number of signers: {certificate.metadata.total_signers}
Signed entity:{" "}
<SignedEntityType
signedEntityType={certificate.signed_entity_type}
table
/>
</ListGroup.Item>
<ListGroup.Item>
Initiated at:{" "}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7a47c7f

Please sign in to comment.