Skip to content

Commit

Permalink
Brought back some L1/L2 functions
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvol committed Oct 7, 2024
1 parent eccb85e commit a62806c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
6 changes: 2 additions & 4 deletions packages/protocol/contracts-0.8/governance/Validators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion packages/protocol/contracts/governance/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) ||
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}

0 comments on commit a62806c

Please sign in to comment.