BlockKeeperContractRoot.sol

Overview

BlockKeeperContractRoot.sol implements the root contract for managing Block Keeper nodes and their lifecycle within a blockchain network. This contract handles configuration parameters, deployment of node wallets, staking operations, reward and slash calculations, and coordination among related contracts representing different stages of Block Keeper nodes (PreEpoch, Epoch, Cooler). The contract maintains the network state, controls staking thresholds, and facilitates secure interactions using cryptographic keys and indexes.

Contract: BlockKeeperContractRoot

Purpose

Acts as the central controller for Block Keeper node management. It:

State Variables

Variable

Type

Description

version

string constant

Version string of the contract

_notion

string

Inspirational quote string, unrelated to functionality

_code

mapping(uint8 => TvmCell)

Stores code cells for different contract components (wallet, epoch, keys, etc.)

_epochDuration

uint64

Duration of a single epoch in seconds (default 259200)

_epochCliff

uint64

Epoch cliff time calculated from epoch duration

_waitStep

uint64

Wait step time derived from epoch duration

_minBlockKeepers

uint128

Minimum required number of active Block Keeper nodes

_totalStake

uint256

Total stake amount across all active Block Keeper nodes

_licenseRoot

address

Address of the license root contract

_walletTouch

uint8

Wallet touch parameter for controlling interaction

_networkStart

uint32

Timestamp marking the start of the network

_numberOfActiveBlockKeepers

uint128

Current count of active Block Keeper nodes

_block_seqno

uint32

Last processed block sequence number

_numberOfActiveBlockKeepersAtBlockStart

uint128

Number of active Block Keepers at the start of the current block

_needNumberOfActiveBlockKeepers

uint128

Required number of active Block Keepers if enforced

_isNeedNumberOfActiveBlockKeepers

bool

Flag indicating if minimum active Block Keepers requirement is enforced

_reward_sum

uint128

Accumulated reward sum

_slash_sum

uint128

Accumulated slashed stake amount

_nlinit

uint128

Initialization parameter affecting stake calculations

_mbkOld

uint128

Cached parameter used in reward calculations

_is_close_owner

bool

Flag indicating if the contract is closed by the owner

_Gparam

uint256

Global parameter used in reward calculations

_REMparam

uint256

Remainder parameter used in reward calculations

_Bparam

uint32

Parameter reserved for future use

Constructor

constructor(address licenseRoot)

Key Functions and Methods


ensureBalance()

Private function that:

Usage: Called internally before state-changing operations to maintain contract solvency.


calcParams()

Private function to update reward calculation parameters based on elapsed time and total stake.

Usage: Called before adjusting stakes or distributing rewards.


Configuration Functions

Both functions recalculate dependent parameters like _epochCliff and _waitStep.


Deployment Functions


Stake Management Functions


Block Keeper Request Handling


BLS Key and Signer Index Acceptance Callbacks


Utility and Calculation Functions


Getter Functions

Provide external read access to contract parameters, addresses, and codes related to Block Keeper components:


Fallback Function


Important Implementation Details

Interactions with Other Contracts and Libraries

Usage Examples

Deploying a Block Keeper Node Wallet

blockKeeperRoot.deployAckiNackiBlockKeeperNodeWallet(pubkey, whiteListLicense);

Deploys a new node wallet for the given public key and license whitelist, ensuring the whitelist does not exceed the maximum allowed licenses.

Handling a Stake Request from a Node Wallet

blockKeeperRoot.receiveBlockKeeperRequestWithStakeFromWallet(pubkey, bls_pubkey, signerIndex, rep_coef, is_min, ProxyList, myIp, nodeVersion);

Processes a staking request, validates stake against minimum and maximum thresholds, and initiates the creation of BLS and Signer index contracts for the node.

Adjusting Configuration Parameters (Owner Only)

blockKeeperRoot.setConfig(epochDuration, minBlockKeepers, isNeedNumberOfActiveBlockKeepers, needNumberOfActiveBlockKeepers, walletTouch, nlinit);

Updates the contract configuration parameters related to epochs, staking requirements, and wallet behavior.

Mermaid Class Diagram

classDiagram
class BlockKeeperContractRoot {
-string version
-string _notion
-mapping(uint8 => TvmCell) _code
-uint64 _epochDuration
-uint64 _epochCliff
-uint64 _waitStep
-uint128 _minBlockKeepers
-uint256 _totalStake
-address _licenseRoot
-uint8 _walletTouch
-uint32 _networkStart
-uint128 _numberOfActiveBlockKeepers
-uint32 _block_seqno
-uint128 _numberOfActiveBlockKeepersAtBlockStart
-uint128 _needNumberOfActiveBlockKeepers
-bool _isNeedNumberOfActiveBlockKeepers
-uint128 _reward_sum
-uint128 _slash_sum
-uint128 _nlinit
-uint128 _mbkOld
-bool _is_close_owner
-uint256 _Gparam
-uint256 _REMparam
-uint32 _Bparam
+constructor(address)
-ensureBalance()
-calcParams()
+closeRoot()
+setConfig(uint64,uint128,bool,uint128,uint8,uint128)
+setConfigNode(uint64,uint128,bool,uint128,uint8,uint128)
+deployAckiNackiBlockKeeperNodeWallet(uint256,mapping)
+coolerSlash(uint64,uint256)
+decreaseStakes(uint256,uint64,uint128,uint128)
+increaseActiveBlockKeeperNumber(uint256,uint64,uint128,uint128,optional)
+receiveBlockKeeperRequestWithStakeFromWallet(uint256,bytes,uint16,uint128,bool,mapping,string,optional)
+isBLSAccepted(address,uint256,bytes,uint128,bool,uint16,uint128,optional,mapping,string,optional)
+isSignerIndexAccepted(address,uint256,bytes,uint128,bool,uint16,uint128,optional,mapping,string,optional)
+calculateMaxStake(uint128)
+receiveBlockKeeperRequestWithStakeFromWalletContinue(uint256,bytes,uint64,uint16,bool,mapping,uint64,uint128,optional)
+isBLSAcceptedContinue(address,uint256,bytes,uint128,bool,uint64,uint16,optional,mapping,uint128,optional)
+isSignerIndexContinue(address,uint256,bytes,uint128,bool,uint64,uint16,optional,mapping,uint128,optional)
+setNewCode(uint8,TvmCell)
+decreaseActiveBlockKeeper(uint256,uint128,uint64,uint128,optional,uint128,uint256,bool)
-calcBKReward(uint128,uint128,uint128,uint256)
+getBlockKeeperCoolerAddress(uint256,uint64)
+getAckiNackiBlockKeeperNodeWalletAddress(uint256)
+getAckiNackiBlockKeeperNodeWalletCode()
+getBlockKeeperEpochCode()
+getBlockKeeperEpochAddress(uint256,uint64)
+getBlockKeeperPreEpochAddress(uint256,uint64)
+getDetails()
+getEpochCodeHash()
+getPreEpochCodeHash()
+getRewardOut(uint128,uint128,uint256,uint128)
+getProxyListCode()
+getProxyListAddress(uint256)
+getRewardNow(uint128,uint128)
+getMinStakeNow()
+getMaxStakeNow()
+getConfig()
+getSignerIndexAddress(uint16)
+getMinStakeOut(uint128,uint128,uint128,uint128)
+getBLSIndexAddress(bytes)
+getCodes()
+getVersion()
}

This diagram shows the BlockKeeperContractRoot contract with its state variables and public/private methods, highlighting the comprehensive functionality encapsulated in this root contract.