mod.rs

Overview

This file defines core network message structures and related functionality for handling block propagation, acknowledgments, synchronization, and authority switch protocols within the system. It provides serializable types for transmitting blocks and various network messages among nodes. The file's primary focus is on representing blocks and network messages with associated metadata, enabling their serialization/deserialization and formatted display for debugging and logging purposes.

The file interacts heavily with cryptographic envelope structures (Envelope), block-related types (AckiNackiBlock, BlockIdentifier, etc.), node identifiers, threading, and the authority switch protocol. It serves as a bridge between raw cryptographic block envelopes and higher-level network message types used by the system's node communication layer.


Structures and Enums

NetBlock

A serializable wrapper around a block envelope, extracting and storing metadata needed for network transmission.

Fields

Methods

Trait Implementations


Command Enum

Represents internal commands used within the authority switch service.


NetworkMessage Enum

Defines all possible network messages transmitted between nodes. It encapsulates various block-related messages, synchronization commands, authority switch protocol messages, and local commands.

Variants

Methods

Trait Implementations


Implementation Details and Algorithms


Interactions with Other Modules


Visual Diagram

classDiagram
class NetBlock {
+producer_id: NodeIdentifier
+producer_selector: Option<ProducerSelector>
+thread_id: ThreadIdentifier
+identifier: BlockIdentifier
+seq_no: BlockSeqNo
+envelope_data: Vec<u8>
+with_envelope()
+get_envelope()
}
class Command {
<<enum>>
+StartSynchronization
}
class NetworkMessage {
<<enum>>
+Candidate
+ResentCandidate
+Ack
+Nack
+ExternalMessage
+NodeJoining
+BlockAttestation
+BlockRequest
+SyncFinalized
+SyncFrom
+AuthoritySwitchProtocol
+InnerCommand
+candidate()
+resent_candidate()
}
NetBlock --> Envelope
NetworkMessage --> NetBlock
NetworkMessage --> Envelope
NetworkMessage --> Command
NetworkMessage --> AuthoritySwitch

Usage Examples

Creating a NetBlock from an Envelope

let envelope: Envelope<GoshBLS, AckiNackiBlock> = ...;
let net_block = NetBlock::with_envelope(&envelope)?;
println!("NetBlock: {}", net_block);

Creating a Candidate Network Message

let candidate_msg = NetworkMessage::candidate(&envelope)?;
match candidate_msg {
    NetworkMessage::Candidate(block) => {
        // Process candidate block
    }
    _ => {}
}

Debugging a Network Message

let network_msg: NetworkMessage = ...;
println!("{:?}", network_msg);       // Concise debug output
println!("{:#?}", network_msg);      // Verbose debug output (only variant names)

References