mod.rs

Overview

This file defines the AckiNackiBlock struct which encapsulates a blockchain block representation enriched with a CommonSection metadata structure and additional auxiliary data. It provides methods for block construction, hash verification, serialization/deserialization, and access to block-related metadata such as identifiers, sequence numbers, and references to parent blocks. The file also manages interactions with the underlying TVM block structure (tvm_block::Block), handling serialization and hash calculations essential for block validation and replication.

The AckiNackiBlock integrates tightly with other components managing the blockchain's threading model, block referencing, and cryptographic verification. Key dependencies include the CommonSection for block metadata, cryptographic hashing utilities (Sha256Hash), and block serialization utilities from the tvm_block and tvm_types crates.

Modules

The file publicly re-exports the compare_hashes function from the hash module for external comparison of block hashes.

Constants

Struct: AckiNackiBlock

Encapsulates a blockchain block along with its metadata and auxiliary serialized data.

Fields

Trait Implementations

Methods

new

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

Constructs a new AckiNackiBlock instance by initializing the common_section with the provided metadata and storing the provided TVM block and transaction count. The hash is initialized to zero and raw data is not precomputed.

let acki_block = AckiNackiBlock::new(
    thread_id,
    tvm_block,
    producer_id,
    tx_count,
    block_keeper_changes,
    verify_complexity,
    refs,
    Some(threads_table),
    round,
    block_height,
    #[cfg(feature = "monitor-accounts-number")]
    accounts_number_diff,
);

raw_block_data

pub fn raw_block_data(&self) -> anyhow::Result<(Vec<u8>, Cell)>

Retrieves the raw serialized block data and its corresponding Cell representation. It attempts to reuse cached raw data and Cell if present; otherwise, it serializes the block anew.

parent

pub fn parent(&self) -> BlockIdentifier

Returns the identifier of the parent block by reading the previous reference from the TVM block info.

parent_seq_no

pub fn parent_seq_no(&self) -> BlockSeqNo

Returns the sequence number of the parent block by reading it from the TVM block info.

identifier

pub fn identifier(&self) -> BlockIdentifier

Returns the identifier of the current block computed as the hash of the underlying TVM block.

seq_no

pub fn seq_no(&self) -> BlockSeqNo

Returns the sequence number of the current block.

directives

pub fn directives(&self) -> Directives

Returns the directives contained in the common_section of the block.

check_hash

pub fn check_hash(&self) -> anyhow::Result<bool>

Verifies that the stored hash matches the hash computed from the raw block data.

get_hash

pub fn get_hash(&self) -> Sha256Hash

Returns the current SHA-256 hash of the block.

get_common_section

pub fn get_common_section(&self) -> &CommonSection

Returns a reference to the block's CommonSection.

set_common_section

pub fn set_common_section(
    &mut self,
    common_section: CommonSection,
    update_hash: bool,
) -> anyhow::Result<()>

Updates the block's CommonSection and optionally recalculates and updates the block hash and raw serialized data.

is_thread_splitting

pub fn is_thread_splitting(&self) -> bool

Determines whether the current block causes a thread splitting event.

tvm_block

pub fn tvm_block(&self) -> &tvm_block::Block

Returns a reference to the underlying TVM block.

tx_cnt

pub fn tx_cnt(&self) -> usize

Returns the count of transactions in the block.

time

pub fn time(&self) -> anyhow::Result<u64>

Returns the timestamp of block generation in milliseconds.

Important Implementation Details and Algorithms

Interaction with Other System Components

Visual Diagram: AckiNackiBlock Class Structure

classDiagram
class AckiNackiBlock {
-common_section: CommonSection
-block: tvm_block::Block
-tx_cnt: usize
-hash: Sha256Hash
-raw_data: Option<Vec<u8>>
-block_cell: Option<Cell>
+new()
+raw_block_data()
+parent()
+parent_seq_no()
+identifier()
+seq_no()
+directives()
+check_hash()
+get_hash()
+get_common_section()
+set_common_section()
+is_thread_splitting()
+tvm_block()
+tx_cnt()
+time()
}
AckiNackiBlock --> CommonSection : contains
AckiNackiBlock --> "tvm_block::Block" : contains
AckiNackiBlock --> Sha256Hash : contains
AckiNackiBlock --> Vec<u8> : optionally contains
AckiNackiBlock --> Cell : optionally contains

This diagram illustrates the main structure of AckiNackiBlock, showing its fields and methods, as well as its relationships to key types like CommonSection, tvm_block::Block, Sha256Hash, and serialization buffers.


For further details on the hashing mechanisms, see hash and for the metadata structure, refer to CommonSection. Interaction with the thread model is elaborated under ThreadsTable and ThreadIdentifier. Serialization and TVM block internals are documented in tvm_block and serialize.