Skip to content

Commit a6a8576

Browse files
committed
Fix Stake Distribution aggregator
Avoid recomputing the stake distribution multiple times per epoch.
1 parent 655bac9 commit a6a8576

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

0 commit comments

Comments
 (0)