mod.rs

Overview

This file defines the ProducerService struct, which encapsulates the lifecycle and management of a block production service within the system. The primary responsibility of this service is to coordinate and execute block production tasks by leveraging a BlockProducer instance. The service runs asynchronously in its own thread, handling communication, synchronization, and production control commands. It integrates tightly with various components such as networking, cryptographic key management, block state repositories, and attestation services.

Entities and Components

ProducerService Struct

AllowGuardedMut Implementation

Functions and Methods

ProducerService::start

pub fn start(
    self_addr: SocketAddr,
    thread_id: ThreadIdentifier,
    repository: RepositoryImpl,
    block_state_repository: BlockStateRepository,
    block_producer_control_rx: std::sync::mpsc::Receiver<BlockProducerCommand>,
    production_process: TVMBlockProducerProcess,
    feedback_sender: InstrumentedSender<ExtMsgFeedbackList>,
    received_acks: Arc<Mutex<Vec<Envelope<GoshBLS, AckData>>>>,
    received_nacks: Arc<Mutex<Vec<Envelope<GoshBLS, NackData>>>>,
    shared_services: SharedServices,
    bls_keys_map: Arc<Mutex<HashMap<PubKey, (Secret, RndSeed)>>>,
    last_block_attestations: Arc<Mutex<CollectedAttestations>>,
    attestations_target_service: AttestationTargetsService,
    self_tx: XInstrumentedSender<(NetworkMessage, SocketAddr)>,
    self_authority_tx: XInstrumentedSender<(NetworkMessage, SocketAddr)>,
    broadcast_tx: NetBroadcastSender<NetworkMessage>,
    node_identifier: NodeIdentifier,
    production_timeout: Duration,
    save_state_frequency: u32,
    external_messages: ExternalMessagesThreadState,
    is_state_sync_requested: Arc<Mutex<Option<BlockSeqNo>>>,
    bp_production_count: Arc<AtomicI32>,
    save_optimistic_service_sender: InstrumentedSender<Arc<OptimisticStateImpl>>,
) -> anyhow::Result<Self>
let producer_service = ProducerService::start(
    self_addr,
    thread_id,
    repository,
    block_state_repository,
    block_producer_control_rx,
    production_process,
    feedback_sender,
    received_acks,
    received_nacks,
    shared_services,
    bls_keys_map,
    last_block_attestations,
    attestations_target_service,
    self_tx,
    self_authority_tx,
    broadcast_tx,
    node_identifier,
    production_timeout,
    save_state_frequency,
    external_messages,
    is_state_sync_requested,
    bp_production_count,
    save_optimistic_service_sender,
)?;

ProducerService::touch

pub fn touch(&mut self)
producer_service.touch(); // Will panic if the thread has stopped.

Important Implementation Details

Interactions with Other System Components

Diagram: ProducerService Structure and Workflow

classDiagram
class ProducerService {
-handler: Option<JoinHandle<Result>>
+start(...)
+touch()
}
class BlockProducer {
+builder()
+main_loop()
}
ProducerService "1" --> "1" BlockProducer : manages
ProducerService ..> JoinHandle : spawns thread
ProducerService ..> "mpsc::Receiver<BlockProducerCommand>" : control_rx
ProducerService ..> InstrumentedSender : feedback_sender
ProducerService ..> Arc~Mutex~ : received_acks, received_nacks, bls_keys_map
ProducerService ..> SharedServices : shared_services
ProducerService ..> RepositoryImpl : repository
ProducerService ..> BlockStateRepository : block_state_repository
ProducerService ..> AttestationTargetsService : attestations_target_service
ProducerService ..> ExternalMessagesThreadState : external_messages
ProducerService ..> AtomicI32 : bp_production_count
ProducerService ..> InstrumentedSender~Arc~OptimisticStateImpl~ : save_optimistic_service_sender