diff --git a/contracts/interfaces/validator/info-fragments/IValidatorInfoV2.sol b/contracts/interfaces/validator/info-fragments/IValidatorInfoV2.sol index 1d73cfd5f..ee6feda3d 100644 --- a/contracts/interfaces/validator/info-fragments/IValidatorInfoV2.sol +++ b/contracts/interfaces/validator/info-fragments/IValidatorInfoV2.sol @@ -26,12 +26,22 @@ interface IValidatorInfoV2 { /** * @dev Returns the current validator list. */ - function getValidators() external view returns (address[] memory _validatorList); + function getValidators() external view returns (TConsensus[] memory validatorList); + + /** + * @dev Returns the ids of current validator list. + */ + function getValidatorIds() external view returns (address[] memory cids); /** * @dev Returns the current block producer list. */ - function getBlockProducers() external view returns (address[] memory); + function getBlockProducers() external view returns (TConsensus[] memory consensusList); + + /** + * @dev Returns the ids current block producer list. + */ + function getBlockProducerIds() external view returns (address[] memory cids); /** * @dev Returns whether the address is block producer or not. diff --git a/contracts/mocks/validator/MockValidatorSet.sol b/contracts/mocks/validator/MockValidatorSet.sol index fcc231361..6058cae2f 100644 --- a/contracts/mocks/validator/MockValidatorSet.sol +++ b/contracts/mocks/validator/MockValidatorSet.sol @@ -59,7 +59,9 @@ contract MockValidatorSet is function epochOf(uint256 _block) external view override returns (uint256) {} - function getValidators() external view override returns (address[] memory) {} + function getValidators() external view override returns (TConsensus[] memory) {} + + function getValidatorIds() external view override returns (address[] memory) {} function epochEndingAt(uint256 _block) external view override returns (bool) {} @@ -84,7 +86,9 @@ contract MockValidatorSet is return _numberOfBlocksInEpoch; } - function getBlockProducers() external view override returns (address[] memory) {} + function getBlockProducers() external view override returns (TConsensus[] memory) {} + + function getBlockProducerIds() external view override returns (address[] memory) {} function isBlockProducer(TConsensus) external pure override returns (bool) { return true; @@ -125,6 +129,10 @@ contract MockValidatorSet is return IProfile(getContract(ContractType.PROFILE)).getManyConsensus2Id(consensusAddrs); } + function __cid2cssBatch(address[] memory cids) internal view override returns (TConsensus[] memory) { + return IProfile(getContract(ContractType.PROFILE)).getManyId2Consensus(cids); + } + function execReleaseLockedFundForEmergencyExitRequest( address _candidateId, address payable _recipient diff --git a/contracts/ronin/Maintenance.sol b/contracts/ronin/Maintenance.sol index 072f33ee3..90296a13d 100644 --- a/contracts/ronin/Maintenance.sol +++ b/contracts/ronin/Maintenance.sol @@ -261,7 +261,7 @@ contract Maintenance is IMaintenance, HasContracts, HasValidatorDeprecated, Init * @inheritdoc IMaintenance */ function totalSchedule() public view override returns (uint256 count) { - address[] memory validatorIds = IRoninValidatorSet(getContract(ContractType.VALIDATOR)).getValidators(); + address[] memory validatorIds = IRoninValidatorSet(getContract(ContractType.VALIDATOR)).getValidatorIds(); unchecked { for (uint i = 0; i < validatorIds.length; i++) { if (_checkScheduledById(validatorIds[i])) { diff --git a/contracts/ronin/validator/CandidateManager.sol b/contracts/ronin/validator/CandidateManager.sol index c5d94e639..5423ff27b 100644 --- a/contracts/ronin/validator/CandidateManager.sol +++ b/contracts/ronin/validator/CandidateManager.sol @@ -107,7 +107,7 @@ abstract contract CandidateManager is * @inheritdoc ICandidateManager */ function getValidatorCandidates() external view override returns (TConsensus[] memory) { - return IProfile(getContract(ContractType.PROFILE)).getManyId2Consensus(_candidateIds); + return __cid2cssBatch(getValidatorCandidateIds()); } /** @@ -285,4 +285,7 @@ abstract contract CandidateManager is /// @dev See {RoninValidatorSet-__css2cidBatch} function __css2cidBatch(TConsensus[] memory consensusAddrs) internal view virtual returns (address[] memory); + + /// @dev See {RoninValidatorSet-__cid2cssBatch} + function __cid2cssBatch(address[] memory cids) internal view virtual returns (TConsensus[] memory); } diff --git a/contracts/ronin/validator/CoinbaseExecution.sol b/contracts/ronin/validator/CoinbaseExecution.sol index 561a0a42e..d2f96237f 100644 --- a/contracts/ronin/validator/CoinbaseExecution.sol +++ b/contracts/ronin/validator/CoinbaseExecution.sol @@ -111,7 +111,7 @@ abstract contract CoinbaseExecution is uint256 newPeriod = _computePeriod(block.timestamp); bool periodEnding = _isPeriodEnding(newPeriod); - address[] memory currValidatorIds = getValidators(); + address[] memory currValidatorIds = getValidatorIds(); address[] memory revokedCandidateIds; uint256 epoch = epochOf(block.number); uint256 nextEpoch = epoch + 1; @@ -410,7 +410,7 @@ abstract contract CoinbaseExecution is ++_i; } } - emit BlockProducerSetUpdated(_newPeriod, _nextEpoch, getBlockProducers()); + emit BlockProducerSetUpdated(_newPeriod, _nextEpoch, getBlockProducerIds()); } /** diff --git a/contracts/ronin/validator/EmergencyExit.sol b/contracts/ronin/validator/EmergencyExit.sol index 80834b1a6..27a22e7b1 100644 --- a/contracts/ronin/validator/EmergencyExit.sol +++ b/contracts/ronin/validator/EmergencyExit.sol @@ -165,6 +165,11 @@ abstract contract EmergencyExit is IEmergencyExit, RONTransferHelper, CandidateM TConsensus[] memory consensusAddrs ) internal view virtual override(CandidateManager, CommonStorage) returns (address[] memory); + /// @dev See {RoninValidatorSet-__cid2cssBatch} + function __cid2cssBatch( + address[] memory cids + ) internal view virtual override(CandidateManager, ValidatorInfoStorageV2) returns (TConsensus[] memory); + /** * @dev See `setEmergencyExitLockedAmount. */ diff --git a/contracts/ronin/validator/RoninValidatorSet.sol b/contracts/ronin/validator/RoninValidatorSet.sol index 1ad33e606..fe7d79970 100644 --- a/contracts/ronin/validator/RoninValidatorSet.sol +++ b/contracts/ronin/validator/RoninValidatorSet.sol @@ -102,4 +102,13 @@ contract RoninValidatorSet is Initializable, CoinbaseExecution, SlashingExecutio ) internal view override(EmergencyExit, CommonStorage) returns (address[] memory) { return IProfile(getContract(ContractType.PROFILE)).getManyConsensus2Id(consensusAddrs); } + + /** + * @dev Convert many id to corresponding consensus addresses from the Profile contract. + */ + function __cid2cssBatch( + address[] memory cids + ) internal view override(EmergencyExit, ValidatorInfoStorageV2) returns (TConsensus[] memory) { + return IProfile(getContract(ContractType.PROFILE)).getManyId2Consensus(cids); + } } diff --git a/contracts/ronin/validator/storage-fragments/ValidatorInfoStorageV2.sol b/contracts/ronin/validator/storage-fragments/ValidatorInfoStorageV2.sol index aacfa19e1..623a70df0 100644 --- a/contracts/ronin/validator/storage-fragments/ValidatorInfoStorageV2.sol +++ b/contracts/ronin/validator/storage-fragments/ValidatorInfoStorageV2.sol @@ -37,12 +37,19 @@ abstract contract ValidatorInfoStorageV2 is IValidatorInfoV2, HasContracts, HasT /** * @inheritdoc IValidatorInfoV2 */ - function getValidators() public view override returns (address[] memory validatorList_) { - validatorList_ = new address[](_validatorCount); + function getValidators() public view override returns (TConsensus[] memory consensusList) { + return __cid2cssBatch(getValidatorIds()); + } + + /** + * @inheritdoc IValidatorInfoV2 + */ + function getValidatorIds() public view override returns (address[] memory cids) { + cids = new address[](_validatorCount); address iValidator; - for (uint i; i < validatorList_.length; ) { + for (uint i; i < cids.length; ) { iValidator = _validatorIds[i]; - validatorList_[i] = iValidator; + cids[i] = iValidator; unchecked { ++i; @@ -53,13 +60,20 @@ abstract contract ValidatorInfoStorageV2 is IValidatorInfoV2, HasContracts, HasT /** * @inheritdoc IValidatorInfoV2 */ - function getBlockProducers() public view override returns (address[] memory result) { - result = new address[](_validatorCount); + function getBlockProducers() public view override returns (TConsensus[] memory consensusList) { + return __cid2cssBatch(getBlockProducerIds()); + } + + /** + * @inheritdoc IValidatorInfoV2 + */ + function getBlockProducerIds() public view override returns (address[] memory cids) { + cids = new address[](_validatorCount); uint256 count = 0; - for (uint i; i < result.length; ) { + for (uint i; i < cids.length; ) { address validatorId = _validatorIds[i]; if (_isBlockProducerById(validatorId)) { - result[count++] = validatorId; + cids[count++] = validatorId; } unchecked { @@ -68,7 +82,7 @@ abstract contract ValidatorInfoStorageV2 is IValidatorInfoV2, HasContracts, HasT } assembly { - mstore(result, count) + mstore(cids, count) } } @@ -146,4 +160,7 @@ abstract contract ValidatorInfoStorageV2 is IValidatorInfoV2, HasContracts, HasT /// @dev See {RoninValidatorSet-__css2cidBatch} function __css2cidBatch(TConsensus[] memory consensusAddrs) internal view virtual returns (address[] memory); + + /// @dev See {RoninValidatorSet-__cid2cssBatch} + function __cid2cssBatch(address[] memory cids) internal view virtual returns (TConsensus[] memory); }