From a62806c261c79825ba51bcfe9e8a2ba81c122a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Mon, 7 Oct 2024 13:35:22 +0200 Subject: [PATCH] Brought back some L1/L2 functions --- .../protocol/contracts-0.8/governance/Validators.sol | 6 ++---- .../protocol/contracts/governance/Governance.sol | 12 +++++++++++- .../unit/governance/validators/Validators.t.sol | 7 ++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/protocol/contracts-0.8/governance/Validators.sol b/packages/protocol/contracts-0.8/governance/Validators.sol index b76d91beba3..647847712ce 100644 --- a/packages/protocol/contracts-0.8/governance/Validators.sol +++ b/packages/protocol/contracts-0.8/governance/Validators.sol @@ -162,6 +162,7 @@ contract Validators is address indexed group, uint256 groupPayment ); + event SlashingMultiplierResetPeriodSet(uint256 period); modifier onlySlasher() { require(getLockedGold().isSlasher(msg.sender), "Only registered slasher can call"); @@ -611,7 +612,6 @@ contract Validators is * @param validatorAccount The validator to deaffiliate from their affiliated validator group. */ function forceDeaffiliateIfValidator(address validatorAccount) external nonReentrant onlySlasher { - allowOnlyL1(); // TODO, safe in L1? if (isValidator(validatorAccount)) { Validator storage validator = validators[validatorAccount]; if (validator.affiliation != address(0)) { @@ -640,7 +640,6 @@ contract Validators is * @param account The group being slashed. */ function halveSlashingMultiplier(address account) external nonReentrant onlySlasher { - allowOnlyL1(); // TODO, safe in L1? require(isValidatorGroup(account), "Not a validator group"); ValidatorGroup storage group = groups[account]; group.slashInfo.multiplier = FixidityLib.wrap(group.slashInfo.multiplier.unwrap().div(2)); @@ -1054,9 +1053,8 @@ contract Validators is * @param value New reset period for slashing multiplier. */ function setSlashingMultiplierResetPeriod(uint256 value) public nonReentrant onlyOwner { - allowOnlyL1(); // TODO safe in L2? slashingMultiplierResetPeriod = value; - // TODO emit + emit SlashingMultiplierResetPeriodSet(value); } /** diff --git a/packages/protocol/contracts/governance/Governance.sol b/packages/protocol/contracts/governance/Governance.sol index cb3da2ac0fd..5e67ec0763a 100644 --- a/packages/protocol/contracts/governance/Governance.sol +++ b/packages/protocol/contracts/governance/Governance.sol @@ -1268,6 +1268,15 @@ contract Governance is emit HotfixRecordReset(hash); } + function _getValidatorSignerAddressFromCurrentSet(uint256 index) internal view returns (address) { + if (isL2()) { + // TODO this has getEpochManage() inside the a loop + return getEpochManager().getElectedSigners()[index]; + } else { + return validatorSignerAddressFromCurrentSet(index); + } + } + /** * @notice Returns number of validators from current set which have whitelisted the given hotfix. * @param hash The abi encoded keccak256 hash of the hotfix transaction. @@ -1278,7 +1287,7 @@ contract Governance is uint256 n = numberValidatorsInCurrentSet(); IAccounts accounts = getAccounts(); for (uint256 i = 0; i < n; i = i.add(1)) { - address validatorSigner = validatorSignerAddressFromCurrentSet(i); + address validatorSigner = _getValidatorSignerAddressFromCurrentSet(i); address validatorAccount = accounts.signerToAccount(validatorSigner); if ( isHotfixWhitelistedBy(hash, validatorSigner) || @@ -1296,6 +1305,7 @@ contract Governance is * @return Whether validator whitelist tally >= validator byzantine quorum */ function isHotfixPassing(bytes32 hash) public view onlyL1 returns (bool) { + // TODO minQuorumSizeInCurrentSet should be in hotfix return hotfixWhitelistValidatorTally(hash) >= minQuorumSizeInCurrentSet(); } diff --git a/packages/protocol/test-sol/unit/governance/validators/Validators.t.sol b/packages/protocol/test-sol/unit/governance/validators/Validators.t.sol index 6af19e999b8..39488961e64 100644 --- a/packages/protocol/test-sol/unit/governance/validators/Validators.t.sol +++ b/packages/protocol/test-sol/unit/governance/validators/Validators.t.sol @@ -3639,9 +3639,8 @@ contract ValidatorsTest_ForceDeaffiliateIfValidator is ValidatorsTest { assertEq(entries.length, 0); } - function test_ShouldSendValidatorPayment_WhenL2() public { + function test_ShouldWork_WhenL2() public { _whenL2(); - vm.expectRevert("This method is no longer supported in L2."); vm.prank(paymentDelegatee); validators.forceDeaffiliateIfValidator(validator); } @@ -3806,11 +3805,10 @@ contract ValidatorsTest_HalveSlashingMultiplier is ValidatorsTest { } } - function test_Reverts_HalveSlashingMultiplier_WhenL2() public { + function test_Should_HalveSlashingMultiplier_WhenL2() public { _whenL2(); FixidityLib.Fraction memory expectedMultiplier = FixidityLib.fixed1(); vm.prank(paymentDelegatee); - vm.expectRevert("This method is no longer supported in L2."); validators.halveSlashingMultiplier(group); } @@ -3892,7 +3890,6 @@ contract ValidatorsTest_ResetSlashingMultiplier is ValidatorsTest { function test_Reverts_SetSlashingMultiplierResetPeriod_WhenL2() public { _whenL2(); uint256 newResetPeriod = 10 * DAY; - vm.expectRevert("This method is no longer supported in L2."); validators.setSlashingMultiplierResetPeriod(newResetPeriod); } }