Skip to content

Commit f8dbd4e

Browse files
authored
Merge pull request #805 from input-output-hk/jpraynaud/804-fix-stake-distribution-compute-optimization
Avoid compute stake distribution multiple times per epoch
2 parents 459d644 + 53c0a00 commit f8dbd4e

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
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.2.29"
3+
version = "0.2.30"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/runtime/runner.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::snapshotter::OngoingSnapshot;
2121
use crate::store::SingleSignatureStorer;
2222
use crate::CertificateCreator;
2323
use crate::MithrilCertificateCreator;
24+
use crate::RuntimeError;
2425
use crate::{DependencyManager, ProtocolError, SnapshotError};
2526

2627
#[cfg(test)]
@@ -307,6 +308,29 @@ impl AggregatorRunnerTrait for AggregatorRunner {
307308
new_beacon: &Beacon,
308309
) -> Result<(), Box<dyn StdError + Sync + Send>> {
309310
debug!("RUNNER: update stake distribution"; "beacon" => #?new_beacon);
311+
let exists_stake_distribution = !self
312+
.dependencies
313+
.stake_store
314+
.get_stakes(
315+
self.dependencies
316+
.multi_signer
317+
.read()
318+
.await
319+
.get_current_beacon()
320+
.await
321+
.ok_or_else(|| {
322+
RuntimeError::keep_state("Current beacon is not available", None)
323+
})?
324+
.epoch
325+
.offset_to_recording_epoch(),
326+
)
327+
.await?
328+
.unwrap_or_default()
329+
.is_empty();
330+
if exists_stake_distribution {
331+
return Ok(());
332+
}
333+
310334
let stake_distribution = self
311335
.dependencies
312336
.chain_observer

mithril-signer/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-signer"
3-
version = "0.2.20"
3+
version = "0.2.21"
44
description = "A Mithril Signer"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-signer/src/runtime/runner.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,17 @@ impl Runner for SignerRunner {
240240
) -> Result<(), Box<dyn StdError + Sync + Send>> {
241241
debug!("RUNNER: update_stake_distribution");
242242

243+
let exists_stake_distribution = !self
244+
.services
245+
.stake_store
246+
.get_stakes(epoch.offset_to_recording_epoch())
247+
.await?
248+
.unwrap_or_default()
249+
.is_empty();
250+
if exists_stake_distribution {
251+
return Ok(());
252+
}
253+
243254
let stake_distribution = self
244255
.services
245256
.chain_observer

0 commit comments

Comments
 (0)