Skip to content

Commit 179bc23

Browse files
committed
Use ArtifactBuilderService in aggregator runtime
1 parent f68e0e8 commit 179bc23

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

mithril-aggregator/src/runtime/runner.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ pub trait AggregatorRunnerTrait: Sync + Send {
149149
remote_locations: Vec<String>,
150150
) -> Result<Snapshot, Box<dyn StdError + Sync + Send>>;
151151

152+
/// Create an artifact and persist it.
153+
async fn create_and_save_artifact(
154+
&self,
155+
signed_entity_type: &SignedEntityType,
156+
certificate: &Certificate,
157+
) -> Result<(), Box<dyn StdError + Sync + Send>>;
158+
152159
/// Update the EraChecker with EraReader information.
153160
async fn update_era_checker(
154161
&self,
@@ -548,6 +555,25 @@ impl AggregatorRunnerTrait for AggregatorRunner {
548555
Ok(snapshot)
549556
}
550557

558+
async fn create_and_save_artifact(
559+
&self,
560+
signed_entity_type: &SignedEntityType,
561+
certificate: &Certificate,
562+
) -> Result<(), Box<dyn StdError + Sync + Send>> {
563+
debug!("RUNNER: create and save artifact");
564+
let artifact = self
565+
.dependencies
566+
.artifact_builder_service
567+
.compute_artifact(signed_entity_type.to_owned(), certificate)
568+
.await?;
569+
self.dependencies
570+
.artifact_builder_service
571+
.create_and_save_signed_entity(signed_entity_type.to_owned(), certificate, artifact)
572+
.await?;
573+
574+
Ok(())
575+
}
576+
551577
async fn update_era_checker(
552578
&self,
553579
beacon: &Beacon,

mithril-aggregator/src/runtime/state_machine.rs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -282,18 +282,8 @@ impl AggregatorRuntime {
282282
})?;
283283

284284
self.runner.drop_pending_certificate().await?;
285-
let ongoing_snapshot = self
286-
.runner
287-
.create_snapshot_archive(&state.current_beacon, &state.protocol_message)
288-
.await?;
289-
let locations = self
290-
.runner
291-
.upload_snapshot_archive(&ongoing_snapshot)
292-
.await?;
293-
294-
let _ = self
295-
.runner
296-
.create_and_save_snapshot(certificate, &ongoing_snapshot, locations)
285+
self.runner
286+
.create_and_save_artifact(&state.signed_entity_type, &certificate)
297287
.await?;
298288

299289
Ok(IdleState {
@@ -356,10 +346,7 @@ impl AggregatorRuntime {
356346
#[cfg(test)]
357347
mod tests {
358348

359-
use std::path::Path;
360-
361349
use crate::entities::OpenMessage;
362-
use crate::snapshotter::OngoingSnapshot;
363350

364351
use super::super::runner::MockAggregatorRunner;
365352
use super::*;
@@ -684,22 +671,9 @@ mod tests {
684671
.once()
685672
.returning(|| Ok(Some(fake_data::certificate_pending())));
686673
runner
687-
.expect_create_snapshot_archive()
688-
.once()
689-
.returning(|_, _| {
690-
Ok(OngoingSnapshot::new(
691-
Path::new("/tmp/archive.zip").to_path_buf(),
692-
1234,
693-
))
694-
});
695-
runner
696-
.expect_upload_snapshot_archive()
697-
.once()
698-
.returning(|_path| Ok(vec!["locA".to_string(), "locB".to_string()]));
699-
runner
700-
.expect_create_and_save_snapshot()
674+
.expect_create_and_save_artifact()
701675
.once()
702-
.returning(|_, _, _| Ok(fake_data::snapshots(1)[0].clone()));
676+
.returning(|_, _| Ok(()));
703677

704678
let state = SigningState {
705679
current_beacon: fake_data::beacon(),

0 commit comments

Comments
 (0)