-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1942 from input-output-hk/jpraynaud/1941-refactor…
…-signable-builder Refactor: signable builder services compute full protocol message
- Loading branch information
Showing
22 changed files
with
513 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod signable_seed_builder; | ||
|
||
pub use signable_seed_builder::*; |
79 changes: 79 additions & 0 deletions
79
mithril-aggregator/src/services/signable_builder/signable_seed_builder.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//! ## AggregatorSignableSeedBuilder | ||
//! | ||
//! This service is responsible for computing the seed protocol message | ||
//! that is used by the [SignableBuilder] to compute the final protocol message. | ||
//! | ||
use anyhow::Context; | ||
use async_trait::async_trait; | ||
use std::sync::Arc; | ||
use tokio::sync::RwLock; | ||
|
||
use mithril_common::{ | ||
entities::ProtocolMessagePartValue, signable_builder::SignableSeedBuilder, StdResult, | ||
}; | ||
|
||
use crate::services::EpochService; | ||
|
||
/// SignableSeedBuilder aggregator implementation | ||
pub struct AggregatorSignableSeedBuilder { | ||
epoch_service: Arc<RwLock<dyn EpochService>>, | ||
} | ||
|
||
impl AggregatorSignableSeedBuilder { | ||
/// AggregatorSignableSeedBuilder factory | ||
pub fn new(epoch_service: Arc<RwLock<dyn EpochService>>) -> Self { | ||
Self { epoch_service } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl SignableSeedBuilder for AggregatorSignableSeedBuilder { | ||
async fn compute_next_aggregate_verification_key_protocol_message_part_value( | ||
&self, | ||
) -> StdResult<ProtocolMessagePartValue> { | ||
let epoch_service = self.epoch_service.read().await; | ||
let next_aggregate_verification_key = (*epoch_service) | ||
.next_aggregate_verification_key()? | ||
.to_json_hex() | ||
.with_context(|| "convert next avk to json hex failure")? | ||
.to_string(); | ||
|
||
Ok(next_aggregate_verification_key) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use mithril_common::{entities::Epoch, test_utils::MithrilFixtureBuilder}; | ||
|
||
use crate::services::FakeEpochService; | ||
|
||
use super::*; | ||
|
||
#[tokio::test] | ||
async fn test_compute_next_aggregate_verification_key_protocol_message_value() { | ||
let epoch = Epoch(5); | ||
let fixture = MithrilFixtureBuilder::default().with_signers(5).build(); | ||
let next_fixture = MithrilFixtureBuilder::default().with_signers(4).build(); | ||
let expected_next_aggregate_verification_key = next_fixture.compute_and_encode_avk(); | ||
let epoch_service = Arc::new(RwLock::new(FakeEpochService::with_data( | ||
epoch, | ||
&fixture.protocol_parameters(), | ||
&next_fixture.protocol_parameters(), | ||
&next_fixture.protocol_parameters(), | ||
&fixture.signers_with_stake(), | ||
&next_fixture.signers_with_stake(), | ||
))); | ||
let signable_seed_builder = AggregatorSignableSeedBuilder::new(epoch_service); | ||
|
||
let next_aggregate_verification_key = signable_seed_builder | ||
.compute_next_aggregate_verification_key_protocol_message_part_value() | ||
.await | ||
.unwrap(); | ||
|
||
assert_eq!( | ||
next_aggregate_verification_key, | ||
expected_next_aggregate_verification_key | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.