mithril_cardano_node_chain/chain_importer/
api.rs

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