-
Notifications
You must be signed in to change notification settings - Fork 52
Implement signable and artifact builders for Cardano Stake Distribution #1847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dlachaume
merged 20 commits into
main
from
dlachaume/1832/implement-signable-artifact-builders-for-cardano-stake-distribution
Jul 29, 2024
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6c99591
feat: extend `ProtocolMessagePartKey` with `CardanoStakeDistributionE…
dlachaume fb246c0
feat: implement `CardanoStakeDistributionSignableBuilder`
dlachaume fefbc89
feat: handle `CardanoStakeDistribution` signed entity type in `Signab…
dlachaume 8d230f3
feat: implement `StakeDistributionRetriever` for `StakeStore` in the …
dlachaume e044bc2
feat: implement `StakeDistributionRetriever` for `StakePoolStore` in …
dlachaume 7550e0c
feat: create `CardanoStakeDistribution` entity
dlachaume 6aa2545
feat: implement `CardanoStakeDistributionArtifactBuilder`
dlachaume c72c20e
feat: implement `compute_hash` for `CardanoStakeDistribution`
dlachaume 5876347
feat: wire `CardanoStakeDistributionArtifactBuilder` with Signed enti…
dlachaume d3d52f9
test: activate `CardanoStakeDistribution` in E2E
dlachaume 375cc29
feat: `StakeDistributionRetriever` as dependency for `CardanoStakeDis…
dlachaume cd6edb5
fix: typo and clarify formulations
dlachaume ab5a2ad
feat: introduced new type representing a stake distribution entry tha…
dlachaume 89f3407
feat: apply epoch offset when retrieving the stake distribution for S…
dlachaume 0071868
feat: apply epoch offset when creating a `SignedEntityType` from a `T…
dlachaume 37b9d4d
feat: create dedicated function to get the epoch when the signed enti…
dlachaume 7a98039
docs: reference the feature in the `CHANGELOG`
dlachaume 54f5e3e
fix: minor changes from PR review comments
dlachaume f8b1f0e
feat: move epoch offset responsibility when retrieving a stake distri…
dlachaume 4829708
chore: bump crates versions
dlachaume File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
96 changes: 96 additions & 0 deletions
96
mithril-aggregator/src/artifact_builder/cardano_stake_distribution.rs
This file contains hidden or 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,96 @@ | ||
| use anyhow::anyhow; | ||
| use async_trait::async_trait; | ||
| use std::sync::Arc; | ||
|
|
||
| use mithril_common::{ | ||
| entities::{CardanoStakeDistribution, Certificate, Epoch}, | ||
| signable_builder::StakeDistributionRetriever, | ||
| StdResult, | ||
| }; | ||
|
|
||
| use crate::ArtifactBuilder; | ||
|
|
||
| /// A [CardanoStakeDistributionArtifact] builder | ||
| pub struct CardanoStakeDistributionArtifactBuilder { | ||
| stake_distribution_retriever: Arc<dyn StakeDistributionRetriever>, | ||
| } | ||
|
|
||
| impl CardanoStakeDistributionArtifactBuilder { | ||
| /// CardanoStakeDistribution artifact builder factory | ||
| pub fn new(stake_distribution_retriever: Arc<dyn StakeDistributionRetriever>) -> Self { | ||
| Self { | ||
| stake_distribution_retriever, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl ArtifactBuilder<Epoch, CardanoStakeDistribution> for CardanoStakeDistributionArtifactBuilder { | ||
| async fn compute_artifact( | ||
| &self, | ||
| epoch: Epoch, | ||
| _certificate: &Certificate, | ||
| ) -> StdResult<CardanoStakeDistribution> { | ||
| let stake_distribution = self | ||
| .stake_distribution_retriever | ||
| .retrieve(epoch) | ||
| .await? | ||
| .ok_or_else(|| anyhow!("No stake distribution found for epoch '{}'", epoch))?; | ||
|
|
||
| Ok(CardanoStakeDistribution::new(epoch, stake_distribution)) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use mithril_common::{entities::StakeDistribution, test_utils::fake_data}; | ||
| use mockall::{mock, predicate::eq}; | ||
|
|
||
| use super::*; | ||
|
|
||
| mock! { | ||
| pub StakeDistributionRetrieverImpl {} | ||
|
|
||
| #[async_trait] | ||
| impl StakeDistributionRetriever for StakeDistributionRetrieverImpl { | ||
| async fn retrieve(&self, epoch: Epoch) -> StdResult<Option<StakeDistribution>>; | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn compute_artifact_returns_valid_artifact_if_stakes_stored_for_epoch() { | ||
| let epoch = Epoch(1); | ||
| let certificate = fake_data::certificate("whatever".to_string()); | ||
| let stake_distribution = StakeDistribution::from([("pool-123".to_string(), 123)]); | ||
| let stake_distribution_clone = stake_distribution.clone(); | ||
| let mut mock_storer = MockStakeDistributionRetrieverImpl::new(); | ||
| mock_storer | ||
| .expect_retrieve() | ||
| .with(eq(epoch)) | ||
| .return_once(move |_| Ok(Some(stake_distribution_clone))); | ||
| let builder = CardanoStakeDistributionArtifactBuilder::new(Arc::new(mock_storer)); | ||
|
|
||
| let cardano_stake_distribution = | ||
| builder.compute_artifact(epoch, &certificate).await.unwrap(); | ||
|
|
||
| let expected = CardanoStakeDistribution::new(epoch, stake_distribution); | ||
| assert_eq!(cardano_stake_distribution, expected); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn compute_artifact_returns_error_if_no_stakes_found_for_epoch() { | ||
| let epoch = Epoch(1); | ||
| let certificate = fake_data::certificate("whatever".to_string()); | ||
| let mut mock_storer = MockStakeDistributionRetrieverImpl::new(); | ||
| mock_storer | ||
| .expect_retrieve() | ||
| .with(eq(epoch)) | ||
| .return_once(move |_| Ok(None)); | ||
| let builder = CardanoStakeDistributionArtifactBuilder::new(Arc::new(mock_storer)); | ||
|
|
||
| builder | ||
| .compute_artifact(epoch, &certificate) | ||
| .await | ||
| .expect_err("Should return error"); | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| //! The module used for building artifact | ||
| mod cardano_immutable_files_full; | ||
| mod cardano_stake_distribution; | ||
| mod cardano_transactions; | ||
| mod interface; | ||
| mod mithril_stake_distribution; | ||
|
|
||
| pub use cardano_immutable_files_full::*; | ||
| pub use cardano_stake_distribution::*; | ||
| pub use cardano_transactions::*; | ||
| pub use interface::*; | ||
| pub use mithril_stake_distribution::*; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.