Skip to content

Commit

Permalink
Martinvol/state fix (#11282)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvol authored Dec 10, 2024
1 parent 682235e commit dcaf00b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
27 changes: 21 additions & 6 deletions packages/protocol/contracts-0.8/common/EpochManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ contract EpochManager is
*/
function startNextEpochProcess() external nonReentrant onlySystemAlreadyInitialized {
require(isTimeForNextEpoch(), "Epoch is not ready to start");
require(!isOnEpochProcess(), "Epoch process is already started");
require(
epochProcessing.status == EpochProcessStatus.NotStarted,
"Epoch process is already started"
);
require(!isEpochProcessingStarted(), "Epoch process is already started");

epochProcessing.status = EpochProcessStatus.Started;
epochs[currentEpochNumber].rewardsBlock = block.number;
Expand Down Expand Up @@ -288,10 +292,7 @@ contract EpochManager is
*/
function processGroup(address group, address lesser, address greater) public {
EpochProcessState storage _epochProcessing = epochProcessing;
require(
_epochProcessing.status == EpochProcessStatus.IndivudualGroupsProcessing,
"Indivudual epoch process is not started"
);
require(isIndividualProcessing(), "Indivudual epoch process is not started");
require(toProcessGroups > 0, "no more groups to process");

uint256 epochRewards = processedGroups[group];
Expand Down Expand Up @@ -470,7 +471,7 @@ contract EpochManager is
* @return Whether or not the blockable functions are blocked.
*/
function isBlocked() external view returns (bool) {
return isOnEpochProcess();
return isEpochProcessingStarted();
}

/**
Expand Down Expand Up @@ -617,6 +618,20 @@ contract EpochManager is
emit OracleAddressSet(newOracleAddress);
}

/**
* @return Whether epoch is being processed by individualy group by group.
*/
function isIndividualProcessing() public view returns (bool) {
return epochProcessing.status == EpochProcessStatus.IndivudualGroupsProcessing;
}

/**
* @return Whether epoch process has been started.
*/
function isEpochProcessingStarted() public view returns (bool) {
return isOnEpochProcess() || isIndividualProcessing();
}

/**
* @return Whether or not the next epoch can be processed.
*/
Expand Down
18 changes: 18 additions & 0 deletions packages/protocol/test-sol/unit/common/EpochManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,24 @@ contract EpochManagerTest_setToProcessGroups is EpochManagerTest {
assertEq(EpochManager(address(epochManager)).toProcessGroups(), groups.length);
}

function test_blocksChilds() public {
epochManager.startNextEpochProcess();
epochManager.setToProcessGroups();
assertTrue(epochManager.isBlocked());
}

function test_Reverts_startEpochAgain() public {
epochManager.startNextEpochProcess();
epochManager.setToProcessGroups();
vm.expectRevert("Epoch process is already started");
epochManager.startNextEpochProcess();
}

function test_Reverts_WhenSetToProcessGroups() public {
vm.expectRevert("Epoch process is not started");
epochManager.setToProcessGroups();
}

function test_setsGroupRewards() public {
(address[] memory groups, , ) = getGroupsWithLessersAndGreaters();
epochManager.startNextEpochProcess();
Expand Down

0 comments on commit dcaf00b

Please sign in to comment.