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

EpochManager e2e tests add/remove validators between ecpochs #11214

Merged
merged 7 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/protocol/contracts-0.8/common/EpochManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ contract EpochManager is
epochs[currentEpochNumber].firstBlock = block.number;
epochs[currentEpochNumber].startTimestamp = block.timestamp;

epochProcessing.toProcessGroups = 0;

for (uint i = 0; i < elected.length; i++) {
address group = getValidators().getValidatorsGroup(elected[i]);
if (!processedGroups[group].processed) {
Expand All @@ -213,9 +215,7 @@ contract EpochManager is

require(epochProcessing.toProcessGroups == groups.length, "number of groups does not match");

// since we are adding values it makes sense to start from the end
for (uint ii = groups.length; ii > 0; ii--) {
uint256 i = ii - 1;
for (uint i = 0; i < groups.length; i++) {
martinvol marked this conversation as resolved.
Show resolved Hide resolved
ProcessedGroup storage processedGroup = processedGroups[groups[i]];
// checks that group is actually from elected group
require(processedGroup.processed, "group not processed");
Expand All @@ -226,7 +226,6 @@ contract EpochManager is
greaters[i]
);

epochProcessing.toProcessGroups = 0;
delete processedGroups[groups[i]];
}
getCeloUnreleasedTreasure().release(
Expand Down
3 changes: 0 additions & 3 deletions packages/protocol/contracts-0.8/governance/Validators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ contract Validators is
* @dev De-affiliates with the previously affiliated group if present.
*/
function affiliate(address group) external nonReentrant returns (bool) {
allowOnlyL1();
address account = getAccounts().validatorSignerToAccount(msg.sender);
require(isValidator(account), "Not a validator");
require(isValidatorGroup(group), "Not a validator group");
Expand Down Expand Up @@ -509,7 +508,6 @@ contract Validators is
* @dev Fails if the group has zero members.
*/
function addMember(address validator) external nonReentrant returns (bool) {
allowOnlyL1();
address account = getAccounts().validatorSignerToAccount(msg.sender);
require(groups[account].members.numElements > 0, "Validator group empty");
return _addMember(account, validator, address(0), address(0));
Expand All @@ -529,7 +527,6 @@ contract Validators is
address lesser,
address greater
) external nonReentrant returns (bool) {
allowOnlyL1();
address account = getAccounts().validatorSignerToAccount(msg.sender);
require(groups[account].members.numElements == 0, "Validator group not empty");
return _addMember(account, validator, lesser, greater);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ interface IElection {
function hasActivatablePendingVotes(address, address) external view returns (bool);
function validatorSignerAddressFromCurrentSet(uint256 index) external view returns (address);
function numberValidatorsInCurrentSet() external view returns (uint256);
function owner() external view returns (address);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface ILockedCelo {
) external;
function addSlasher(string calldata slasherIdentifier) external;

function getAccountNonvotingLockedGold(address account) external view returns (uint256);
function getAccountTotalLockedCelo(address) external view returns (uint256);
function getTotalLockedCelo() external view returns (uint256);
function getPendingWithdrawals(
Expand Down
3 changes: 2 additions & 1 deletion packages/protocol/scripts/foundry/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export LIBRARY_DEPENDENCIES_PATH=(
"lib/openzeppelin-contracts/contracts/math/SafeMath.sol"
"lib/openzeppelin-contracts8/contracts/utils/math/SafeMath.sol"
"lib/openzeppelin-contracts/contracts/math/Math.sol"
"lib/openzeppelin-contracts/contracts/cryptography/ECDSA.sol"
"lib/openzeppelin-contracts/contracts/cryptography/ECDSA.sol"
"lib/openzeppelin-contracts/contracts/utils/Address.sol"
"lib/solidity-bytes-utils/contracts/BytesLib.sol"
"lib/celo-foundry/lib/forge-std/src/console.sol"
)
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ forge script \
$LIBRARY_FLAGS \
--rpc-url $ANVIL_RPC_URL || { echo "Migration script failed"; exit 1; }

CELO_EPOCH_REWARDS_ADDRESS=$(
cast call \
$REGISTRY_ADDRESS \
"getAddressForStringOrDie(string calldata identifier)(address)" \
"EpochRewards" \
--rpc-url $ANVIL_RPC_URL
)

echo "Setting storage of EpochRewards start time to same value as on mainnet"
# Storage slot of start time is 2 and the value is 1587587214 which is identical to mainnet
cast rpc \
anvil_setStorageAt \
$CELO_EPOCH_REWARDS_ADDRESS 2 "0x000000000000000000000000000000000000000000000000000000005ea0a88e" \
--rpc-url $ANVIL_RPC_URL

# Keeping track of the finish time to measure how long it takes to run the script entirely
ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo "Migration script total elapsed time: $ELAPSED_TIME seconds"
Expand Down
Loading
Loading