Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soloseng/dynamically-fetch-epochmanagerenabler-address #11207

23 changes: 7 additions & 16 deletions packages/protocol/contracts-0.8/common/EpochManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ contract EpochManager is
mapping(uint256 => Epoch) private epochs;
mapping(address => uint256) public validatorPendingPayments;

address public carbonOffsettingPartner;
address public epochManagerInitializer;

/**
* @notice Event emited when epochProcessing has begun.
* @param epochNumber The epoch number that is being processed.
Expand All @@ -74,7 +71,10 @@ contract EpochManager is
event EpochProcessingEnded(uint256 indexed epochNumber);

modifier onlyEpochManagerInitializer() {
require(msg.sender == epochManagerInitializer, "msg.sender is not Initializer");
require(
msg.sender == registry.getAddressForOrDie(EPOCH_MANAGER_INITIALIZER_REGISTRY_ID),
"msg.sender is not Initializer"
);
_;
}

Expand All @@ -89,18 +89,10 @@ contract EpochManager is
* @param registryAddress The address of the registry core smart contract.
* @param newEpochDuration The duration of an epoch in seconds.
*/
function initialize(
address registryAddress,
uint256 newEpochDuration,
address _carbonOffsettingPartner,
address _epochManagerInitializer
) external initializer {
require(_epochManagerInitializer != address(0), "EpochManagerInitializer address is required");
function initialize(address registryAddress, uint256 newEpochDuration) external initializer {
_transferOwnership(msg.sender);
setRegistry(registryAddress);
setEpochDuration(newEpochDuration);
carbonOffsettingPartner = _carbonOffsettingPartner;
epochManagerInitializer = _epochManagerInitializer;
}

// DESIGNDESICION(XXX): we assume that the first epoch on the L2 starts as soon as the system is initialized
Expand All @@ -127,7 +119,6 @@ contract EpochManager is
_currentEpoch.startTimestamp = block.timestamp;

elected = firstElected;
epochManagerInitializer = address(0);
}

// TODO maybe "freezeEpochRewards" "prepareForNextEpoch"
Expand Down Expand Up @@ -208,7 +199,7 @@ contract EpochManager is
epochProcessing.totalRewardsCommunity
);
getCeloUnreleasedTreasure().release(
carbonOffsettingPartner,
getEpochRewards().carbonOffsettingPartner(),
epochProcessing.totalRewardsCarbonFund
);
// run elections
Expand Down Expand Up @@ -285,7 +276,7 @@ contract EpochManager is
}

function systemAlreadyInitialized() public view returns (bool) {
return initialized && epochManagerInitializer == address(0);
return initialized;
soloseng marked this conversation as resolved.
Show resolved Hide resolved
}

function allocateValidatorsRewards() internal {
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol/contracts-0.8/common/UsingRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ contract UsingRegistry is Ownable {
bytes32 constant LOCKED_CELO_REGISTRY_ID = keccak256(abi.encodePacked("LockedCelo"));
bytes32 constant CELO_UNRELEASED_TREASURE_REGISTRY_ID =
keccak256(abi.encodePacked("CeloUnreleasedTreasure"));
bytes32 constant EPOCH_MANAGER_INITIALIZER_REGISTRY_ID =
soloseng marked this conversation as resolved.
Show resolved Hide resolved
keccak256(abi.encodePacked("EpochManagerInitializer"));
bytes32 constant EPOCH_MANAGER_REGISTRY_ID = keccak256(abi.encodePacked("EpochManager"));
bytes32 constant SCORE_MANAGER_REGISTRY_ID = keccak256(abi.encodePacked("ScoreManager"));
// solhint-enable state-visibility
Expand Down
Loading