From dcaf00b5a942976531ec6953351d122f282c05b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 10 Dec 2024 17:30:16 +0100 Subject: [PATCH] Martinvol/state fix (#11282) --- .../contracts-0.8/common/EpochManager.sol | 27 ++++++++++++++----- .../test-sol/unit/common/EpochManager.t.sol | 18 +++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/packages/protocol/contracts-0.8/common/EpochManager.sol b/packages/protocol/contracts-0.8/common/EpochManager.sol index 5f847e56de..497e5bedcb 100644 --- a/packages/protocol/contracts-0.8/common/EpochManager.sol +++ b/packages/protocol/contracts-0.8/common/EpochManager.sol @@ -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; @@ -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]; @@ -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(); } /** @@ -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. */ diff --git a/packages/protocol/test-sol/unit/common/EpochManager.t.sol b/packages/protocol/test-sol/unit/common/EpochManager.t.sol index b166776750..398d129c45 100644 --- a/packages/protocol/test-sol/unit/common/EpochManager.t.sol +++ b/packages/protocol/test-sol/unit/common/EpochManager.t.sol @@ -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();