Skip to content

Commit 55827c1

Browse files
committed
feat(signer): wire 'SignaturePublisherDmq' in DI
1 parent 54a819e commit 55827c1

File tree

5 files changed

+70
-35
lines changed

5 files changed

+70
-35
lines changed

mithril-signer/src/configuration.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ pub struct Configuration {
3535
#[example = "`cardano-cli`"]
3636
pub cardano_cli_path: PathBuf,
3737

38-
/// Path of the socket used by the Cardano CLI tool
39-
/// to communicate with the Cardano node
40-
#[example = "`/tmp/cardano.sock`"]
38+
/// Path of the socket opened by the Cardano node
39+
#[example = "`/ipc/node.socket`"]
4140
pub cardano_node_socket_path: PathBuf,
4241

42+
/// Path of the socket opened by the DMQ node
43+
#[example = "`/ipc/dmq.socket`"]
44+
pub dmq_node_socket_path: Option<PathBuf>,
45+
4346
/// Cardano network
4447
#[example = "`testnet` or `mainnet` or `devnet`"]
4548
pub network: String,
@@ -150,6 +153,7 @@ impl Configuration {
150153
relay_endpoint: None,
151154
cardano_cli_path: PathBuf::new(),
152155
cardano_node_socket_path: PathBuf::new(),
156+
dmq_node_socket_path: None,
153157
db_directory: PathBuf::new(),
154158
network: "devnet".to_string(),
155159
network_magic: Some(42),

mithril-signer/src/dependency_injection/builder.rs

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::sync::Arc;
33
use std::time::Duration;
44

55
use anyhow::{anyhow, Context};
6+
use mithril_dmq_node::{DmqMessageBuilder, DmqPublisherPallas};
67
use slog::Logger;
78
use tokio::sync::{Mutex, RwLock};
89

@@ -19,14 +20,16 @@ use mithril_cardano_node_internal_database::{
1920
signable_builder::{CardanoDatabaseSignableBuilder, CardanoImmutableFilesFullSignableBuilder},
2021
ImmutableFileObserver, ImmutableFileSystemObserver,
2122
};
22-
use mithril_common::api_version::APIVersionProvider;
23-
use mithril_common::crypto_helper::{OpCert, ProtocolPartyId, SerDeShelleyFileFormat};
23+
use mithril_common::crypto_helper::{
24+
KesSigner, KesSignerStandard, OpCert, ProtocolPartyId, SerDeShelleyFileFormat,
25+
};
2426
use mithril_common::signable_builder::{
2527
CardanoStakeDistributionSignableBuilder, CardanoTransactionsSignableBuilder,
2628
MithrilSignableBuilderService, MithrilStakeDistributionSignableBuilder,
2729
SignableBuilderServiceDependencies,
2830
};
2931
use mithril_common::StdResult;
32+
use mithril_common::{api_version::APIVersionProvider, messages::RegisterSignatureMessageDmq};
3033

3134
use mithril_era::{EraChecker, EraReader};
3235
use mithril_signed_entity_lock::SignedEntityTypeLock;
@@ -37,10 +40,6 @@ use mithril_persistence::database::repository::CardanoTransactionRepository;
3740
use mithril_persistence::database::{ApplicationNodeType, SqlMigration};
3841
use mithril_persistence::sqlite::{ConnectionBuilder, SqliteConnection, SqliteConnectionPool};
3942

40-
use crate::database::repository::{
41-
ProtocolInitializerRepository, SignedBeaconRepository, StakePoolStore,
42-
};
43-
use crate::dependency_injection::SignerDependencyContainer;
4443
use crate::services::{
4544
AggregatorHTTPClient, CardanoTransactionsImporter,
4645
CardanoTransactionsPreloaderActivationSigner, MithrilEpochService, MithrilSingleSigner,
@@ -50,6 +49,11 @@ use crate::services::{
5049
TransactionsImporterWithPruner, TransactionsImporterWithVacuum,
5150
};
5251
use crate::store::MKTreeStoreSqlite;
52+
use crate::{
53+
database::repository::{ProtocolInitializerRepository, SignedBeaconRepository, StakePoolStore},
54+
services::SignaturePublisher,
55+
};
56+
use crate::{dependency_injection::SignerDependencyContainer, services::SignaturePublisherDmq};
5357
use crate::{
5458
Configuration, MetricsService, HTTP_REQUEST_TIMEOUT_DURATION, SQLITE_FILE,
5559
SQLITE_FILE_CARDANO_TRANSACTION,
@@ -390,10 +394,46 @@ impl<'a> DependenciesBuilder<'a> {
390394
self.root_logger(),
391395
));
392396

397+
let kes_signer = match (
398+
&self.config.kes_secret_key_path,
399+
&self.config.operational_certificate_path,
400+
) {
401+
(Some(kes_secret_key_path), Some(operational_certificate_path)) => {
402+
Some(Arc::new(KesSignerStandard::new(
403+
kes_secret_key_path.clone(),
404+
operational_certificate_path.clone(),
405+
)) as Arc<dyn KesSigner>)
406+
}
407+
(Some(_), None) | (None, Some(_)) => {
408+
return Err(anyhow!(
409+
"kes_secret_key and operational_certificate are both mandatory".to_string(),
410+
))
411+
}
412+
_ => None,
413+
};
414+
415+
let cardano_network = &self.config.get_network()?;
416+
393417
let signature_publisher = {
394-
// Temporary no-op publisher before a DMQ-based implementation is available.
395418
let first_publisher = SignaturePublisherRetrier::new(
396-
Arc::new(SignaturePublisherNoop {}),
419+
if let Some(dmq_node_socket_path) = &self.config.dmq_node_socket_path {
420+
let dmq_message_builder = DmqMessageBuilder::new_with_default_ttl(
421+
kes_signer
422+
.clone()
423+
.ok_or(anyhow!("A KES signer is mandatory to sign DMQ messages"))?,
424+
chain_observer.clone(),
425+
);
426+
Arc::new(SignaturePublisherDmq::new(Arc::new(DmqPublisherPallas::<
427+
RegisterSignatureMessageDmq,
428+
>::new(
429+
dmq_node_socket_path.to_owned(),
430+
*cardano_network,
431+
dmq_message_builder,
432+
self.root_logger(),
433+
)))) as Arc<dyn SignaturePublisher>
434+
} else {
435+
Arc::new(SignaturePublisherNoop) as Arc<dyn SignaturePublisher>
436+
},
397437
SignaturePublishRetryPolicy::never(),
398438
);
399439

@@ -442,6 +482,7 @@ impl<'a> DependenciesBuilder<'a> {
442482
upkeep_service,
443483
epoch_service,
444484
certifier,
485+
kes_signer,
445486
};
446487

447488
Ok(services)

mithril-signer/src/dependency_injection/containers.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use mithril_common::crypto_helper::KesSigner;
12
use std::sync::Arc;
23
use tokio::sync::RwLock;
34

@@ -81,4 +82,7 @@ pub struct SignerDependencyContainer {
8182

8283
/// Certifier service
8384
pub certifier: Arc<dyn CertifierService>,
85+
86+
/// Kes signer service
87+
pub kes_signer: Option<Arc<dyn KesSigner>>,
8488
}

mithril-signer/src/runtime/runner.rs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
use std::sync::Arc;
2-
31
use anyhow::Context;
42
use async_trait::async_trait;
53
use slog::{debug, warn, Logger};
64
use thiserror::Error;
75
use tokio::sync::RwLockReadGuard;
86

9-
use mithril_common::crypto_helper::{
10-
KesPeriod, KesSigner, KesSignerStandard, OpCert, ProtocolOpCert, SerDeShelleyFileFormat,
11-
};
7+
use mithril_common::crypto_helper::{KesPeriod, OpCert, ProtocolOpCert, SerDeShelleyFileFormat};
128
use mithril_common::entities::{
139
Epoch, PartyId, ProtocolMessage, SignedEntityType, Signer, TimePoint,
1410
};
@@ -186,28 +182,10 @@ impl Runner for SignerRunner {
186182
),
187183
None => None,
188184
};
189-
let kes_signer = match (
190-
&self.config.kes_secret_key_path,
191-
&self.config.operational_certificate_path,
192-
) {
193-
(Some(kes_secret_key_path), Some(operational_certificate_path)) => {
194-
Some(Arc::new(KesSignerStandard::new(
195-
kes_secret_key_path.clone(),
196-
operational_certificate_path.clone(),
197-
)) as Arc<dyn KesSigner>)
198-
}
199-
(Some(_), None) | (None, Some(_)) => {
200-
return Err(RunnerError::NoValueError(
201-
"kes_secret_key and operational_certificate are both mandatory".to_string(),
202-
)
203-
.into())
204-
}
205-
_ => None,
206-
};
207185
let protocol_initializer = MithrilProtocolInitializerBuilder::build(
208186
stake,
209187
&protocol_parameters,
210-
kes_signer,
188+
self.services.kes_signer.clone(),
211189
kes_period,
212190
)?;
213191
let signer = Signer::new(
@@ -528,6 +506,7 @@ mod tests {
528506
aggregator_client.clone(),
529507
logger.clone(),
530508
));
509+
let kes_signer = None;
531510

532511
SignerDependencyContainer {
533512
stake_store,
@@ -547,6 +526,7 @@ mod tests {
547526
upkeep_service,
548527
epoch_service,
549528
certifier,
529+
kes_signer,
550530
}
551531
}
552532

mithril-signer/tests/test_extensions/state_machine_tester.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use mithril_cardano_node_internal_database::{
2727
};
2828
use mithril_common::{
2929
api_version::APIVersionProvider,
30+
crypto_helper::{KesSigner, KesSignerStandard},
3031
entities::{
3132
BlockNumber, CardanoTransactionsSigningConfig, ChainPoint, Epoch, SignedEntityConfig,
3233
SignedEntityType, SignedEntityTypeDiscriminants, SignerWithStake, SlotNumber, SupportedEra,
@@ -287,6 +288,10 @@ impl StateMachineTester {
287288
certificate_handler.clone(),
288289
logger.clone(),
289290
));
291+
let kes_signer = Some(Arc::new(KesSignerStandard::new(
292+
config.kes_secret_key_path.clone().unwrap(),
293+
config.operational_certificate_path.clone().unwrap(),
294+
)) as Arc<dyn KesSigner>);
290295

291296
let services = SignerDependencyContainer {
292297
certificate_handler: certificate_handler.clone(),
@@ -306,6 +311,7 @@ impl StateMachineTester {
306311
upkeep_service,
307312
epoch_service,
308313
certifier,
314+
kes_signer,
309315
};
310316
// set up stake distribution
311317
chain_observer

0 commit comments

Comments
 (0)