Skip to content

Commit 3d75d3f

Browse files
authored
Merge pull request #1896 from input-output-hk/jpraynaud/1895-fix-epoch-cardano-stake-distribution
Fix: Cardano stake distribution certification epoch discrepancy
2 parents b3faff0 + 3ffc3ec commit 3d75d3f

File tree

7 files changed

+22
-13
lines changed

7 files changed

+22
-13
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.5.54"
3+
version = "0.5.55"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/artifact_builder/cardano_stake_distribution.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl ArtifactBuilder<Epoch, CardanoStakeDistribution> for CardanoStakeDistributi
3333
) -> StdResult<CardanoStakeDistribution> {
3434
let stake_distribution = self
3535
.stake_distribution_retriever
36-
.retrieve(epoch.offset_to_recording_epoch())
36+
.retrieve(epoch.offset_to_cardano_stake_distribution_snapshot_epoch())
3737
.await?
3838
.ok_or_else(|| anyhow!("No stake distribution found for epoch '{}'", epoch))?;
3939

@@ -60,7 +60,7 @@ mod tests {
6060
#[tokio::test]
6161
async fn compute_artifact_returns_valid_artifact_and_retrieve_with_epoch_offset() {
6262
let epoch = Epoch(1);
63-
let epoch_to_retrieve = Epoch(2);
63+
let epoch_to_retrieve = Epoch(3);
6464
let certificate = fake_data::certificate("whatever".to_string());
6565
let stake_distribution = StakeDistribution::from([("pool-123".to_string(), 123)]);
6666
let stake_distribution_clone = stake_distribution.clone();
@@ -81,7 +81,7 @@ mod tests {
8181
#[tokio::test]
8282
async fn compute_artifact_returns_error_if_no_stakes_found_for_epoch() {
8383
let epoch = Epoch(1);
84-
let epoch_to_retrieve = Epoch(2);
84+
let epoch_to_retrieve = Epoch(3);
8585
let certificate = fake_data::certificate("whatever".to_string());
8686
let mut mock_storer = MockStakeDistributionRetrieverImpl::new();
8787
mock_storer

mithril-aggregator/tests/cardano_stake_distribution_verify_stakes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ async fn cardano_stake_distribution_verify_stakes() {
7373
)
7474
})
7575
.collect::<Vec<_>>();
76-
let updated_stake_distribution: StakeDistribution = signers_with_updated_stake_distribution
77-
.iter()
78-
.map(|s| (s.party_id.clone(), s.stake))
79-
.collect();
8076
tester
8177
.chain_observer
8278
.set_signers(signers_with_updated_stake_distribution)
@@ -121,6 +117,10 @@ async fn cardano_stake_distribution_verify_stakes() {
121117
)
122118
})
123119
.collect::<Vec<_>>();
120+
let updated_stake_distribution: StakeDistribution = signers_with_updated_stake_distribution
121+
.iter()
122+
.map(|s| (s.party_id.clone(), s.stake))
123+
.collect();
124124
tester
125125
.chain_observer
126126
.set_signers(signers_with_updated_stake_distribution)

mithril-common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-common"
3-
version = "0.4.44"
3+
version = "0.4.45"
44
description = "Common types, interfaces, and utilities for Mithril nodes."
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-common/src/entities/epoch.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ impl Epoch {
3434
/// at which the signer can send single signatures.
3535
pub const SIGNER_SIGNING_OFFSET: u64 = 2;
3636

37+
/// The epoch offset used to retrieve the epoch at the end of which the snapshot of the stake distribution
38+
/// was taken by the Cardano node and labeled as 'Mark' snapshot during the following epoch.
39+
pub const CARDANO_STAKE_DISTRIBUTION_SNAPSHOT_OFFSET: u64 = 2;
40+
3741
/// Computes a new Epoch by applying an epoch offset.
3842
///
3943
/// Will fail if the computed epoch is negative.
@@ -70,6 +74,11 @@ impl Epoch {
7074
*self + Self::SIGNER_SIGNING_OFFSET
7175
}
7276

77+
/// Apply the [cardano stake distribution snapshot epoch offset][Self::CARDANO_STAKE_DISTRIBUTION_SNAPSHOT_OFFSET] to this epoch
78+
pub fn offset_to_cardano_stake_distribution_snapshot_epoch(&self) -> Self {
79+
*self + Self::CARDANO_STAKE_DISTRIBUTION_SNAPSHOT_OFFSET
80+
}
81+
7382
/// Computes the next Epoch
7483
pub fn next(&self) -> Self {
7584
*self + 1

mithril-common/src/signable_builder/cardano_stake_distribution.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl SignableBuilder<Epoch> for CardanoStakeDistributionSignableBuilder {
6666
async fn compute_protocol_message(&self, epoch: Epoch) -> StdResult<ProtocolMessage> {
6767
let pools_with_stake = self
6868
.cardano_stake_distribution_retriever
69-
.retrieve(epoch.offset_to_recording_epoch())
69+
.retrieve(epoch.offset_to_cardano_stake_distribution_snapshot_epoch())
7070
.await?.ok_or(anyhow!(
7171
"CardanoStakeDistributionSignableBuilder could not find the stake distribution for epoch: '{epoch}'"
7272
))?;
@@ -161,7 +161,7 @@ mod tests {
161161
#[tokio::test]
162162
async fn compute_protocol_message_returns_signable_and_retrieve_with_epoch_offset() {
163163
let epoch = Epoch(1);
164-
let epoch_to_retrieve = Epoch(2);
164+
let epoch_to_retrieve = Epoch(3);
165165
let stake_distribution = StakeDistribution::from([("pool-123".to_string(), 100)]);
166166
let stake_distribution_clone = stake_distribution.clone();
167167

0 commit comments

Comments
 (0)