BlockManagerContractRoot.sol


Overview

BlockManagerContractRoot.sol defines the BlockManagerContractRoot smart contract, which acts as the central root contract managing Block Manager Node Wallets within a blockchain network. This contract maintains the lifecycle, configuration, and reward management of block managers, overseeing their deployment, activity tracking, and reward/slashing mechanisms. It also handles the storage and updating of code for various block manager wallet types and interacts closely with AckiNackiBlockManagerNodeWallet contracts and utility libraries like BlockKeeperLib.


Contract: BlockManagerContractRoot

Version

State Variables

Variable

Type

Description

_code

mapping(uint8 => TvmCell)

Stores contract code cells indexed by an ID, used for wallet deployment and upgrades.

_licenseBMRoot

address

Address of the License Block Manager Root contract.

_numberOfActiveBlockManagers

uint128

Current count of active block managers.

_owner_wallet

optional(address)

Optional owner wallet address.

_networkStart

uint32

Timestamp marking the network start time.

_epochDuration

uint64

Duration of an epoch in seconds or blocks (context-dependent).

_waitStep

uint64

Wait step duration used in timing controls.

_prevEpochDuration

uint32

Duration of the previous epoch.

_epochStart

uint32

Timestamp when the current epoch started.

_epochEnd

uint64

Sequence number indicating the epoch end block.

_numberOfActiveBlockManagersAtEpochStart

uint128

Number of active block managers at the start of the current epoch.

_numberOfActiveBlockManagersAtPrevEpochStart

uint128

Number of active block managers at the start of the previous epoch.

_reward_adjustment

uint128

Current reward adjustment factor.

_reward_adjustment_prev_epoch

uint128

Reward adjustment factor from the previous epoch.

_reward_last_time

uint32

Timestamp of the last reward calculation.

_min_reward_period

uint32

Minimum period between reward calculations (default 432000).

_reward_period

uint32

Current reward calculation period.

_calc_reward_num

uint32

Number of reward calculations performed.

_reward_sum

uint128

Sum of all rewards issued.

_slash_sum

uint128

Sum of all slashes applied.

_reward_sum_prev_epoch

uint128

Sum of rewards from the previous epoch.

_is_close_owner

bool

Flag indicating if owner operations are closed.

_walletTouch

uint8

Configuration parameter likely controlling wallet interaction frequency or mode.


Constructor

constructor (
    address licenseBMRoot,
    uint64 epochDuration,
    uint64 waitStep,
    uint128 reward_adjustment,
    uint8 walletTouch
)

Purpose: Initializes the contract with initial network and epoch parameters, reward adjustment, and wallet interaction settings.

Parameters:

Behavior:


Functions

setConfig

function setConfig(
    uint64 epochDuration, 
    uint64 waitStep,
    uint32 reward_period, 
    uint32 min_reward_period, 
    uint32 calc_reward_num, 
    uint8 walletTouch
) public onlyOwner accept

Description: Updates the contract configuration parameters related to epoch duration, wait steps, reward periods, and wallet interaction. Callable only by the owner.

Parameters:

Implementation Details:


setConfigNode

function setConfigNode(
    uint64 epochDuration,
    uint64 waitStep,
    uint32 reward_period,
    uint32 min_reward_period,
    uint32 calc_reward_num,
    uint8 walletTouch
) public senderIs(address(this)) accept

Description: Similar to setConfig but callable only by the contract itself (internal calls).


closeRoot

function closeRoot() public onlyOwner accept

Description: Marks the root owner as closed, preventing further owner-only configuration changes.


setNewCode

function setNewCode(uint8 id, TvmCell code) public senderIs(address(this)) accept

Description: Updates a code cell in the _code mapping, enabling upgrades or changes in wallet contract code.

Parameters:


calcRewardAdjustment

function calcRewardAdjustment() private returns (uint128)

Description: Calculates and updates the reward adjustment factor based on elapsed time, past rewards, and configured parameters.

Implementation Details:


ensureBalance

function ensureBalance() private

Description: Ensures the contract's balance and state are consistent with epoch timing. Handles epoch transitions, reward adjustment recalculation, and triggers minting tokens if balance is low.

Implementation Details:


increaseBM

function increaseBM(uint256 pubkey) public senderIs(BlockKeeperLib.calculateBlockManagerWalletAddress(_code[m_AckiNackiBlockManagerNodeWalletCode], address(this), pubkey)) accept

Description: Increments the number of active block managers. Only callable by a valid block manager wallet identified by its public key.


deployAckiNackiBlockManagerNodeWallet

function deployAckiNackiBlockManagerNodeWallet(
    uint256 pubkey,
    uint256 signerPubkey,
    mapping(uint256 => bool) whiteListLicense
) public accept

Description: Deploys a new AckiNackiBlockManagerNodeWallet contract instance initialized with the provided public keys and license whitelist.

Parameters:

Implementation Details:


slashed

function slashed(uint256 pubkey, bool isWorking) public senderIs(BlockKeeperLib.calculateBlockManagerWalletAddress(_code[m_AckiNackiBlockManagerNodeWalletCode], address(this), pubkey)) accept

Description: Called by block manager wallets to register a slashing event, reducing active block manager count if applicable and updating total slashed sum.

Parameters:


getReward

function getReward(
    uint256 pubkey,
    uint256 sign_pubkey,
    address wallet_address,
    uint32 rewarded,
    uint32 startBM,
    bool isEnd
) public senderIs(BlockKeeperLib.calculateBlockManagerWalletAddress(_code[m_AckiNackiBlockManagerNodeWalletCode], address(this), pubkey)) accept

Description: Processes reward distribution to block managers based on activity, epoch timing, and reward sums.

Parameters:

Implementation Details:


Fallback and Receive Functions

receive() external {}

Getters


Important Implementation Details and Algorithms


Interaction with Other Components


Visual Structure Diagram

classDiagram
class BlockManagerContractRoot {
-mapping(uint8 => TvmCell) _code
-address _licenseBMRoot
-uint128 _numberOfActiveBlockManagers
-optional(address) _owner_wallet
-uint32 _networkStart
-uint64 _epochDuration
-uint64 _waitStep
-uint32 _prevEpochDuration
-uint32 _epochStart
-uint64 _epochEnd
-uint128 _numberOfActiveBlockManagersAtEpochStart
-uint128 _numberOfActiveBlockManagersAtPrevEpochStart
-uint128 _reward_adjustment
-uint128 _reward_adjustment_prev_epoch
-uint32 _reward_last_time
-uint32 _min_reward_period
-uint32 _reward_period
-uint32 _calc_reward_num
-uint128 _reward_sum
-uint128 _slash_sum
-uint128 _reward_sum_prev_epoch
-bool _is_close_owner
-uint8 _walletTouch
+BlockManagerContractRoot()
+setConfig()
+setConfigNode()
+closeRoot()
+setNewCode()
+calcRewardAdjustment()
+ensureBalance()
+increaseBM()
+deployAckiNackiBlockManagerNodeWallet()
+slashed()
+getReward()
+receive()
+getAckiNackiBlockManagerNodeWalletAddress()
+getAckiNackiBlockManagerNodeWalletCode()
+getCodes()
+getDetails()
+getVersion()
}
class AckiNackiBlockManagerNodeWallet
class BlockKeeperLib
BlockManagerContractRoot --> AckiNackiBlockManagerNodeWallet : deploys, interacts
BlockManagerContractRoot ..> BlockKeeperLib : uses utilities
BlockManagerContractRoot --> gosh : calls reward & mint functions

Usage Examples

Deploying a New Block Manager Wallet

// Example call to deploy a new block manager wallet
deployAckiNackiBlockManagerNodeWallet(pubkey, signerPubkey, whiteListLicense);

Updating Contract Configuration

// Owner updates configuration parameters
setConfig(
    86400,       // epochDuration (e.g., 1 day)
    300,         // waitStep (e.g., 5 minutes)
    432000,      // reward_period
    432000,      // min_reward_period
    10,          // calc_reward_num
    200          // walletTouch parameter
);

Requesting Reward

// Called by a block manager wallet to claim rewards
getReward(pubkey, sign_pubkey, wallet_address, rewarded, startBM, isEnd);

Notes on Constants and External Dependencies


This contract is central to the block management system, coordinating wallet deployments, managing epoch-based reward distributions, and maintaining system state with strict access controls and inter-contract communication patterns. For detailed understanding of utility functions and wallet interactions, refer to BlockKeeperLib and AckiNackiBlockManagerNodeWallet subtopics.