mithril_cardano_node_chain/chain_importer/
api.rs

1use std::collections::BTreeSet;
2use std::ops::Range;
3
4use async_trait::async_trait;
5
6use mithril_common::StdResult;
7use mithril_common::crypto_helper::MKTreeNode;
8use mithril_common::entities::{
9    BlockNumber, BlockRange, CardanoBlockTransactionMkTreeNode, CardanoBlockWithTransactions,
10    CardanoTransaction, ChainPoint, SlotNumber,
11};
12
13/// Cardano chain data importer
14#[cfg_attr(test, mockall::automock)]
15#[async_trait]
16pub trait ChainDataImporter: Send + Sync {
17    /// Import data stored on the chain up to the given beacon into the system
18    async fn import(&self, up_to_beacon: BlockNumber) -> StdResult<()>;
19}
20
21/// Cardano chain data store
22#[cfg_attr(test, mockall::automock)]
23#[async_trait]
24pub trait ChainDataStore: Send + Sync {
25    /// Get the highest known transaction beacon
26    async fn get_highest_beacon(&self) -> StdResult<Option<ChainPoint>>;
27
28    /// Get the highest stored block range root bounds
29    async fn get_highest_block_range(&self) -> StdResult<Option<BlockRange>>;
30
31    /// Get the highest stored legacy block range root bounds
32    async fn get_highest_legacy_block_range(&self) -> StdResult<Option<BlockRange>>;
33
34    /// Store the given blocks and their transactions
35    async fn store_blocks_and_transactions(
36        &self,
37        block_with_transactions: Vec<CardanoBlockWithTransactions>,
38    ) -> StdResult<()>;
39
40    /// Get all blocks and transactions in an interval of blocks
41    async fn get_blocks_and_transactions_in_range(
42        &self,
43        range: Range<BlockNumber>,
44    ) -> StdResult<BTreeSet<CardanoBlockTransactionMkTreeNode>>;
45
46    /// Get transactions in an interval of blocks
47    async fn get_transactions_in_range(
48        &self,
49        range: Range<BlockNumber>,
50    ) -> StdResult<Vec<CardanoTransaction>>;
51
52    /// Store list of block ranges with their corresponding merkle root
53    async fn store_block_range_roots(
54        &self,
55        block_ranges: Vec<(BlockRange, MKTreeNode)>,
56    ) -> StdResult<()>;
57
58    /// Store list of legacy block ranges with their corresponding merkle root
59    async fn store_legacy_block_range_roots(
60        &self,
61        block_ranges: Vec<(BlockRange, MKTreeNode)>,
62    ) -> StdResult<()>;
63
64    /// Remove blocks, transactions, and block range roots that are in a rolled-back fork
65    ///
66    /// * Remove blocks and transactions with a slot number strictly greater than the given slot number
67    /// * Remove block range roots that have lower bound range strictly above the given slot number
68    async fn remove_rolled_chain_data_and_block_range(
69        &self,
70        slot_number: SlotNumber,
71    ) -> StdResult<()>;
72
73    /// Tell the store to perform optimization tasks if it needs them to improve its query performances
74    async fn optimize(&self) -> StdResult<()>;
75}