mod.rs

Overview

This file defines data structures and logic related to the management of "Block Keepers" within the system. Block Keepers appear to be entities responsible for certain roles in maintaining or validating blockchain-related data, tracked through their cryptographic keys, status, stakes, and identifiers.

The file provides:

This module interacts heavily with cryptographic public keys (PubKey), node identifiers, and account addresses, integrating with external HTTP API types (ApiBk, ApiBkStatus, etc.) and cryptographic utilities from other parts of the codebase.


Enumerations

BlockKeeperSetChange

Represents state changes in the Block Keeper set.

Variants:

BlockKeeperStatus

Represents the lifecycle status of a Block Keeper.

Variants:


Structs and Their Details

BlockKeeperData

Holds comprehensive information about a Block Keeper.

Fields:

Methods:

Traits Implemented:

Usage example:

let bk_data = BlockKeeperData {
    pubkey: some_pubkey,
    epoch_finish_seq_no: Some(100),
    wait_step: 5,
    status: BlockKeeperStatus::Active,
    address: "0xabc...".to_string(),
    stake: BigUint::from(1000u32),
    owner_address: some_account_address,
    signer_index: 1,
    owner_pubkey: [0u8; 32],
};

println!("BlockKeeper Node ID: {:?}", bk_data.node_id());

BlockKeeperSet

A collection that manages multiple BlockKeeperData entries indexed by SignerIndex and NodeIdentifier.

Fields (private):

Key Methods:

Traits Implemented:

Usage example:

let mut bk_set = BlockKeeperSet::new();
bk_set.insert(1, bk_data.clone());
assert_eq!(bk_set.len(), 1);
if let Some(keeper) = bk_set.get_by_signer(&1) {
    println!("Found keeper with stake: {}", keeper.stake);
}

BlockKeeperSlashData

Represents slashing information for a Block Keeper, potentially used to penalize misbehavior.

Fields:

Traits:


Conversion Implementations

These allow seamless transformation between internal types and API representations (ApiBk, ApiBkStatus, etc.).


Important Implementation Details


Interactions with Other Modules


Visual Diagram

classDiagram
class BlockKeeperData {
+pubkey
+epoch_finish_seq_no
+wait_step
+status
+address
+stake
+owner_address
+signer_index
+owner_pubkey
+node_id()
}
class BlockKeeperSet {
-by_signer: HashMap
-signer_to_pubkey: HashMap
-signer_by_node_id: BTreeMap
+new()
+len()
+is_empty()
+insert()
+contains_signer()
+contains_node()
+get_by_signer()
+get_by_node_id()
+get_pubkeys_by_signers()
+get_undistributed_stake()
+iter_node_ids()
+remove_signer()
}
class BlockKeeperSetChange {
<<enumeration>>
+BlockKeeperAdded
+BlockKeeperRemoved
+FutureBlockKeeperAdded
}
class BlockKeeperStatus {
<<enumeration>>
+PreEpoch
+Active
+CalledToFinish
+Expired
}
class BlockKeeperSlashData {
+node_id
+bls_pubkey
+addr
+slash_type
}
BlockKeeperSet "1" o-- "many" BlockKeeperData : manages
BlockKeeperData ..> NodeIdentifier : uses
BlockKeeperData ..> PubKey : uses
BlockKeeperSetChange ..> BlockKeeperData : state changes with
BlockKeeperSlashData ..> NodeIdentifier : references
BlockKeeperSlashData ..> PubKey : references

Summary of Main Functions

Function

Description

BlockKeeperData::node_id()

Returns the node identifier derived from the owner address.

BlockKeeperSet::new()

Creates an empty Block Keeper set.

BlockKeeperSet::insert()

Inserts or updates a Block Keeper in the set.

BlockKeeperSet::get_by_signer()

Retrieves a Block Keeper by signer index.

BlockKeeperSet::get_by_node_id()

Retrieves a Block Keeper by node identifier.

BlockKeeperSet::get_undistributed_stake()

Computes stake not held by attested signers.

BlockKeeperSet::remove_signer()

Removes a Block Keeper by signer index.


Usage Context

This file plays a critical role in managing Block Keeper information, enabling the tracking of their states, statuses, and stakes, and facilitating communication with external API layers. It is essential for the parts of the system that require knowledge of active block validators or maintainers, their cryptographic identities, and their operational statuses. The presence of slashing data structures indicates integration with consensus or governance mechanisms that enforce penalties.

For more details on the cryptographic key types, node identifiers, and account addresses used here, see the respective topics:

For API interaction specifics, refer to:

For serialization and deserialization strategies, refer to: