update.rs


Overview

This file provides an extension implementation for the ZeroState struct, enabling the addition and management of blockchain accounts and internal messages within the zero state. It implements key functions to:

The file primarily manipulates low-level blockchain state abstractions such as StateInit, AccountStorage, and Message, relying on cryptographic identifiers like UInt256 and AccountId. It interacts with thread-specific shard states and message queues, ensuring state consistency and message propagation for optimistic execution contexts.


Detailed Descriptions

Impl Block: ZeroState

The implementation block extends the ZeroState struct with several crucial methods that maintain and manipulate blockchain state and messages.


Method: add_account

pub fn add_account<P: AsRef<Path>>(
    &mut self,
    path: P,
    address: Option<String>,
    dapp_id: Option<UInt256>,
    balance: Option<CurrencyCollection>,
    salt: Option<Cell>,
    thread_identifier: &ThreadIdentifier,
) -> anyhow::Result<String>

Purpose

Adds a new blockchain account into the zero state by loading a StateInit from a specified file path, optionally applying a salt to the code cell, and associating the account with a thread-specific shard state.

Parameters

Returns

Usage Example

let account_id = zero_state.add_account(
    "path/to/state_init.boc",
    Some("abcdef1234567890...".to_string()),
    None,
    None,
    None,
    &thread_id,
)?;
println!("Added account with ID: {}", account_id);

Implementation Details


Method: add_message_from_zeroes

pub fn add_message_from_zeroes(
    &mut self,
    dest: String,
    value: Option<u128>,
    ecc: Option<ExtraCurrencyCollection>,
    dapp_id: Option<UInt256>,
    thread_identifier: &ThreadIdentifier,
) -> anyhow::Result<()>

Purpose

Creates and adds an internal message originating from the zero account (all zero address) to a specified destination account within the zero state message queue.

Parameters

Returns

Usage Example

zero_state.add_message_from_zeroes(
    "0123456789abcdef...".to_string(),
    Some(1000000),
    None,
    Some(dapp_id),
    &thread_id,
)?;

Implementation Details


Method: add_message

pub fn add_message(
    &mut self,
    message: Message,
    thread_identifier: &ThreadIdentifier,
) -> anyhow::Result<()>

Purpose

Inserts an internal message into the zero state's message queue for a specified thread, enabling optimistic execution and message tracking.

Parameters

Returns

Usage Example

zero_state.add_message(message, &thread_id)?;

Implementation Details


Method: calculate_block_keeper_wallet_address

pub fn calculate_block_keeper_wallet_address(
    _owner_pubkey: UInt256,
    mut data: StateInit,
) -> anyhow::Result<UInt256>

Purpose

Computes the wallet address hash for a block keeper by salting the StateInit code using the owner's public key and then hashing the updated StateInit.

Parameters

Returns

Usage Example

let wallet_address = ZeroState::calculate_block_keeper_wallet_address(owner_pubkey, state_init)?;

Implementation Details


Method: add_block_keeper

#[allow(clippy::too_many_arguments)]
pub fn add_block_keeper(
    &mut self,
    wallet_address: String,
    pubkey: String,
    epoch_finish_seq_no: u64,
    wait_step: u64,
    stake: BigUint,
    thread_id: ThreadIdentifier,
    signer_index: SignerIndex,
    owner_pubkey: String,
)

Purpose

Registers or updates block keeper metadata within the zero state context, associating cryptographic keys, staking information, and operational status.

Parameters

Usage Example

zero_state.add_block_keeper(
    wallet_addr_str,
    pubkey_str,
    epoch_end,
    wait_step_val,
    stake_amount,
    thread_id,
    signer_idx,
    owner_pubkey_str,
);

Implementation Details


Important Implementation Notes


Interaction with Other Components


Visual Diagram: Class Structure of ZeroState Extension

classDiagram
class ZeroState {
+add_account(path, address, dapp_id, balance, salt, thread_identifier) String
+add_message_from_zeroes(dest, value, ecc, dapp_id, thread_identifier) void
+add_message(message, thread_identifier) void
+calculate_block_keeper_wallet_address(owner_pubkey, data) UInt256
+add_block_keeper(wallet_address, pubkey, epoch_finish_seq_no, wait_step, stake, thread_id, signer_index, owner_pubkey) void
}

This diagram summarizes the methods added to ZeroState by this file, focusing on account and message management as well as block keeper registration.


For further details on concepts like StateInit, Message, and AccountStorage, see State Initialization and Account Management and Message Handling in Blockchain Systems. The cryptographic primitives such as UInt256 and AccountId are detailed in Cryptographic Identifiers.