Skip to content

Commit

Permalink
Split initEpochManager Function (#11199)
Browse files Browse the repository at this point in the history
* ++ contract function

* ++ comment
  • Loading branch information
soloseng authored Sep 11, 2024
1 parent 49a49ed commit 4cbc6d9
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions packages/protocol/contracts-0.8/common/EpochManagerInitializer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import "../../contracts/common/interfaces/ICeloVersionedContract.sol";
import "../../contracts/governance/interfaces/IEpochRewards.sol";

contract EpochManagerInitializer is Initializable, UsingPrecompiles, UsingRegistry {
uint256 public lastKnownEpochNumber;
address[] public lastKnownElectedAccounts;

/**
* @notice Sets initialized == true on implementation contracts
* @param test Set to true to skip implementation initialization
Expand All @@ -27,22 +30,33 @@ contract EpochManagerInitializer is Initializable, UsingPrecompiles, UsingRegist
/**
* @notice initializes the epochManager contract during L2 transition.
*/
function initEpochManager() external onlyOwner {
uint256 currentEpoch = getEpochNumber();
function initEpochManager() external onlyL2 {
require(lastKnownEpochNumber != 0, "lastKnownEpochNumber not set.");
require(lastKnownElectedAccounts.length > 0, "lastKnownElectedAccounts not set.");
getEpochManager().initializeSystem(
lastKnownEpochNumber,
_getFirstBlockOfEpoch(lastKnownEpochNumber),
lastKnownElectedAccounts
);
}

/**
* @notice Stores the last known epochNumber and the related elected validator accounts.
*/
function captureEpochAndValidators() external onlyL1 {
lastKnownEpochNumber = getEpochNumber();

uint256 numberElectedValidators = numberValidatorsInCurrentSet();

address[] memory electedValidatorAddresses = new address[](numberElectedValidators);
lastKnownElectedAccounts = new address[](numberElectedValidators);

for (uint256 i = 0; i < numberElectedValidators; i++) {
address validatorAddress = validatorSignerAddressFromCurrentSet(i);
electedValidatorAddresses[i] = validatorAddress;
// TODO: document how much gas this takes for 110 signers
address validatorAccountAddress = getAccounts().validatorSignerToAccount(
validatorSignerAddressFromCurrentSet(i)
);
lastKnownElectedAccounts[i] = validatorAccountAddress;
}
getEpochManager().initializeSystem(
currentEpoch,
_getFirstBlockOfEpoch(currentEpoch),
electedValidatorAddresses
);
}

function getFirstBlockOfEpoch(uint256 currentEpoch) external view returns (uint256) {
Expand Down

0 comments on commit 4cbc6d9

Please sign in to comment.