iota_light_client/
object_store.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2025 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use core::num::NonZeroUsize;
6
7use anyhow::{Result, anyhow};
8use iota_config::node::ArchiveReaderConfig;
9use iota_data_ingestion_core::history::reader::HistoricalReader;
10use iota_types::{
11    full_checkpoint_content::CheckpointData, messages_checkpoint::CertifiedCheckpointSummary,
12};
13use tracing::debug;
14
15use crate::config::Config;
16
17pub struct CheckpointStore {
18    historical_reader: HistoricalReader,
19}
20
21impl CheckpointStore {
22    pub fn new(config: &Config) -> Result<Self> {
23        let checkpoint_store_config = config
24            .checkpoint_store_config
25            .as_ref()
26            .cloned()
27            .ok_or_else(|| anyhow!("missing checkpoint store url"))?;
28
29        let config = ArchiveReaderConfig {
30            remote_store_config: checkpoint_store_config,
31            download_concurrency: NonZeroUsize::new(5).unwrap(),
32            use_for_pruning_watermark: false,
33        };
34
35        Ok(Self {
36            historical_reader: HistoricalReader::new(config)?,
37        })
38    }
39
40    pub async fn fetch_checkpoint_summary(&self, seq: u64) -> Result<CertifiedCheckpointSummary> {
41        let full_checkpoint = self.fetch_full_checkpoint(seq).await?;
42
43        Ok(full_checkpoint.checkpoint_summary)
44    }
45
46    pub async fn fetch_full_checkpoint(&self, seq: u64) -> Result<CheckpointData> {
47        self.historical_reader.sync_manifest_once().await?;
48        let checkpoint = self
49            .historical_reader
50            .iter_for_range(seq..seq + 1)
51            .await?
52            .next()
53            .ok_or_else(|| anyhow!("missing full checkpoint"))?;
54        debug!("Fetched checkpoint '{seq}' from checkpoint store",);
55
56        Ok(checkpoint)
57    }
58}