Trait BlockStorage

Source
pub trait BlockStorage:
    Clone
    + Send
    + Sync {
    // Required methods
    fn get_last_processed_block<'life0, 'life1, 'async_trait>(
        &'life0 self,
        network_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<u64>, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn save_last_processed_block<'life0, 'life1, 'async_trait>(
        &'life0 self,
        network_id: &'life1 str,
        block: u64,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn save_blocks<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        network_id: &'life1 str,
        blocks: &'life2 [BlockType],
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn delete_blocks<'life0, 'life1, 'async_trait>(
        &'life0 self,
        network_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn save_missed_blocks<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        network_id: &'life1 str,
        blocks: &'life2 [u64],
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn get_missed_blocks<'life0, 'life1, 'async_trait>(
        &'life0 self,
        network_id: &'life1 str,
        max_block_age: u64,
        current_block: u64,
        max_retries: u32,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<MissedBlockEntry>, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn update_missed_block_status<'life0, 'life1, 'async_trait>(
        &'life0 self,
        network_id: &'life1 str,
        block_number: u64,
        status: MissedBlockStatus,
        error: Option<String>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn remove_recovered_blocks<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        network_id: &'life1 str,
        block_numbers: &'life2 [u64],
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn prune_old_missed_blocks<'life0, 'life1, 'async_trait>(
        &'life0 self,
        network_id: &'life1 str,
        max_block_age: u64,
        current_block: u64,
    ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Interface for block storage implementations

Defines the required functionality for storing and retrieving blocks and tracking the last processed block for each network.

Required Methods§

Source

fn get_last_processed_block<'life0, 'life1, 'async_trait>( &'life0 self, network_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<u64>, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves the last processed block number for a network

§Arguments
  • network_id - Unique identifier for the network
§Returns
  • Result<Option<u64>, anyhow::Error> - Last processed block number or None if not found
Source

fn save_last_processed_block<'life0, 'life1, 'async_trait>( &'life0 self, network_id: &'life1 str, block: u64, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Saves the last processed block number for a network

§Arguments
  • network_id - Unique identifier for the network
  • block - Block number to save
§Returns
  • Result<(), anyhow::Error> - Success or error
Source

fn save_blocks<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, network_id: &'life1 str, blocks: &'life2 [BlockType], ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Saves a collection of blocks for a network

§Arguments
  • network_id - Unique identifier for the network
  • blocks - Collection of blocks to save
§Returns
  • Result<(), anyhow::Error> - Success or error
Source

fn delete_blocks<'life0, 'life1, 'async_trait>( &'life0 self, network_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Deletes all stored blocks for a network

§Arguments
  • network_id - Unique identifier for the network
§Returns
  • Result<(), anyhow::Error> - Success or error
Source

fn save_missed_blocks<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, network_id: &'life1 str, blocks: &'life2 [u64], ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Saves multiple missed blocks for a network in a single operation

§Arguments
  • network_id - Unique identifier for the network
  • blocks - Slice of block numbers to save
§Returns
  • Result<(), anyhow::Error> - Success or error
Source

fn get_missed_blocks<'life0, 'life1, 'async_trait>( &'life0 self, network_id: &'life1 str, max_block_age: u64, current_block: u64, max_retries: u32, ) -> Pin<Box<dyn Future<Output = Result<Vec<MissedBlockEntry>, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves missed blocks eligible for recovery

Returns blocks that are within the max_block_age range and have status Pending with retry_count below max_retries.

§Arguments
  • network_id - Unique identifier for the network
  • max_block_age - Maximum age in blocks from current_block
  • current_block - The current block number
  • max_retries - Maximum retry attempts; blocks with retry_count >= max_retries are excluded
§Returns
  • Result<Vec<MissedBlockEntry>, anyhow::Error> - Eligible missed blocks
Source

fn update_missed_block_status<'life0, 'life1, 'async_trait>( &'life0 self, network_id: &'life1 str, block_number: u64, status: MissedBlockStatus, error: Option<String>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Updates the status of a missed block

§Arguments
  • network_id - Unique identifier for the network
  • block_number - Block number to update
  • status - New status for the block
  • error - Optional error message (for failed status)
§Returns
  • Result<(), anyhow::Error> - Success or error
Source

fn remove_recovered_blocks<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, network_id: &'life1 str, block_numbers: &'life2 [u64], ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Removes recovered blocks from storage

§Arguments
  • network_id - Unique identifier for the network
  • block_numbers - Block numbers to remove
§Returns
  • Result<(), anyhow::Error> - Success or error
Source

fn prune_old_missed_blocks<'life0, 'life1, 'async_trait>( &'life0 self, network_id: &'life1 str, max_block_age: u64, current_block: u64, ) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Prunes missed blocks older than max_block_age

§Arguments
  • network_id - Unique identifier for the network
  • max_block_age - Maximum age in blocks
  • current_block - The current block number
§Returns
  • Result<usize, anyhow::Error> - Number of pruned blocks

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§