epoch.rs

Overview

This file is responsible for handling the encoding, decoding, and message creation related to epoch and preepoch data structures within the system managed by the BlockKeeper module. It primarily interacts with blockchain account data to decode stored epoch-related information and provides utilities to create specific messages used in the epoch lifecycle.

The key functionalities include:

The file relies on ABI definitions (EPOCH_ABI and PREEPOCH_ABI) and various blockchain-related types and traits for parsing and encoding data.


Constants

Constant

Description

BLS_PUBKEY_TOKEN_KEY

Key to identify the BLS public key token in the data.

EPOCH_FINISH_TOKEN_KEY

Key for the epoch finish sequence number token.

WAIT_STEP_TOKEN_KEY

Key for the wait step token.

STAKE_TOKEN_KEY

Key for the stake token (amount staked).

OWNER_TOKEN_KEY

Key for the owner wallet address in epoch data.

PREEPOCH_OWNER_TOKEN_KEY

Key for the owner wallet address in preepoch data.

SIGNER_INDEX_KEY

Key for the signer index token.

OWNER_PUBKEY_KEY

Key for the owner's public key token.


Functions

get_epoch_abi() -> tvm_client::abi::Abi

Returns the ABI object for the epoch smart contract interface by wrapping the EPOCH_ABI JSON string.

Usage

let epoch_abi = get_epoch_abi();

get_preepoch_abi() -> tvm_client::abi::Abi

Returns the ABI object for the preepoch smart contract interface by wrapping the PREEPOCH_ABI JSON string.

Usage

let preepoch_abi = get_preepoch_abi();

decode_epoch_data(account: &Account) -> anyhow::Result<Option<(SignerIndex, BlockKeeperData)>>

Decodes epoch data from a blockchain Account object.

Behavior

Example

let epoch_data = decode_epoch_data(&account)?;
if let Some((signer_idx, block_keeper_data)) = epoch_data {
    // Use block_keeper_data and signer_idx
}

decode_preepoch_data(account: &Account) -> anyhow::Result<Option<(SignerIndex, BlockKeeperData)>>

Decodes preepoch data from a blockchain Account object.

Behavior

Example

let preepoch_data = decode_preepoch_data(&account)?;
if let Some((signer_idx, block_keeper_data)) = preepoch_data {
    // Use block_keeper_data and signer_idx for preepoch logic
}

create_epoch_touch_message(data: &BlockKeeperData, time: u32) -> anyhow::Result<Message>

Creates an external inbound message to "touch" (update) an epoch contract.

Behavior

Example

let touch_msg = create_epoch_touch_message(&block_keeper_data, current_time)?;

Implementation Details and Algorithms


Interaction with Other Modules


Data Structures

BlockKeeperData

A struct representing the state of an epoch or preepoch keeper. It contains:


Visual Diagram: File Structure and Function Relationships

flowchart TD
A[Account] -->|get_data()| B[decode_epoch_data]
A -->|get_data()| C[decode_preepoch_data]
B --> D[BlockKeeperData + SignerIndex]
C --> D
D --> E[create_epoch_touch_message]
E --> F[Message]
subgraph ABI
G["get_epoch_abi()"]
H["get_preepoch_abi()"]
end
B -.-> G
C -.-> H
E -.-> G

Usage Notes


For more on blockchain data types, ABI encoding/decoding, and message handling, see Blockchain Account Management and ABI Encoding and Decoding. For details on BLS cryptography, refer to BLS Cryptography.