Skip to content

Commit

Permalink
Add getters to validator manager
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-vball committed Nov 22, 2024
1 parent aec3442 commit ee44ba6
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 15 deletions.
111 changes: 109 additions & 2 deletions contracts/validator-manager/PoSValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ abstract contract PoSValidatorManager is
revert InvalidStakeMultiplier(maximumStakeMultiplier);
}
// Minimum stake duration should be at least one churn period in order to prevent churn tracker abuse.
if (minimumStakeDuration < _getChurnPeriodSeconds()) {
if (minimumStakeDuration < getChurnPeriodSeconds()) {
revert InvalidMinStakeDuration(minimumStakeDuration);
}
if (weightToValueFactor == 0) {
Expand Down Expand Up @@ -506,6 +506,113 @@ abstract contract PoSValidatorManager is
return uint256(weight) * _getPoSValidatorManagerStorage()._weightToValueFactor;
}

/**
* @notice Returns the minimum stake amount for this contract.
*/
function getMinimumStakeAmount() external view returns (uint256) {
return _getPoSValidatorManagerStorage()._minimumStakeAmount;
}

/**
* @notice Returns the maximum stake amount for this contract.
*/
function getMaximumStakeAmount() external view returns (uint256) {
return _getPoSValidatorManagerStorage()._maximumStakeAmount;
}

/**
* @notice Returns the mininum stake duration for this contract.
*/
function getMinimumStakeDuration() external view returns (uint64) {
return _getPoSValidatorManagerStorage()._minimumStakeDuration;
}

/**
* @notice Returns the mininum delegation fee in bips for this contract.
*/
function getMinimumDelegationFeeBips() external view returns (uint16) {
return _getPoSValidatorManagerStorage()._minimumDelegationFeeBips;
}

/**
* @notice Returns the maximum stake multiplier for this contract.
*/
function getMaximumStakeMultiplier() external view returns (uint64) {
return _getPoSValidatorManagerStorage()._maximumStakeMultiplier;
}

/**
* @notice Returns the weight to value factor for this contract.
*/
function getWeightToValueFactor() external view returns (uint256) {
return _getPoSValidatorManagerStorage()._weightToValueFactor;
}

/**
* @notice Returns the reward calculator address for this contract.
*/
function getRewardCalculatorAddress() external view returns (address) {
return address(_getPoSValidatorManagerStorage()._rewardCalculator);
}

/**
* @notice Returns the uptime blockchain ID for this contract.
*/
function getUptimeBlockchainID() external view returns (bytes32) {
return _getPoSValidatorManagerStorage()._uptimeBlockchainID;
}

/**
* @notice Returns the validator info for the given validation ID.
* @param validationID ID of the validtor being queried.
*/
function getPoSValidatorInfo(bytes32 validationID)
external
view
returns (PoSValidatorInfo memory)
{
return _getPoSValidatorManagerStorage()._posValidatorInfo[validationID];
}

/**
* @notice Returns the delegator info for the given delegation ID.
*/
function getDelegator(bytes32 delegationID) external view returns (Delegator memory) {
return _getPoSValidatorManagerStorage()._delegatorStakes[delegationID];
}

/**
* @notice Returns the rewards immediately redeemable for the given delegation ID.
* @param delegationID ID of the delegator being queried.
*/
function getRedeemableDelegatorRewards(bytes32 delegationID) external view returns (uint256) {
return _getPoSValidatorManagerStorage()._redeemableDelegatorRewards[delegationID];
}

/**
* @notice Returns the rewards recipient for the given delegation ID.
* @param delegationID ID of the delegator being queried.
*/
function getDelegatorRewardRecipient(bytes32 delegationID) external view returns (address) {
return _getPoSValidatorManagerStorage()._delegatorRewardRecipients[delegationID];
}

/**
* @notice Returns the rewards immediately redeemable for the given validation ID.
* @param validationID ID of the validtor being queried.
*/
function getRedeemableValidatorRewards(bytes32 validationID) external view returns (uint256) {
return _getPoSValidatorManagerStorage()._redeemableValidatorRewards[validationID];
}

/**
* @notice Returns the rewards recipient for the given validation ID.
* @param validationID ID of the validtor being queried.
*/
function getValidatorRewardRecipient(bytes32 validationID) external view returns (address) {
return _getPoSValidatorManagerStorage()._rewardRecipients[validationID];
}

/**
* @notice Locks tokens in this contract.
* @param value Number of tokens to lock.
Expand Down Expand Up @@ -882,7 +989,7 @@ abstract contract PoSValidatorManager is

// To prevent churn tracker abuse, check that one full churn period has passed,
// so a delegator may not stake twice in the same churn period.
if (block.timestamp < delegator.startedAt + _getChurnPeriodSeconds()) {
if (block.timestamp < delegator.startedAt + getChurnPeriodSeconds()) {
revert MinStakeDurationNotPassed(uint64(block.timestamp));
}

Expand Down
50 changes: 37 additions & 13 deletions contracts/validator-manager/ValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,6 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
return $._registeredValidators[nodeID];
}

/**
* @notice Returns a validator registered to the given validationID
* @param validationID ID of the validation period associated with the validator
*/
function getValidator(bytes32 validationID) public view returns (Validator memory) {
ValidatorManagerStorage storage $ = _getValidatorManagerStorage();
return $._validationPeriods[validationID];
}

/**
* @notice Begins the process of ending an active validation period. The validation period must have been previously
* started by a successful call to {completeValidatorRegistration} with the given validationID.
Expand Down Expand Up @@ -464,6 +455,22 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
return (validationID, validator);
}

/**
* @notice Returns a validator registered to the given validationID
* @param validationID ID of the validation period associated with the validator
*/
function getValidator(bytes32 validationID) public view returns (Validator memory) {
ValidatorManagerStorage storage $ = _getValidatorManagerStorage();
return $._validationPeriods[validationID];
}

/**
* @notice Returns the churn period for this contractin seconds.
*/
function getChurnPeriodSeconds() public view returns (uint64) {
return _getValidatorManagerStorage()._churnPeriodSeconds;
}

/**
* @notice Returns the validator's weight. This weight is not guaranteed to be known by the P-Chain
* @return Weight of the validator. If the validation ID does not exist, the weight will be 0.
Expand All @@ -472,6 +479,27 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
return getValidator(validationID).weight;
}

/**
* @notice Returns the ID for the subnet this contract is tracking.
*/
function getSubnetID() external view returns (bytes32) {
return _getValidatorManagerStorage()._subnetID;
}

/**
* @notice Returns the maximum churn percentage for this contract.
*/
function getMaximumChurnPercentage() external view returns (uint8) {
return _getValidatorManagerStorage()._maximumChurnPercentage;
}

/**
* @notice Returns the validator churn period information for this contract.
*/
function getValidatorChurnPeriod() external view returns (ValidatorChurnPeriod memory) {
return _getValidatorManagerStorage()._churnTracker;
}

function _incrementAndGetNonce(bytes32 validationID) internal returns (uint64) {
ValidatorManagerStorage storage $ = _getValidatorManagerStorage();
return ++$._validationPeriods[validationID].messageNonce;
Expand Down Expand Up @@ -527,10 +555,6 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
return (nonce, messageID);
}

function _getChurnPeriodSeconds() internal view returns (uint64) {
return _getValidatorManagerStorage()._churnPeriodSeconds;
}

/**
* @dev Helper function to check if the stake weight to be added or removed would exceed the maximum stake churn
* rate for the past churn period. If the churn rate is exceeded, the function will revert. If the churn rate is
Expand Down

0 comments on commit ee44ba6

Please sign in to comment.