sui_indexer/store/
indexer_store.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use std::collections::BTreeMap;
5
6use async_trait::async_trait;
7use strum::IntoEnumIterator;
8
9use crate::errors::IndexerError;
10use crate::handlers::pruner::PrunableTable;
11use crate::handlers::{CommitterWatermark, EpochToCommit, TransactionObjectChangesToCommit};
12use crate::models::display::StoredDisplay;
13use crate::models::obj_indices::StoredObjectVersion;
14use crate::models::objects::{StoredDeletedObject, StoredObject};
15use crate::models::raw_checkpoints::StoredRawCheckpoint;
16use crate::models::watermarks::StoredWatermark;
17use crate::types::{
18    EventIndex, IndexedCheckpoint, IndexedEvent, IndexedPackage, IndexedTransaction, TxIndex,
19};
20
21#[allow(clippy::large_enum_variant)]
22pub enum ObjectsToCommit {
23    MutatedObject(StoredObject),
24    DeletedObject(StoredDeletedObject),
25}
26
27#[async_trait]
28pub trait IndexerStore: Clone + Sync + Send + 'static {
29    async fn get_latest_checkpoint_sequence_number(&self) -> Result<Option<u64>, IndexerError>;
30
31    async fn get_available_epoch_range(&self) -> Result<(u64, u64), IndexerError>;
32
33    async fn get_available_checkpoint_range(&self) -> Result<(u64, u64), IndexerError>;
34
35    async fn get_latest_object_snapshot_checkpoint_sequence_number(
36        &self,
37    ) -> Result<Option<u64>, IndexerError>;
38
39    async fn get_chain_identifier(&self) -> Result<Option<Vec<u8>>, IndexerError>;
40
41    async fn persist_protocol_configs_and_feature_flags(
42        &self,
43        chain_id: Vec<u8>,
44    ) -> Result<(), IndexerError>;
45
46    async fn persist_objects(
47        &self,
48        object_changes: Vec<TransactionObjectChangesToCommit>,
49    ) -> Result<(), IndexerError>;
50
51    async fn persist_object_history(
52        &self,
53        object_changes: Vec<TransactionObjectChangesToCommit>,
54    ) -> Result<(), IndexerError>;
55
56    async fn persist_full_objects_history(
57        &self,
58        object_changes: Vec<TransactionObjectChangesToCommit>,
59    ) -> Result<(), IndexerError>;
60
61    async fn persist_objects_version(
62        &self,
63        object_versions: Vec<StoredObjectVersion>,
64    ) -> Result<(), IndexerError>;
65
66    async fn persist_objects_snapshot(
67        &self,
68        object_changes: Vec<TransactionObjectChangesToCommit>,
69    ) -> Result<(), IndexerError>;
70
71    async fn persist_checkpoints(
72        &self,
73        checkpoints: Vec<IndexedCheckpoint>,
74    ) -> Result<(), IndexerError>;
75
76    async fn persist_chain_identifier(
77        &self,
78        checkpoint_digest: Vec<u8>,
79    ) -> Result<(), IndexerError>;
80
81    async fn persist_transactions(
82        &self,
83        transactions: Vec<IndexedTransaction>,
84    ) -> Result<(), IndexerError>;
85
86    async fn persist_tx_indices(&self, indices: Vec<TxIndex>) -> Result<(), IndexerError>;
87
88    async fn persist_events(&self, events: Vec<IndexedEvent>) -> Result<(), IndexerError>;
89    async fn persist_event_indices(
90        &self,
91        event_indices: Vec<EventIndex>,
92    ) -> Result<(), IndexerError>;
93
94    async fn persist_displays(
95        &self,
96        display_updates: BTreeMap<String, StoredDisplay>,
97    ) -> Result<(), IndexerError>;
98
99    async fn persist_packages(&self, packages: Vec<IndexedPackage>) -> Result<(), IndexerError>;
100
101    /// Updates the current epoch with end-of-epoch data, and writes a new epoch to the database.
102    async fn persist_epoch(&self, epoch: EpochToCommit) -> Result<(), IndexerError>;
103
104    /// Updates epoch-partitioned tables to accept data from the new epoch.
105    async fn advance_epoch(&self, epoch: EpochToCommit) -> Result<(), IndexerError>;
106
107    async fn prune_epoch(&self, epoch: u64) -> Result<(), IndexerError>;
108
109    async fn get_network_total_transactions_by_end_of_epoch(
110        &self,
111        epoch: u64,
112    ) -> Result<Option<u64>, IndexerError>;
113
114    async fn upload_display(&self, epoch: u64) -> Result<(), IndexerError>;
115
116    async fn restore_display(&self, bytes: bytes::Bytes) -> Result<(), IndexerError>;
117
118    async fn persist_raw_checkpoints(
119        &self,
120        checkpoints: Vec<StoredRawCheckpoint>,
121    ) -> Result<(), IndexerError>;
122
123    /// Update the upper bound of the watermarks for the given tables.
124    async fn update_watermarks_upper_bound<E: IntoEnumIterator>(
125        &self,
126        watermark: CommitterWatermark,
127    ) -> Result<(), IndexerError>
128    where
129        E::Iterator: Iterator<Item: AsRef<str>>;
130
131    /// Updates each watermark entry's lower bounds per the list of tables and their new epoch lower
132    /// bounds.
133    async fn update_watermarks_lower_bound(
134        &self,
135        watermarks: Vec<(PrunableTable, u64)>,
136    ) -> Result<(), IndexerError>;
137
138    /// Load all watermark entries from the store, and the latest timestamp from the db.
139    async fn get_watermarks(&self) -> Result<(Vec<StoredWatermark>, i64), IndexerError>;
140}