ValidatorManagerLib
Library for managing validator storage
*This library is used by the Infrared contract for:
- Adding and removing validators (to the set of validators and distributor contract)
- Queuing/Activating Boosts and Drop/Activate Boosts in BGT contract: https://github.com/berachain/contracts-monorepo/blob/main/src/pol/BGT.sol
- Getting the number of validators
- Checking if validator is an Infrared validator*
Ownership of Operator rewards is tied to the number of validators an operator has, which should be linear to their operating costs hence share of fees. ie if an operator has 10 validators and total validators is 100, they should receive 10% of the fees even if Effective Balances are not super equal.
Functions
isValidator
Checks if a validator is an Infrared validator, ie if the validator ID is in the set of validator IDs
function isValidator(ValidatorStorage storage $, bytes memory pubkey)
external
view
returns (bool);
Parameters
Name | Type | Description |
---|---|---|
$ | ValidatorStorage | Storage pinter for validator storage |
pubkey | bytes | The CL pubkey of validator |
_getValidatorId
Gets the validator ID for associated CL pubkey
function _getValidatorId(bytes memory pubkey) internal pure returns (bytes32);
Parameters
Name | Type | Description |
---|---|---|
pubkey | bytes | The CL pubkey of validator |
addValidators
Adds validator to the set of validators, and maps the validator ID to the public key.
Also adds the validator to a public key set in the distributor contract, for receiving operator rewards. (ie Commissions for running nodeds).address
function addValidators(
ValidatorStorage storage $,
address distributor,
ValidatorTypes.Validator[] memory _validators
) external;
Parameters
Name | Type | Description |
---|---|---|
$ | ValidatorStorage | Storage pointer to the validator storage |
distributor | address | address of the distributor contract |
_validators | ValidatorTypes.Validator[] | array of Validator structs containing the CL public key and address of the validator and their associated fee collecting address |
removeValidators
Removes validators from the set of validators and also removes the validator from the distributor contract.
function removeValidators(
ValidatorStorage storage $,
address distributor,
bytes[] memory _pubkeys
) external;
replaceValidator
Replaces a validator in the set of validators and also updates the validator in the distributor contract.
function replaceValidator(
ValidatorStorage storage $,
address distributor,
bytes calldata _current,
bytes calldata _new
) external;
Parameters
Name | Type | Description |
---|---|---|
$ | ValidatorStorage | Storage pointer to the validator storage |
distributor | address | address of the distributor contract |
_current | bytes | Public key of the current validator |
_new | bytes | Public key of the new validator |
queueBoosts
Queues boosts for validators in the BGT smart contract
The sum of the boosts must be less than or equal to the total supply of iBGT
function queueBoosts(
ValidatorStorage storage $,
address bgt,
address ibgt,
bytes[] memory _pubkeys,
uint128[] memory _amts
) external;
Parameters
Name | Type | Description |
---|---|---|
$ | ValidatorStorage | Storage pointer to the validator storage |
bgt | address | address of the BGT contract |
ibgt | address | |
_pubkeys | bytes[] | array of public keys of validators |
_amts | uint128[] | array of amounts of boosts to queue |
cancelBoosts
Cancels boosts for validators in the BGT smart contract before they are activated
function cancelBoosts(
address bgt,
bytes[] memory _pubkeys,
uint128[] memory _amts
) external;
Parameters
Name | Type | Description |
---|---|---|
bgt | address | address of the BGT contract |
_pubkeys | bytes[] | array of public keys of validators |
_amts | uint128[] | array of amounts of boosts to cancel |
activateBoosts
Activates boosts for validators in the BGT smart contract
function activateBoosts(
ValidatorStorage storage $,
address bgt,
bytes[] memory _pubkeys
) external;
Parameters
Name | Type | Description |
---|---|---|
$ | ValidatorStorage | Storage pointer to the validator storage |
bgt | address | address of the BGT contract |
_pubkeys | bytes[] | array of public keys of validators |
queueDropBoosts
Queues to drop the boosts for validators in the BGT smart contract
function queueDropBoosts(
address bgt,
bytes[] memory _pubkeys,
uint128[] memory _amts
) external;
Parameters
Name | Type | Description |
---|---|---|
bgt | address | address of the BGT contract |
_pubkeys | bytes[] | array of public keys of validators |
_amts | uint128[] | array of amounts of boosts to drop |
cancelDropBoosts
Cancels drop boosts for validators in the BGT smart contract before they are activated
function cancelDropBoosts(
ValidatorStorage storage $,
address bgt,
bytes[] memory _pubkeys,
uint128[] memory _amts
) external;
Parameters
Name | Type | Description |
---|---|---|
$ | ValidatorStorage | Storage pointer to the validator storage |
bgt | address | address of the BGT contract |
_pubkeys | bytes[] | array of public keys of validators |
_amts | uint128[] | array of amounts of boosts to cancel |
dropBoosts
Activates drop boosts for validators in the BGT smart contract
function dropBoosts(address bgt, bytes[] memory _pubkeys) external;
Parameters
Name | Type | Description |
---|---|---|
bgt | address | address of the BGT contract |
_pubkeys | bytes[] | array of public keys of validators |
infraredValidators
Returns the list of validators in the validator storage
function infraredValidators(ValidatorStorage storage $, address distributor)
external
view
returns (ValidatorTypes.Validator[] memory validators);
Parameters
Name | Type | Description |
---|---|---|
$ | ValidatorStorage | Storage pointer to the validator storage |
distributor | address | address of the distributor contract |
Returns
Name | Type | Description |
---|---|---|
validators | ValidatorTypes.Validator[] | array of Validator structs containing the CL public key and address of the validators fee collecting address |
numInfraredValidators
Returns the number of validators in the validator storage
function numInfraredValidators(ValidatorStorage storage $)
external
view
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
$ | ValidatorStorage | Storage pointer to the validator storage |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | number of validators |
_getValidatorAddress
helper function to get the vlaidator fee collecting address via the CL pubkey
function _getValidatorAddress(address distributor, bytes memory pubkey)
internal
view
returns (address);
Parameters
Name | Type | Description |
---|---|---|
distributor | address | address of the distributor contract |
pubkey | bytes | CL pubkey of the validator |
Returns
Name | Type | Description |
---|---|---|
<none> | address | address of the validator fee collecting address |
Structs
ValidatorStorage
Storage structure for validator storage
This structure is used to store validator IDs and public keys
struct ValidatorStorage {
EnumerableSet.Bytes32Set validatorIds;
mapping(bytes32 => bytes) validatorPubkeys;
}
Properties
Name | Type | Description |
---|---|---|
validatorIds | EnumerableSet.Bytes32Set | Set of validator IDs which are keccak256 hashes of public keys. |
validatorPubkeys | mapping(bytes32 => bytes) | Maps validator ID to public key |