Skip to content

Commit

Permalink
Merge pull request #885 from input-output-hk/jpraynaud/851-signable-a…
Browse files Browse the repository at this point in the history
…rtifact-builder-mithril-stake-distribution-signer

Mithril Stake Distribution Signable builder
  • Loading branch information
jpraynaud authored May 3, 2023
2 parents cc9660f + c03101c commit e7c947f
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 102 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.3.10"
version = "0.3.11"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl ArtifactBuilder<Epoch, MithrilStakeDistribution> for MithrilStakeDistributi
) -> StdResult<MithrilStakeDistribution> {
let multi_signer = self.multi_signer.read().await;
Ok(MithrilStakeDistribution::new(
multi_signer.get_signers_with_stake().await?,
multi_signer.get_next_signers_with_stake().await?,
))
}
}
Expand All @@ -68,7 +68,7 @@ mod tests {
let certificate = fake_data::certificate("cert-123".to_string());
let mut mock_multi_signer = MockMultiSigner::new();
mock_multi_signer
.expect_get_signers_with_stake()
.expect_get_next_signers_with_stake()
.return_once(move || Ok(signers_with_stake_clone));
let mithril_stake_distribution_artifact_builder =
MithrilStakeDistributionArtifactBuilder::new(Arc::new(RwLock::new(mock_multi_signer)));
Expand Down
10 changes: 5 additions & 5 deletions mithril-aggregator/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use mithril_common::{
adapters::{EraReaderAdapterBuilder, EraReaderDummyAdapter},
EraChecker, EraMarker, EraReader, EraReaderAdapter, SupportedEra,
},
signable_builder::CardanoImmutableFilesFullSignableBuilder,
signable_builder::{
CardanoImmutableFilesFullSignableBuilder, MithrilStakeDistributionSignableBuilder,
},
store::adapter::{MemoryAdapter, SQLiteAdapter, StoreAdapter},
BeaconProvider, BeaconProviderImpl,
};
Expand Down Expand Up @@ -46,7 +48,7 @@ use crate::{
},
event_store::{EventMessage, EventStore, TransmitterService},
http_server::routes::router,
signable_builder::{MithrilStakeDistributionSignableBuilder, SignableBuilderService},
signable_builder::SignableBuilderService,
signer_registerer::SignerRecorder,
stake_distribution_service::{MithrilStakeDistributionService, StakeDistributionService},
ticker_service::{MithrilTickerService, TickerService},
Expand Down Expand Up @@ -876,9 +878,7 @@ impl DependenciesBuilder {
}

async fn build_signable_builder_service(&mut self) -> Result<Arc<SignableBuilderService>> {
let multi_signer = self.get_multi_signer().await?;
let mithril_stake_distribution_builder =
MithrilStakeDistributionSignableBuilder::new(multi_signer);
let mithril_stake_distribution_builder = MithrilStakeDistributionSignableBuilder::default();
let immutable_signable_builder = CardanoImmutableFilesFullSignableBuilder::new(
self.get_immutable_digester().await?,
self.get_logger().await?,
Expand Down
4 changes: 1 addition & 3 deletions mithril-aggregator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ pub use crate::configuration::{
Configuration, DefaultConfiguration, ExecutionEnvironment, SnapshotUploaderType,
};
pub use crate::multi_signer::{MultiSigner, MultiSignerImpl, ProtocolError};
pub use crate::signable_builder::{
MithrilStakeDistributionSignableBuilder, SignableBuilderService,
};
pub use crate::signable_builder::SignableBuilderService;
pub use crate::snapshot_stores::{LocalSnapshotStore, SnapshotStore};
pub use command_args::MainOpts;
pub use dependency::DependencyManager;
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions mithril-aggregator/src/signable_builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! The module used for building signables
mod mithril_stake_distribution;
mod signable_builder_service;

pub use mithril_stake_distribution::*;
pub use signable_builder_service::*;
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ use std::sync::Arc;

use mithril_common::{
entities::SignedEntityType,
signable_builder::{CardanoImmutableFilesFullSignableBuilder, Signable, SignableBuilder},
signable_builder::{
CardanoImmutableFilesFullSignableBuilder, MithrilStakeDistributionSignableBuilder,
Signable, SignableBuilder,
},
StdResult,
};

use super::MithrilStakeDistributionSignableBuilder;

/// SignableBuilder Service
pub struct SignableBuilderService {
mithril_stake_distribution_builder: MithrilStakeDistributionSignableBuilder,
Expand Down
2 changes: 1 addition & 1 deletion mithril-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-common"
version = "0.2.46"
version = "0.2.47"
authors = { workspace = true }
edition = { workspace = true }
documentation = { workspace = true }
Expand Down
36 changes: 36 additions & 0 deletions mithril-common/src/signable_builder/mithril_stake_distribution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use async_trait::async_trait;

use crate::{
entities::{Epoch, ProtocolMessage},
signable_builder::SignableBuilder,
StdResult,
};

/// A [MithrilStakeDistributionSignableBuilder] builder
#[derive(Default)]
pub struct MithrilStakeDistributionSignableBuilder {}

#[async_trait]
impl SignableBuilder<Epoch, ProtocolMessage> for MithrilStakeDistributionSignableBuilder {
// We just need to return an empty protocol message as the next AVK will be appended by the signing engine automatically
async fn compute_signable(&self, _beacon: Epoch) -> StdResult<ProtocolMessage> {
Ok(ProtocolMessage::new())
}
}

#[cfg(test)]
mod tests {
use super::*;

#[tokio::test]
async fn test_compute_signable() {
let mithril_stake_distribution_signable_builder =
MithrilStakeDistributionSignableBuilder::default();
let signable = mithril_stake_distribution_signable_builder
.compute_signable(Epoch(1))
.await
.unwrap();
let signable_expected = ProtocolMessage::new();
assert_eq!(signable_expected, signable);
}
}
2 changes: 2 additions & 0 deletions mithril-common/src/signable_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
mod cardano_immutable_full_signable_builder;
mod dummy_signable;
mod interface;
mod mithril_stake_distribution;

pub use cardano_immutable_full_signable_builder::*;
pub use dummy_signable::*;
pub use interface::*;
pub use mithril_stake_distribution::*;
2 changes: 1 addition & 1 deletion mithril-signer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-signer"
version = "0.2.37"
version = "0.2.38"
description = "A Mithril Signer"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
14 changes: 10 additions & 4 deletions mithril-signer/src/runtime/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ mod tests {
adapters::{EraReaderAdapterType, EraReaderBootstrapAdapter},
EraChecker, EraReader,
},
signable_builder::CardanoImmutableFilesFullSignableBuilder,
signable_builder::{
CardanoImmutableFilesFullSignableBuilder, MithrilStakeDistributionSignableBuilder,
},
store::{
adapter::{DumbStoreAdapter, MemoryAdapter},
StakeStore, StakeStorer,
Expand Down Expand Up @@ -534,10 +536,14 @@ mod tests {

let api_version_provider = Arc::new(APIVersionProvider::new(era_checker.clone()));
let digester = Arc::new(DumbImmutableDigester::new(DIGESTER_RESULT, true));
let signable_builder =
let immutable_signable_builder =
CardanoImmutableFilesFullSignableBuilder::new(digester.clone(), slog_scope::logger());

let signable_builder_service = Arc::new(SignableBuilderService::new(signable_builder));
let mithril_stake_distribution_signable_builder =
MithrilStakeDistributionSignableBuilder::default();
let signable_builder_service = Arc::new(SignableBuilderService::new(
immutable_signable_builder,
mithril_stake_distribution_signable_builder,
));

SignerServices {
stake_store: Arc::new(StakeStore::new(Box::new(DumbStoreAdapter::new()), None)),
Expand Down
14 changes: 10 additions & 4 deletions mithril-signer/src/runtime/signer_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use mithril_common::{
},
digesters::{CardanoImmutableDigester, ImmutableDigester, ImmutableFileSystemObserver},
era::{EraChecker, EraReader},
signable_builder::CardanoImmutableFilesFullSignableBuilder,
signable_builder::{
CardanoImmutableFilesFullSignableBuilder, MithrilStakeDistributionSignableBuilder,
},
store::{adapter::SQLiteAdapter, StakeStore},
BeaconProvider, BeaconProviderImpl, StdError,
};
Expand Down Expand Up @@ -201,10 +203,14 @@ impl<'a> ServiceBuilder for ProductionServiceBuilder<'a> {
api_version_provider.clone(),
));

let dummy_signable_builder =
let immutable_snapshot_builder =
CardanoImmutableFilesFullSignableBuilder::new(digester.clone(), slog_scope::logger());
let signable_builder_service =
Arc::new(SignableBuilderService::new(dummy_signable_builder));
let mithril_stake_distribution_signable_builder =
MithrilStakeDistributionSignableBuilder::default();
let signable_builder_service = Arc::new(SignableBuilderService::new(
immutable_snapshot_builder,
mithril_stake_distribution_signable_builder,
));

let services = SignerServices {
beacon_provider,
Expand Down
18 changes: 15 additions & 3 deletions mithril-signer/src/signable_builder/signable_builder_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@ use std::sync::Arc;

use mithril_common::{
entities::SignedEntityType,
signable_builder::{CardanoImmutableFilesFullSignableBuilder, Signable, SignableBuilder},
signable_builder::{
CardanoImmutableFilesFullSignableBuilder, MithrilStakeDistributionSignableBuilder,
Signable, SignableBuilder,
},
StdResult,
};

/// SignableBuilder Service
// TODO: temporary implementation
pub struct SignableBuilderService {
immutable_signable_builder: CardanoImmutableFilesFullSignableBuilder,
mithril_stake_distribution_builder: MithrilStakeDistributionSignableBuilder,
}

impl SignableBuilderService {
/// SignableBuilderService factory
pub fn new(immutable_signable_builder: CardanoImmutableFilesFullSignableBuilder) -> Self {
pub fn new(
immutable_signable_builder: CardanoImmutableFilesFullSignableBuilder,
mithril_stake_distribution_builder: MithrilStakeDistributionSignableBuilder,
) -> Self {
Self {
immutable_signable_builder,
mithril_stake_distribution_builder,
}
}
}
Expand All @@ -33,6 +40,11 @@ impl SignableBuilderService {
.compute_signable(beacon)
.await?,
),
SignedEntityType::MithrilStakeDistribution(epoch) => Arc::new(
self.mithril_stake_distribution_builder
.compute_signable(epoch)
.await?,
),
_ => todo!(),
};

Expand Down
11 changes: 9 additions & 2 deletions mithril-signer/tests/test_extensions/state_machine_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use mithril_common::era::{
EraChecker, EraReader,
};
use mithril_common::era::{EraMarker, SupportedEra};
use mithril_common::signable_builder::CardanoImmutableFilesFullSignableBuilder;
use mithril_common::signable_builder::{
CardanoImmutableFilesFullSignableBuilder, MithrilStakeDistributionSignableBuilder,
};
use mithril_common::BeaconProvider;
use slog::Drain;
use slog_scope::debug;
Expand Down Expand Up @@ -152,7 +154,12 @@ impl StateMachineTester {

let signable_builder =
CardanoImmutableFilesFullSignableBuilder::new(digester.clone(), slog_scope::logger());
let signable_builder_service = Arc::new(SignableBuilderService::new(signable_builder));
let mithril_stake_distribution_signable_builder =
MithrilStakeDistributionSignableBuilder::default();
let signable_builder_service = Arc::new(SignableBuilderService::new(
signable_builder,
mithril_stake_distribution_signable_builder,
));

let services = SignerServices {
certificate_handler: certificate_handler.clone(),
Expand Down

0 comments on commit e7c947f

Please sign in to comment.