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

Martinvol/return account instead of signer #11215

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0ddacb1
implemeted with passing test
soloseng Sep 12, 2024
30472a4
merged helper functions
soloseng Sep 17, 2024
6b72a87
Merge branch 'feat/l2-epoch-system' into soloseng/return-account-inst…
soloseng Sep 17, 2024
a14568f
updated test title
soloseng Sep 17, 2024
7a10127
Merge branch 'feat/l2-epoch-system' into soloseng/return-account-inst…
soloseng Sep 17, 2024
870fd83
PR feedback
soloseng Sep 18, 2024
48653d4
Merge branch 'feat/l2-epoch-system' into soloseng/return-account-inst…
soloseng Sep 18, 2024
dd7f66a
revert previous change
soloseng Sep 18, 2024
805c45d
update `sendValidatorPayment()` to use validator account instead of s…
soloseng Sep 18, 2024
c89d799
renamed electValidatorSigner to electValidators on L2.
soloseng Sep 18, 2024
e22300c
added test
soloseng Sep 18, 2024
0623d31
removed onlyL1 modifier
soloseng Sep 18, 2024
1e8abd0
Idea to reduce duplicate code and not break compatibility
martinvol Sep 19, 2024
37c645a
more tests work
martinvol Sep 19, 2024
d25b1dd
test pass
martinvol Sep 20, 2024
f93b948
Changed election mocks with pranks
martinvol Sep 20, 2024
f59e067
Added little optimizations
martinvol Sep 20, 2024
3434ece
TODO
martinvol Sep 20, 2024
c3184cd
nit
martinvol Sep 20, 2024
b1d194a
Generalized WhenL2
martinvol Sep 20, 2024
babea14
updated comment
martinvol Sep 20, 2024
d794788
deleted TODO
martinvol Sep 20, 2024
34953cc
Remove test TODO
martinvol Sep 23, 2024
a905908
Mock Validator supports interface
martinvol Sep 23, 2024
12de46a
Merge branch 'feat/l2-epoch-system' of github.com:celo-org/celo-monor…
martinvol Sep 23, 2024
36c606a
Deleted TODO
martinvol Sep 23, 2024
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
14 changes: 7 additions & 7 deletions packages/protocol/contracts-0.8/common/EpochManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ contract EpochManager is
epochProcessing.totalRewardsCarbonFund
);
// run elections
elected = getElection().electValidatorSigners();
elected = getElection().electValidatorAccounts();
// TODO check how to nullify stuct
epochProcessing.status = EpochProcessStatus.NotStarted;
}
Expand All @@ -248,14 +248,11 @@ contract EpochManager is
* delegation beneficiary.
* @param validator Account of the validator.
*/
function sendValidatorPayment(address validator) external nonReentrant {
IAccounts accounts = IAccounts(getAccounts());
address signer = accounts.getValidatorSigner(validator);

function sendValidatorPayment(address validator) external {
FixidityLib.Fraction memory totalPayment = FixidityLib.newFixed(
validatorPendingPayments[signer]
validatorPendingPayments[validator]
);
validatorPendingPayments[signer] = 0;
validatorPendingPayments[validator] = 0;

IValidators validators = getValidators();
address group = validators.getValidatorsGroup(validator);
Expand Down Expand Up @@ -376,6 +373,9 @@ contract EpochManager is
return initialized && elected.length > 0;
}

/**
* @notice Allocates rewards to elected validator accounts.
*/
function allocateValidatorsRewards() internal {
uint256 totalRewards = 0;
IScoreReader scoreReader = getScoreReader();
Expand Down
20 changes: 17 additions & 3 deletions packages/protocol/contracts-0.8/governance/Validators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import "../../contracts/common/interfaces/ICeloVersionedContract.sol";
import "../../contracts/common/libraries/ReentrancyGuard.sol";
import "../common/interfaces/IStableToken.sol";

import "../../contracts/common/interfaces/IAccounts.sol";

/**
* @title A contract for registering and electing Validator Groups and Validators.
*/
Expand Down Expand Up @@ -712,20 +714,32 @@ contract Validators is
* @notice Returns the top n group members for a particular group.
* @param account The address of the validator group.
* @param n The number of members to return.
* @return The top n group members for a particular group.
* @return The signers of the top n group members for a particular group.
* @dev Returns the account instead of signer on L2.
*/
function getTopGroupValidators(
address account,
uint256 n
) external view returns (address[] memory) {
address[] memory topAccounts = groups[account].members.headN(n);
address[] memory topValidators = new address[](n);

IAccounts accounts = getAccounts();

for (uint256 i = 0; i < n; i = i.add(1)) {
topValidators[i] = getAccounts().getValidatorSigner(topAccounts[i]);
topValidators[i] = accounts.getValidatorSigner(topAccounts[i]);
}
return topValidators;
}

function getTopGroupValidatorsAccounts(
address account,
uint256 n
) external view returns (address[] memory) {
address[] memory topAccounts = groups[account].members.headN(n);
return topAccounts;
}

/**
* @notice Returns the number of members in the provided validator groups.
* @param accounts The addresses of the validator groups.
Expand Down Expand Up @@ -890,7 +904,7 @@ contract Validators is

/**
* @notice Computes epoch payments to the account
* @param account The validator signer of the validator to distribute the epoch payment to.
* @param account The validator account of the validator to distribute the epoch payment to.
* @param maxPayment The maximum payment to the validator. Actual payment is based on score and
* group commission.
* @return The total payment paid to the validator and their group.
Expand Down
62 changes: 51 additions & 11 deletions packages/protocol/contracts/governance/Election.sol
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,23 @@ contract Election is
}

/**
* @notice Returns a list of elected validators with seats allocated to groups via the D'Hondt
* @notice Returns a list of elected validator signers with seats allocated to groups via the D'Hondt
* method.
* @return The list of elected validators.
* @return The list of elected validator signers.
*/
function electValidatorSigners() external view returns (address[] memory) {
return electNValidatorSigners(electableValidators.min, electableValidators.max);
}

/**
* @notice Returns a list of elected validators with seats allocated to groups via the D'Hondt
* method.
* @return The list of elected validators.
*/
function electValidatorAccounts() external view returns (address[] memory) {
return electNValidatorAccounts(electableValidators.min, electableValidators.max);
}

/**
* @notice Returns the total number of votes cast by an account.
* @param account The address of the account.
Expand Down Expand Up @@ -789,16 +798,35 @@ contract Election is
return votes.active.total;
}

function electNValidatorSigners(
uint256 minElectableValidators,
uint256 maxElectableValidators
) public view returns (address[] memory) {
bool accounts = false;
return
_electNValidatorSignerOrAccount(minElectableValidators, maxElectableValidators, accounts);
}

function electNValidatorAccounts(
uint256 minElectableValidators,
uint256 maxElectableValidators
) public view returns (address[] memory) {
bool accounts = true;
return
_electNValidatorSignerOrAccount(minElectableValidators, maxElectableValidators, accounts);
}

/**
* @notice Returns a list of elected validators with seats allocated to groups via the D'Hondt
* @notice Returns a list of elected validator with seats allocated to groups via the D'Hondt
* method.
* @return The list of elected validators.
* @return The list of elected validator signers or accounts depending on input.
* @dev See https://en.wikipedia.org/wiki/D%27Hondt_method#Allocation for more information.
*/
function electNValidatorSigners(
function _electNValidatorSignerOrAccount(
uint256 minElectableValidators,
uint256 maxElectableValidators
) public view returns (address[] memory) {
uint256 maxElectableValidators,
bool accounts // accounts or signers
) internal view returns (address[] memory) {
// Groups must have at least `electabilityThreshold` proportion of the total votes to be
// considered for the election.
uint256 requiredVotes = electabilityThreshold
Expand All @@ -810,6 +838,7 @@ contract Election is
requiredVotes,
maxElectableValidators
);

address[] memory electionGroups = votes.total.eligible.headN(numElectionGroups);
uint256[] memory numMembers = getValidators().getGroupsNumMembers(electionGroups);
// Holds the number of members elected for each of the eligible validator groups.
Expand Down Expand Up @@ -851,12 +880,23 @@ contract Election is
// Grab the top validators from each group that won seats.
address[] memory electedValidators = new address[](totalNumMembersElected);
totalNumMembersElected = 0;

IValidators validators = getValidators();

for (uint256 i = 0; i < electionGroups.length; i = i.add(1)) {
// We use the validating delegate if one is set.
address[] memory electedGroupValidators = getValidators().getTopGroupValidators(
electionGroups[i],
numMembersElected[i]
);
address[] memory electedGroupValidators;
if (accounts) {
electedGroupValidators = validators.getTopGroupValidatorsAccounts(
electionGroups[i],
numMembersElected[i]
);
} else {
electedGroupValidators = validators.getTopGroupValidators(
electionGroups[i],
numMembersElected[i]
);
}
for (uint256 j = 0; j < electedGroupValidators.length; j = j.add(1)) {
electedValidators[totalNumMembersElected] = electedGroupValidators[j];
totalNumMembersElected = totalNumMembersElected.add(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ interface IElection {

// view functions
function electValidatorSigners() external view returns (address[] memory);
function electValidatorAccounts() external view returns (address[] memory);
function electNValidatorSigners(uint256, uint256) external view returns (address[] memory);
function electNValidatorAccounts(uint256, uint256) external view returns (address[] memory);
function getElectableValidators() external view returns (uint256, uint256);
function getElectabilityThreshold() external view returns (uint256);
function getNumVotesReceivable(address) external view returns (uint256);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ interface IValidators {
returns (address[] memory, uint256, uint256, uint256, uint256[] memory, uint256, uint256);
function getGroupNumMembers(address) external view returns (uint256);
function getTopGroupValidators(address, uint256) external view returns (address[] memory);
function getTopGroupValidatorsAccounts(address, uint256) external view returns (address[] memory);
function getGroupsNumMembers(
address[] calldata accounts
) external view returns (uint256[] memory);
Expand Down
7 changes: 5 additions & 2 deletions packages/protocol/contracts/governance/test/MockElection.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract MockElection is IsL2Check {
return true;
}

function activate(address) external onlyL1 returns (bool) {
function activate(address) external returns (bool) {
return true;
}

Expand Down Expand Up @@ -76,7 +76,10 @@ contract MockElection is IsL2Check {
return 0;
}

function electValidatorSigners() external view returns (address[] memory) {
function electValidatorSigners() external view onlyL1 returns (address[] memory) {
return electedValidators;
}
function electValidators() external view onlyL2 returns (address[] memory) {
return electedValidators;
}

Expand Down
Loading
Loading