BlockKeeperCoolerContract.sol

Overview

BlockKeeperCoolerContract.sol defines the BlockKeeperCooler smart contract, which manages stake locking, slashing, and reputation updates within a blockchain epoch system. This contract acts as a cooler component associated with BlockKeeperContractRoot and AckiNackiBlockKeeperNodeWallet contracts, facilitating stake control and penalty enforcement for misbehaving nodes or validators.

The contract's main responsibilities include:


Contract: BlockKeeperCooler

State Variables

Variable

Type

Description

version

string

Constant version identifier "1.0.0".

_owner_pubkey

uint256 (static)

Public key of the contract owner (node).

_root

address

Address of the BlockKeeperContractRoot.

_seqNoStart

uint64 (static)

Start sequence number for epoch locking.

_seqNoFinish

uint64

Finish sequence number for epoch locking.

_owner

address

Owner address, typically node wallet.

_stake

uint128

Total stake locked in this cooler contract.

_signerIndex

uint16

Index of the signer in the epoch.

_licenses

LicenseStake[]

Array of licenses and their stakes.

Constructor

constructor (
    uint64 waitStep,
    address owner,
    address root,
    uint16 signerIndex,
    LicenseStake[] licenses,
    uint128 stake,
    bool isContinue,
    uint128 stakeContinue, 
    uint64 epochDurationContinue, 
    uint64 waitStepContinue, 
    bytes bls_pubkeyContinue, 
    uint16 signerIndexContinue, 
    LicenseStake[] licensesContinue, 
    optional(uint128) virtualStakeContinue, 
    uint128 reward_sum_continue,
    string myIp,
    uint32 unixtimeStart,
    uint128 sumReputationCoefContinue,
    optional(string) nodeVersionContinue,
    optional(uint8) slash_type
)
// Deploy a cooler contract for new epoch with initial stake and licenses
new BlockKeeperCooler(
    waitStep,
    ownerAddress,
    rootAddress,
    signerIndex,
    licensesArray,
    stakeAmount,
    false,  // not continuation
    0, 0, 0, "", 0, [], optional(uint128), 0, "192.168.1.1", block.timestamp, 0, optional("1.0.0"), optional(uint8)
);

Private Function: ensureBalance

function ensureBalance() private pure

Public Function: slash

function slash(uint8 slash_type, bool isFromEpoch) public senderOfTwo(_owner, address(this)) accept
// Partial slash with type 50 (50% slash)
myCooler.slash(50, true);

Private Function: slashPartHelper

function slashPartHelper(uint i, uint8 slash_type, uint128 slash_stake) private returns(uint128)

Public Function: touch

function touch() public view senderIs(_owner) accept

Fallback / Receive Function

receive() external

Getter Functions

getDetails

function getDetails() external view returns(
    uint256 pubkey,
    address root, 
    uint64 seqNoStart,
    uint64 seqNoFinish,
    address owner,
    uint16 signerIndex,
    varuint32 NACKLBalance
)

getVersion

function getVersion() external pure returns(string, string)

Implementation Details and Algorithms


Interactions with Other System Components


Data Structures


Diagram: Class Structure of BlockKeeperCooler

classDiagram
class BlockKeeperCooler {
-string version
-uint256 static _owner_pubkey
-address _root
-uint64 static _seqNoStart
-uint64 _seqNoFinish
-address _owner
-uint128 _stake
-uint16 _signerIndex
-LicenseStake[] _licenses
+constructor()
-ensureBalance()
+slash()
-slashPartHelper()
+touch()
+receive()
+getDetails()
+getVersion()
}

This diagram illustrates the BlockKeeperCooler contract's properties and methods, showing the encapsulation of stake and license data alongside the key functions managing slashing and stake lifecycle events.