Skip to content

Commit

Permalink
Merge branch 'release/core-contracts/12' into soloseng/L2-FeeCurrency…
Browse files Browse the repository at this point in the history
…Directory-test
  • Loading branch information
soloseng committed Dec 16, 2024
2 parents 4f4a917 + dcaf00b commit 75d40e9
Show file tree
Hide file tree
Showing 11 changed files with 365 additions and 158 deletions.
45 changes: 39 additions & 6 deletions packages/protocol/contracts-0.8/common/EpochManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ contract EpochManager is
uint256 delegatedPayment
);

/**
* @notice Emitted when group is marked for processing.
* @param group Address of the group to be processed.
* @param epochNumber The epoch number for which the group gets marked for processing.
*/
event GroupMarkedForProcessing(address indexed group, uint256 indexed epochNumber);

/**
* @notice Emitted when group is processed.
* @param group Address of the processed group.
* @param epochNumber The epoch number for which the group gets processed.
*/
event GroupProcessed(address indexed group, uint256 indexed epochNumber);

/**
* @notice Throws if called by other than EpochManagerEnabler contract.
*/
Expand Down Expand Up @@ -191,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 @@ -245,6 +263,7 @@ contract EpochManager is
groupScore
);
processedGroups[group] = epochRewards == 0 ? type(uint256).max : epochRewards;
emit GroupMarkedForProcessing(group, currentEpochNumber);
}
}
}
Expand Down Expand Up @@ -273,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 All @@ -291,6 +307,8 @@ contract EpochManager is
delete processedGroups[group];
toProcessGroups--;

emit GroupProcessed(group, currentEpochNumber);

if (toProcessGroups == 0) {
_finishEpochHelper(_epochProcessing, election);
}
Expand Down Expand Up @@ -348,6 +366,7 @@ contract EpochManager is
}

delete processedGroups[groups[i]];
emit GroupProcessed(groups[i], currentEpochNumber);
}

_finishEpochHelper(_epochProcessing, election);
Expand Down Expand Up @@ -452,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 @@ -599,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
16 changes: 16 additions & 0 deletions packages/protocol/contracts-0.8/common/FeeCurrencyDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ contract FeeCurrencyDirectory is
mapping(address => CurrencyConfig) public currencies;
address[] private currencyList;

/**
* @notice Emitted when currency config is set.
* @param token Address of the added currency token.
* @param oracle Address of the currency token oracle.
* @param intrinsicGas The intrinsic gas value for transactions.
*/
event CurrencyConfigSet(address indexed token, address indexed oracle, uint256 intrinsicGas);

/**
* @notice Emitted when currency is removed.
* @param token Address of the removed currency token.
*/
event CurrencyRemoved(address indexed token);

constructor(bool test) Initializable(test) {}

/**
Expand Down Expand Up @@ -43,6 +57,7 @@ contract FeeCurrencyDirectory is

currencies[token] = CurrencyConfig({ oracle: oracle, intrinsicGas: intrinsicGas });
currencyList.push(token);
emit CurrencyConfigSet(token, oracle, intrinsicGas);
}

/**
Expand All @@ -58,6 +73,7 @@ contract FeeCurrencyDirectory is
delete currencies[token];
currencyList[index] = currencyList[currencyList.length - 1];
currencyList.pop();
emit CurrencyRemoved(token);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/protocol/contracts/governance/LockedGold.sol
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ contract LockedGold is
_decrementNonvotingAccountBalance(account, maxSlash.sub(difference));
_incrementNonvotingAccountBalance(reporter, reward);
}

_updateDelegatedAmount(account);

address communityFund = registry.getAddressForOrDie(GOVERNANCE_REGISTRY_ID);
address payable communityFundPayable = address(uint160(communityFund));
require(maxSlash.sub(reward) <= address(this).balance, "Inconsistent balance");
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/migrations_sol/MigrationL2.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "forge-std/console.sol";

import "@celo-contracts/common/FixidityLib.sol";
import "@celo-contracts-8/common/UsingRegistry.sol";
import "../../contracts/common/interfaces/IEpochManagerEnabler.sol";
import "@celo-contracts/common/interfaces/IEpochManagerEnabler.sol";

contract MigrationL2 is Script, MigrationsConstants, UsingRegistry {
using FixidityLib for FixidityLib.Fraction;
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol/scripts/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const ProxyContracts = [
'GoldTokenProxy',
'GovernanceApproverMultiSigProxy',
'GovernanceProxy',
'GovernanceSlasherProxy',
'LockedGoldProxy',
'OdisPaymentsProxy',
'RegistryProxy',
Expand Down Expand Up @@ -60,6 +61,7 @@ export const CoreContracts = [
'EpochManager',
'EpochManagerEnabler',
'Governance',
'GovernanceSlasher',
'GovernanceApproverMultiSig',
'BlockchainParameters',
'DoubleSigningSlasher',
Expand Down
59 changes: 58 additions & 1 deletion packages/protocol/test-sol/unit/common/EpochManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ contract EpochManagerTest is Utils08 {
address indexed beneficiary,
uint256 delegatedPayment
);

event EpochProcessingStarted(uint256 indexed epochNumber);
event EpochDurationSet(uint256 indexed newEpochDuration);
event OracleAddressSet(address indexed newOracleAddress);
event GroupMarkedForProcessing(address indexed group, uint256 indexed epochNumber);
event GroupProcessed(address indexed group, uint256 indexed epochNumber);

function setUp() public virtual {
epochManager = new EpochManager_WithMocks();
Expand Down Expand Up @@ -640,6 +641,23 @@ contract EpochManagerTest_finishNextEpochProcess is EpochManagerTest {
assertEq(newElected[i], afterElected[i]);
}
}

function test_Emits_GroupProcessedEvent() public {
(
address[] memory groups,
address[] memory lessers,
address[] memory greaters
) = getGroupsWithLessersAndGreaters();

epochManager.startNextEpochProcess();

for (uint i = 0; i < groups.length; i++) {
vm.expectEmit(true, true, true, true);
emit GroupProcessed(groups[i], firstEpochNumber);
}

epochManager.finishNextEpochProcess(groups, lessers, greaters);
}
}

contract EpochManagerTest_setToProcessGroups is EpochManagerTest {
Expand Down Expand Up @@ -698,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 All @@ -707,6 +743,19 @@ contract EpochManagerTest_setToProcessGroups is EpochManagerTest {
assertEq(EpochManager(address(epochManager)).processedGroups(group), groupEpochRewards);
}
}

function test_Emits_GroupMarkedForProcessingEvent() public {
(address[] memory groups, , ) = getGroupsWithLessersAndGreaters();

epochManager.startNextEpochProcess();

for (uint i = 0; i < groups.length; i++) {
vm.expectEmit(true, true, true, true);
emit GroupMarkedForProcessing(groups[i], firstEpochNumber);
}

epochManager.setToProcessGroups();
}
}

contract EpochManagerTest_processGroup is EpochManagerTest {
Expand Down Expand Up @@ -829,6 +878,14 @@ contract EpochManagerTest_processGroup is EpochManagerTest {
assertEq(signers[i], afterSigners[i]);
}
}

function test_Emits_GroupProcessed() public {
epochManager.startNextEpochProcess();
epochManager.setToProcessGroups();
vm.expectEmit(true, true, true, true);
emit GroupProcessed(group, firstEpochNumber);
epochManager.processGroup(group, address(0), address(0));
}
}

contract EpochManagerTest_getEpochByNumber is EpochManagerTest {
Expand Down
19 changes: 19 additions & 0 deletions packages/protocol/test-sol/unit/common/FeeCurrencyDirectory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ contract FeeCurrencyDirectoryTest is Utils08 {
MockOracle oracle;
address nonOwner;
address owner;
event CurrencyConfigSet(address indexed token, address indexed oracle, uint256 intrinsicGas);
event CurrencyRemoved(address indexed token);

function setUp() public virtual {
super.setUp();
Expand All @@ -38,6 +40,16 @@ contract TestSetCurrencyConfig is FeeCurrencyDirectoryTest {
assertEq(config.intrinsicGas, intrinsicGas);
}

function test_Emits_CurrencyConfigSetEvent() public {
address token = address(1);
uint256 intrinsicGas = 21000;

vm.expectEmit(true, true, true, true);
emit CurrencyConfigSet(token, address(oracle), intrinsicGas);

directory.setCurrencyConfig(token, address(oracle), intrinsicGas);
}

function test_Reverts_WhenNonOwnerSetsCurrencyConfig() public {
address token = address(2);
uint256 intrinsicGas = 21000;
Expand Down Expand Up @@ -83,6 +95,13 @@ contract TestRemoveCurrencies is FeeCurrencyDirectoryTest {
assertEq(config.oracle, address(0));
}

function test_Emits_CurrencyRemovedEvent() public {
address token = address(4);
vm.expectEmit(true, true, true, true);
emit CurrencyRemoved(token);
directory.removeCurrencies(token, 0);
}

function test_Reverts_WhenNonOwnerRemovesCurrencies() public {
address token = address(4);
vm.prank(nonOwner);
Expand Down
Loading

0 comments on commit 75d40e9

Please sign in to comment.