Skip to content

Commit

Permalink
Enforce active status in getActiveSet (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
jterzis authored May 24, 2024
1 parent a61fd0f commit 88f8b98
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ contract RewardsDistribution is
NodeOperatorStatus currentStatus = nos.statusByOperator[operator];

if (
currentStatus == NodeOperatorStatus.Approved &&
currentStatus == NodeOperatorStatus.Active &&
_isActiveSinceLastCycle(nos.approvalTimeByOperator[operator])
) {
expectedOperators[i] = operator;
Expand Down
12 changes: 10 additions & 2 deletions contracts/src/base/registry/facets/operator/NodeOperatorFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ contract NodeOperatorFacet is INodeOperator, OwnableBase, ERC721ABase, Facet {
// Check for valid newStatus transitions
// Exiting -> Standby
// Standby -> Approved
// Approved -> Exiting
// Approved -> Exiting || Active
// Active -> Exiting || Approved
if (
currentStatus == NodeOperatorStatus.Exiting &&
newStatus != NodeOperatorStatus.Standby
Expand All @@ -85,7 +86,14 @@ contract NodeOperatorFacet is INodeOperator, OwnableBase, ERC721ABase, Facet {
revert NodeOperator__InvalidStatusTransition();
} else if (
currentStatus == NodeOperatorStatus.Approved &&
newStatus != NodeOperatorStatus.Exiting
(newStatus != NodeOperatorStatus.Exiting &&
newStatus != NodeOperatorStatus.Active)
) {
revert NodeOperator__InvalidStatusTransition();
} else if (
currentStatus == NodeOperatorStatus.Active &&
(newStatus != NodeOperatorStatus.Exiting &&
newStatus != NodeOperatorStatus.Approved)
) {
revert NodeOperator__InvalidStatusTransition();
}
Expand Down
8 changes: 5 additions & 3 deletions contracts/test/base/registry/RewardsDistribution.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ contract RewardsDistributionTest is
internal
givenOperatorsHaveRegistered(operators)
givenOperatorsHaveCommissionRates(operators)
givenOperatorsHaveBeenApproved(operators)
givenOperatorsAreActive(operators)
{}

function setupUsersAndDelegation(
Expand Down Expand Up @@ -1388,14 +1388,16 @@ contract RewardsDistributionTest is
_;
}

modifier givenOperatorHasBeenApproved(address _operator) {
modifier givenOperatorIsActive(address _operator) {
setOperatorStatus(_operator, NodeOperatorStatus.Approved);
setOperatorStatus(_operator, NodeOperatorStatus.Active);
_;
}

modifier givenOperatorsHaveBeenApproved(Entity[] memory operators) {
modifier givenOperatorsAreActive(Entity[] memory operators) {
for (uint256 i = 0; i < operators.length; i++) {
setOperatorStatus(operators[i].addr, NodeOperatorStatus.Approved);
setOperatorStatus(operators[i].addr, NodeOperatorStatus.Active);
}
_;
}
Expand Down

0 comments on commit 88f8b98

Please sign in to comment.