mithril_aggregator/dependency_injection/builder/support/
upkeep.rs

1use std::sync::Arc;
2
3use crate::dependency_injection::{DependenciesBuilder, Result};
4use crate::services::{AggregatorUpkeepService, EpochPruningTask, UpkeepService};
5
6impl DependenciesBuilder {
7    /// Return a [EpochPruningTask] instance
8    pub async fn get_signer_registration_pruning_task(
9        &mut self,
10    ) -> Result<Arc<dyn EpochPruningTask>> {
11        Ok(if self.configuration.is_follower_aggregator() {
12            self.get_mithril_signer_registration_follower().await?
13        } else {
14            self.get_mithril_signer_registration_leader().await?
15        })
16    }
17
18    async fn build_upkeep_service(&mut self) -> Result<Arc<dyn UpkeepService>> {
19        let stake_pool_pruning_task = self.get_stake_store().await?;
20        let epoch_settings_pruning_task = self.get_epoch_settings_store().await?;
21        let signer_registration_pruning_task = self.get_signer_registration_pruning_task().await?;
22
23        let upkeep_service = Arc::new(AggregatorUpkeepService::new(
24            self.get_sqlite_connection().await?,
25            self.get_sqlite_connection_cardano_transaction_pool()
26                .await?,
27            self.get_event_store_sqlite_connection().await?,
28            self.get_signed_entity_lock().await?,
29            vec![
30                stake_pool_pruning_task,
31                epoch_settings_pruning_task,
32                signer_registration_pruning_task,
33            ],
34            self.root_logger(),
35        ));
36
37        Ok(upkeep_service)
38    }
39
40    /// Get the [UpkeepService] instance
41    pub async fn get_upkeep_service(&mut self) -> Result<Arc<dyn UpkeepService>> {
42        if self.upkeep_service.is_none() {
43            self.upkeep_service = Some(self.build_upkeep_service().await?);
44        }
45
46        Ok(self.upkeep_service.as_ref().cloned().unwrap())
47    }
48}