common_section.rs

Overview

This file defines the CommonSection struct along with its associated types and functionality, which encapsulates common metadata and state information related to blocks within the system. It handles data such as block height, round, producer identification, attestations, acknowledgments, and references to other blocks. Serialization and deserialization logic are implemented to support efficient persistence and transmission of this data. The file also defines the Directives struct, which contains optional sharing state resources that can be referenced by thread identifiers.

The CommonSection is a core data structure used within the block processing and consensus mechanisms, interacting with components like block keepers, cryptographic envelopes, and node identification. It supports conditional compilation features such as monitoring account differences.


Detailed Entities and Components

Directives Struct

Description

Directives encapsulates optional instructions or resource sharing information related to block processing. It currently holds an optional map, share_state_resources, which associates ThreadIdentifiers with corresponding BlockIdentifiers.

Fields

Traits and Derivations

Usage Example

let directives = Directives::default();
if let Some(resources) = directives.share_state_resources() {
    // Process shared state resources
}

CommonSection Struct

Description

CommonSection aggregates essential metadata and state references for a blockchain block. It is intended to be embedded or used as part of larger block-related structures, holding attestations, acknowledgments, references, threading information, and other consensus-related data.

Fields

Field Name

Type

Description

block_height

BlockHeight

The height of the block in the blockchain.

directives

Directives

Optional directives or resource sharing instructions for the block.

block_attestations

Vec<Envelope<GoshBLS, AttestationData>>

Collection of cryptographic attestations related to the block.

round

BlockRound

The consensus round number for the block.

producer_id

NodeIdentifier

Identifier of the node that produced the block.

thread_id

ThreadIdentifier

Identifier of the thread where the block belongs.

threads_table

Option<ThreadsTable>

Optional threads table snapshot for cross-thread state.

refs

Vec<BlockIdentifier>

References to other blocks that this block depends on (e.g., internal message sources).

block_keeper_set_changes

Vec<BlockKeeperSetChange>

Changes in block keeper sets relevant to this block.

verify_complexity

SignerIndex

Expected complexity in terms of the number of expected acknowledgments and negative acknowledgments (nacks).

acks

Vec<Envelope<GoshBLS, AckData>>

Acknowledgments corresponding to the block.

nacks

Vec<Envelope<GoshBLS, NackData>>

Negative acknowledgments corresponding to the block.

producer_selector

Option<ProducerSelector>

Optional selector indicating producer selection information; must be set before serialization.

accounts_number_diff

i64 (conditional on feature monitor-accounts-number)

Optional difference in accounts number monitored for this block.


Methods on CommonSection

new

pub fn new(
    thread_id: ThreadIdentifier,
    round: BlockRound,
    producer_id: NodeIdentifier,
    block_keeper_set_changes: Vec<BlockKeeperSetChange>,
    verify_complexity: SignerIndex,
    refs: Vec<BlockIdentifier>,
    threads_table: Option<ThreadsTable>,
    block_height: BlockHeight,
    #[cfg(feature = "monitor-accounts-number")] accounts_number_diff: i64,
) -> Self
Description

Constructs a new CommonSection instance initializing all core fields, with empty vectors for attestations, acks, and nacks, and default Directives.

Parameters
Returns
Usage Example
let common_section = CommonSection::new(
    thread_id,
    round,
    producer_id,
    vec![],
    verify_complexity,
    vec![],
    None,
    block_height,
    #[cfg(feature = "monitor-accounts-number")]
    0,
);

wrap_serialize

fn wrap_serialize(&self) -> WrappedCommonSection
Description

Prepares a serializable wrapper struct WrappedCommonSection by serializing internal vectors (block_attestations, acks, nacks) into byte arrays using bincode. This method handles conditional compilation fields appropriately.

Returns
Implementation Detail

wrap_deserialize

fn wrap_deserialize(data: WrappedCommonSection) -> Self
Description

Deserializes a WrappedCommonSection back into a CommonSection by decoding the serialized byte arrays (block_attestations, acks, nacks) and reconstructing all fields.

Parameters
Returns
Implementation Detail

WrappedCommonSection Struct

Description

A private helper struct used to facilitate the custom serialization and deserialization logic for CommonSection. It stores serialized byte arrays for attestations, acknowledgments, and negative acknowledgments.

Fields

Field Name

Type

Description

round

BlockRound

Round number of the block.

directives

Directives

Block directives.

block_attestations

Vec<u8>

Serialized byte array of attestations.

producer_id

NodeIdentifier

Producer node identifier.

block_keeper_set_changes

Vec<BlockKeeperSetChange>

Changes in block keeper sets.

verify_complexity

SignerIndex

Verification complexity.

acks

Vec<u8>

Serialized byte array of acknowledgments.

nacks

Vec<u8>

Serialized byte array of negative acknowledgments.

producer_selector

ProducerSelector

Producer selector information.

thread_identifier

ThreadIdentifier

Thread identifier for the block.

refs

Vec<BlockIdentifier>

References to other blocks.

threads_table

Option<ThreadsTable>

Optional threads table snapshot.

block_height

BlockHeight

Height of the block.

accounts_number_diff

i64 (conditional on feature)

Account number difference monitored for block.


Trait Implementations

Serialize for CommonSection

Deserialize for CommonSection

Debug for CommonSection and Directives


Implementation Details and Algorithms


Interactions with Other System Components


Mermaid Diagram: Structure of common_section.rs

classDiagram
class Directives {
+share_state_resources: Option<HashMap<ThreadIdentifier, BlockIdentifier>>
+default()
+clone()
}
Directives ..> HashMap
Directives ..> ThreadIdentifier
Directives ..> BlockIdentifier
class CommonSection {
+block_height: BlockHeight
+directives: Directives
+block_attestations: Vec<Envelope<GoshBLS, AttestationData>>
+round: BlockRound
+producer_id: NodeIdentifier
+thread_id: ThreadIdentifier
+threads_table: Option<ThreadsTable>
+refs: Vec<BlockIdentifier>
+block_keeper_set_changes: Vec<BlockKeeperSetChange>
+verify_complexity: SignerIndex
+acks: Vec<Envelope<GoshBLS, AckData>>
+nacks: Vec<Envelope<GoshBLS, NackData>>
+producer_selector: Option<ProducerSelector>
+accounts_number_diff: i64 (optional)
+new()
-wrap_serialize()
-wrap_deserialize()
}
CommonSection --> Directives
CommonSection --> Envelope
CommonSection --> BlockKeeperSetChange
CommonSection --> ProducerSelector
CommonSection --> ThreadsTable
CommonSection --> ThreadIdentifier
CommonSection --> BlockIdentifier
CommonSection --> NodeIdentifier

This diagram illustrates the main data structures and their relationships in common_section.rs, emphasizing the composition of CommonSection and its dependencies on other system types.