thread_synchrinization_service.rs

Overview

This file implements the ThreadSyncService, a service responsible for tracking and managing synchronization information between multiple threads in a blockchain system. Its primary function is to maintain records of the last finalized blocks per thread and to provide information about blocks from other threads that may send messages to a given thread. The service is designed around the concept of finalized blocks, ignoring forks and focusing on finalized states to ensure consistency and reduce verification delays.

The service facilitates cross-thread communication by referencing finalized blocks from other threads, which helps in verifying blocks in a timely manner and maintaining system integrity. It is structured to be extendable for more optimistic synchronization strategies in the future.

ThreadSyncService Struct

Description

ThreadSyncService maintains a mapping between thread identifiers and the last finalized block identifiers associated with those threads. This mapping supports queries about which blocks from other threads may be sending messages to a specific thread.

Fields

Implementation Details

Methods

pub fn on_block_finalized(&mut self, block_identifier: &BlockIdentifier, thread_identifier: &ThreadIdentifier) -> anyhow::Result<()>

pub fn list_blocks_sending_messages_to_thread(&mut self, thread_identifier: &ThreadIdentifier) -> anyhow::Result<Vec<(ThreadIdentifier, BlockIdentifier)>>

pub fn start(_: ()) -> Self

Important Implementation Considerations

Interactions with Other System Components

Visual Diagram: Class Structure of ThreadSyncService

classDiagram
class ThreadSyncService {
-last_finalized_blocks: HashMap<ThreadIdentifier, BlockIdentifier>
+on_block_finalized()
+list_blocks_sending_messages_to_thread()
+start()
}

This diagram illustrates the ThreadSyncService with its main private field and public methods, highlighting the simplicity and focused responsibility of the service.