Skip to content

Commit 1cafa6a

Browse files
authored
feat(Profile): allow change consensus address (#236)
* restructure * add profile contract * add storage log * fix staking test * fix fixture * Revert "fix fixture" This reverts commit f53277e. * fix hardhat deploy path * fix deploy script * rollback initializerV1 * restructure profile contract * fix fixture * fix dependent test * fix dependent test * fix: profile execApply * fix hardhat deploy src path * rollback NON_VALIDATOR slash type * follow new code convention * feat: support change admin address * fix: inheritance graph * fix: fix test setup * add dev comment * fix rebase issue * rename for convention * add enum for custom error * udvt TPoolId * Revert "udvt TPoolId" This reverts commit 0f2c107. * distinguish poolId vs consensus * declare TPoolId type * remove mockup contract * remove bridge operator change method * rename interface param * remove comment * refactor * revert casting in coinbase * Remove TPoolId. Using TConsensus. * fix test * remove public vars * remove more public vars * remove redundant code * wrap all external method to TConsensus type * fix config * fix test init * fix mock * fix test * fix test * add comment * fix helper * restructure * fix edge case * fix conventions * add docs * fix: foundry config * chore: fix conventions * fix: remove bridge voter * fix: change inheritance tree * Merge branch 'feat/fast-finality' into feat/profile * fix: fix test setup * Merge branch 'feat/bridge-admin-rebase' into feat/profile * fix test after merging * chore: add TODO tag * tmp disable forge test * fix fixture * update ci * Continue merge branch 'testnet' into feat/profile * fix test setup * fix more test setup * fix test * fix test & improve conf test * refactor initializer * apply initializer for test suites * fix fast finality test * fix initializers * chore: resolve conflict * feat(Profile): remove unused method, fix execApplyCandidate * feat(Profile, Staking): require pubkey at apply candidate, fix init test * test(Profile): fix other dependent tests * chore: fix test * feat(ValidatorSet): recover slot shifted * fix(Profile): cherry-pick fix from 'test/feat/profile' * fix(SlashFastFinality): fix wrapper for consensus * chore: resolve low-level call warning * temp(*): rename to cid, pid, _shadowed** * feat(ValidatorSet): cached admin * feat(Profile, ValidatorSet): handle execChangeAdminAddress * feat(Staking): rename admin to `__shadowPoolAdmin` * feat(Profile): handle change treasury, fix missing rename * chore(Validator): rename to *ById suffix * chore: rename `_convert*C2P` * chore(Validator): remove old version contract * chore(docs): write natspecs doc for struct * chore(*): remove `_` for consistent var names * chore(docs): NatSpecs for __css2cid * chore: remove compiler warning * feat(TrustedOrg): handle change consensus for Trusted Org * feat(SlashIndicator): remove code related to bridge * chore: clean up PR, remove unrelated files * fix(Staking): fix inaccurate shifted gap * chore(ValidatorSet): consist interface * chore(ValidatorSet, Staking): move callbacks to separate files * chore(ValidatorSet): refactor callbacks * chore: remove log * fix(TrustedOrg): remove onlyAdmin in initV2, fix test * test: fix test after restrict not allowing rejoin in Profile * test: fix more test * feat(RoninTO): fix bug when change consensus in RoninTO * chore: fix rebase issue * fix(RoninTO): delete deprecated storage * chore: rename consensus to cid * fix(GovernanceAdmin): fix emergency exit typehash * test(*): fix deprecated voter for test setup * feat(RoninTO): return address(0) for bridge voter * chore: fix typo * chore: fix deprecatedVoter in test * feat(RoninTO): rename for consistency * feat(Validator): better handling emergency exit revert * feat(EmergencyExit): revert to original typehash * fix(Profile); rename check to require * feat: migrate registry for renounced candidates * feat(Profile): fix migration * chore: fix test setup * config: enable literal content for RoninValidatorSet deployment
1 parent e30e4f7 commit 1cafa6a

File tree

114 files changed

+6755
-2780
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+6755
-2780
lines changed

.github/workflows/unittest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- "release/**"
88
pull_request:
99
branches:
10-
- main
10+
- mainnet
1111
- testnet
1212
- "release/**"
1313

contracts/extensions/forwarder/Forwarder.sol

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ contract Forwarder is AccessControlEnumerable {
2525
/**
2626
* @dev Initializes the forwarder with an initial target address and a contract admin.
2727
*/
28-
constructor(address[] memory _targets, address _admin, address _moderator) payable {
29-
for (uint _i = 0; _i < _targets.length; ) {
30-
_setupRole(TARGET_ROLE, _targets[_i]);
28+
constructor(address[] memory targets, address admin, address moderator) payable {
29+
for (uint i = 0; i < targets.length; ) {
30+
_setupRole(TARGET_ROLE, targets[i]);
3131

3232
unchecked {
33-
++_i;
33+
++i;
3434
}
3535
}
36-
_setupRole(DEFAULT_ADMIN_ROLE, _admin);
37-
_setupRole(MODERATOR_ROLE, _moderator);
36+
_setupRole(DEFAULT_ADMIN_ROLE, admin);
37+
_setupRole(MODERATOR_ROLE, moderator);
3838
}
3939

40-
modifier validTarget(address _target) {
41-
_checkRole(TARGET_ROLE, _target);
40+
modifier validTarget(address target) {
41+
_checkRole(TARGET_ROLE, target);
4242
_;
4343
}
4444

@@ -61,21 +61,21 @@ contract Forwarder is AccessControlEnumerable {
6161
* - Only user with {MODERATOR_ROLE} can call this method.
6262
*/
6363
function functionCall(
64-
address _target,
65-
bytes memory _data,
66-
uint256 _val
67-
) external payable validTarget(_target) onlyRole(MODERATOR_ROLE) {
68-
if (_val > address(this).balance) revert ErrInvalidForwardValue();
69-
_call(_target, _data, _val);
64+
address target,
65+
bytes memory data,
66+
uint256 val
67+
) external payable validTarget(target) onlyRole(MODERATOR_ROLE) {
68+
if (val > address(this).balance) revert ErrInvalidForwardValue();
69+
_call(target, data, val);
7070
}
7171

7272
/**
7373
* @dev Forwards the current call to `target`.
7474
*
7575
* This function does not return to its internal call site, it will return directly to the external caller.
7676
*/
77-
function _call(address _target, bytes memory _data, uint256 _value) internal {
78-
(bool _success, bytes memory _res) = _target.call{ value: _value }(_data);
79-
_success.handleRevert(bytes4(_data), _res);
77+
function _call(address target, bytes memory data, uint256 value) internal {
78+
(bool success, bytes memory res) = target.call{ value: value }(data);
79+
success.handleRevert(bytes4(data), res);
8080
}
8181
}

contracts/interfaces/IMaintenance.sol

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
pragma solidity ^0.8.9;
44

5+
import { TConsensus } from "../udvts/Types.sol";
6+
57
interface IMaintenance {
68
/**
79
* @dev Error thrown when attempting to schedule an already scheduled event.
@@ -61,9 +63,9 @@ interface IMaintenance {
6163
}
6264

6365
/// @dev Emitted when a maintenance is scheduled.
64-
event MaintenanceScheduled(address indexed consensusAddr, Schedule);
66+
event MaintenanceScheduled(TConsensus indexed consensusAddr, Schedule);
6567
/// @dev Emitted when a schedule of maintenance is cancelled.
66-
event MaintenanceScheduleCancelled(address indexed consensusAddr);
68+
event MaintenanceScheduleCancelled(TConsensus indexed consensusAddr);
6769
/// @dev Emitted when the maintenance config is updated.
6870
event MaintenanceConfigUpdated(
6971
uint256 minMaintenanceDurationInBlock,
@@ -75,52 +77,76 @@ interface IMaintenance {
7577
);
7678

7779
/**
78-
* @dev Returns whether the validator `_consensusAddr` maintained at the block number `_block`.
80+
* @dev Returns whether the validator `consensusAddr` maintained at the block number `_block`.
81+
*/
82+
function checkMaintained(TConsensus consensusAddr, uint256 _block) external view returns (bool);
83+
84+
/**
85+
* @dev Returns whether the validator whose id `validatorId` maintained at the block number `_block`.
7986
*/
80-
function checkMaintained(address _consensusAddr, uint256 _block) external view returns (bool);
87+
function checkMaintainedById(address validatorId, uint256 _block) external view returns (bool);
8188

8289
/**
83-
* @dev Returns whether the validator `_consensusAddr` maintained in the inclusive range [`_fromBlock`, `_toBlock`] of blocks.
90+
* @dev Returns whether the validator `consensusAddr` maintained in the inclusive range [`_fromBlock`, `_toBlock`] of blocks.
8491
*/
8592
function checkMaintainedInBlockRange(
86-
address _consensusAddr,
93+
TConsensus consensusAddr,
8794
uint256 _fromBlock,
8895
uint256 _toBlock
8996
) external view returns (bool);
9097

9198
/**
92-
* @dev Returns the bool array indicating the validators maintained at block number `_block` or not.
99+
* @dev Returns the bool array indicating the validators maintained at block number `k` or not.
93100
*/
94-
function checkManyMaintained(address[] calldata _addrList, uint256 _block) external view returns (bool[] memory);
101+
function checkManyMaintained(
102+
TConsensus[] calldata consensusAddrList,
103+
uint256 atBlock
104+
) external view returns (bool[] memory);
105+
106+
function checkManyMaintainedById(
107+
address[] calldata candidateIdList,
108+
uint256 atBlock
109+
) external view returns (bool[] memory);
95110

96111
/**
97112
* @dev Returns a bool array indicating the validators maintained in the inclusive range [`_fromBlock`, `_toBlock`] of blocks or not.
98113
*/
99114
function checkManyMaintainedInBlockRange(
100-
address[] calldata _addrList,
115+
TConsensus[] calldata _consensusAddrList,
101116
uint256 _fromBlock,
102117
uint256 _toBlock
103118
) external view returns (bool[] memory);
104119

120+
function checkManyMaintainedInBlockRangeById(
121+
address[] calldata idList,
122+
uint256 fromBlock,
123+
uint256 toBlock
124+
) external view returns (bool[] memory);
125+
105126
/**
106-
* @dev Returns whether the validator `_consensusAddr` has scheduled.
127+
* @dev Returns whether the validator `consensusAddr` has finished cooldown.
107128
*/
108-
function checkScheduled(address _consensusAddr) external view returns (bool);
129+
function checkCooldownEnded(TConsensus consensusAddr) external view returns (bool);
109130

110131
/**
111-
* @dev Returns whether the validator `_consensusAddr`
132+
* @dev Returns whether the validator `consensusAddr` has schedule.
112133
*/
113-
function checkCooldownEnded(address _consensusAddr) external view returns (bool);
134+
function checkScheduled(TConsensus consensusAddr) external view returns (bool);
114135

115136
/**
116-
* @dev Returns the detailed schedule of the validator `_consensusAddr`.
137+
* @dev Returns the detailed schedule of the validator `consensusAddr`.
117138
*/
118-
function getSchedule(address _consensusAddr) external view returns (Schedule memory);
139+
function getSchedule(TConsensus consensusAddr) external view returns (Schedule memory);
119140

120141
/**
121142
* @dev Returns the total of current schedules.
122143
*/
123-
function totalSchedule() external view returns (uint256 _count);
144+
function totalSchedule() external view returns (uint256 count);
145+
146+
/**
147+
* @dev Returns the cooldown to maintain in seconds.
148+
*/
149+
function cooldownSecsToMaintain() external view returns (uint256);
124150

125151
/**
126152
* @dev Sets the duration restriction, start time restriction, and max allowed for maintenance.
@@ -134,12 +160,12 @@ interface IMaintenance {
134160
*
135161
*/
136162
function setMaintenanceConfig(
137-
uint256 _minMaintenanceDurationInBlock,
138-
uint256 _maxMaintenanceDurationInBlock,
139-
uint256 _minOffsetToStartSchedule,
140-
uint256 _maxOffsetToStartSchedule,
141-
uint256 _maxSchedules,
142-
uint256 _cooldownSecsToMaintain
163+
uint256 minMaintenanceDurationInBlock_,
164+
uint256 maxMaintenanceDurationInBlock_,
165+
uint256 minOffsetToStartSchedule_,
166+
uint256 maxOffsetToStartSchedule_,
167+
uint256 maxSchedules_,
168+
uint256 cooldownSecsToMaintain_
143169
) external;
144170

145171
/**
@@ -168,12 +194,12 @@ interface IMaintenance {
168194
function maxSchedule() external view returns (uint256);
169195

170196
/**
171-
* @dev Schedules for maintenance from `_startedAtBlock` to `_startedAtBlock`.
197+
* @dev Schedules for maintenance from `startedAtBlock` to `endedAtBlock`.
172198
*
173199
* Requirements:
174-
* - The candidate `_consensusAddr` is the block producer.
175-
* - The method caller is candidate admin of the candidate `_consensusAddr`.
176-
* - The candidate `_consensusAddr` has no schedule yet or the previous is done.
200+
* - The candidate `consensusAddr` is the block producer.
201+
* - The method caller is candidate admin of the candidate `consensusAddr`.
202+
* - The candidate `consensusAddr` has no schedule yet or the previous is done.
177203
* - The total number of schedules is not larger than `maxSchedules()`.
178204
* - The start block must be at least `minOffsetToStartSchedule()` and at most `maxOffsetToStartSchedule()` blocks from the current block.
179205
* - The end block is larger than the start block.
@@ -184,17 +210,17 @@ interface IMaintenance {
184210
* Emits the event `MaintenanceScheduled`.
185211
*
186212
*/
187-
function schedule(address _consensusAddr, uint256 _startedAtBlock, uint256 _endedAtBlock) external;
213+
function schedule(TConsensus consensusAddr, uint256 startedAtBlock, uint256 endedAtBlock) external;
188214

189215
/**
190-
* @dev Cancel the schedule of maintenance for the `_consensusAddr`.
216+
* @dev Cancel the schedule of maintenance for the `consensusAddr`.
191217
*
192218
* Requirements:
193-
* - The candidate `_consensusAddr` is the block producer.
194-
* - The method caller is candidate admin of the candidate `_consensusAddr`.
195-
* - A schedule for the `_consensusAddr` must be existent and not executed yet.
219+
* - The candidate `consensusAddr` is the block producer.
220+
* - The method caller is candidate admin of the candidate `consensusAddr`.
221+
* - A schedule for the `consensusAddr` must be existent and not executed yet.
196222
*
197223
* Emits the event `MaintenanceScheduleCancelled`.
198224
*/
199-
function cancelSchedule(address _consensusAddr) external;
225+
function cancelSchedule(TConsensus consensusAddr) external;
200226
}

contracts/interfaces/IProfile.sol

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
pragma solidity ^0.8.9;
44

5+
import { TPoolId, TConsensus } from "../udvts/Types.sol";
56
import "../utils/RoleAccess.sol";
67

78
interface IProfile {
@@ -15,13 +16,13 @@ interface IProfile {
1516
*/
1617
address id;
1718
/// @dev Consensus address.
18-
address consensus;
19+
TConsensus consensus;
1920
/// @dev Pool admin address.
2021
address admin;
2122
/// @dev Treasury address.
2223
address payable treasury;
2324
/// @dev Address to voting proposal.
24-
address governor;
25+
address __reservedGovernor;
2526
/// @dev Public key for fast finality.
2627
bytes pubkey;
2728
}
@@ -51,6 +52,15 @@ interface IProfile {
5152
/// @dev Getter to query full `profile` from `id` address.
5253
function getId2Profile(address id) external view returns (CandidateProfile memory profile);
5354

55+
/// @dev Getter to batch query from `id` to `consensus`, return address(0) if the profile not exist.
56+
function getManyId2Consensus(address[] calldata idList) external view returns (TConsensus[] memory consensusList);
57+
58+
/// @dev Getter to backward query from `consensus` address to `id` address.
59+
function getConsensus2Id(TConsensus consensus) external view returns (address id);
60+
61+
/// @dev Getter to backward batch query from `consensus` address to `id` address.
62+
function getManyConsensus2Id(TConsensus[] memory consensus) external view returns (address[] memory);
63+
5464
/**
5565
* @notice Add a new profile.
5666
*
@@ -61,14 +71,34 @@ interface IProfile {
6171
function addNewProfile(CandidateProfile memory profile) external;
6272

6373
/**
64-
* @notice The candidate admin registers a new profile.
74+
* @dev Cross-contract function to add/update new profile of a validator candidate when they
75+
* applying for candidate role.
6576
*
66-
* @dev Requirements:
67-
* - The profile must not be existent before.
68-
* - Only user with candidate admin role can call this method.
77+
* Requirements:
78+
* - Only `stakingContract` can call this method.
6979
*/
80+
function execApplyValidatorCandidate(address admin, address id, address treasury, bytes calldata pubkey) external;
7081

71-
function registerProfile(CandidateProfile memory profile) external;
82+
/**
83+
* @dev Updated the treasury address of candidate id `id` immediately without waiting time.
84+
*
85+
* Emit an {ProfileAddressChanged}.
86+
*/
87+
function requestChangeAdminAddress(address id, address newAdminAddr) external;
88+
89+
/**
90+
* @dev Updated the treasury address of candidate id `id` immediately without waiting time.
91+
*
92+
* Emit an {ProfileAddressChanged}.
93+
*/
94+
function requestChangeConsensusAddr(address id, TConsensus newConsensusAddr) external;
95+
96+
/**
97+
* @dev Updated the treasury address of candidate id `id` immediately without waiting time.
98+
*
99+
* Emit an {ProfileAddressChanged}.
100+
*/
101+
function requestChangeTreasuryAddr(address id, address payable newTreasury) external;
72102

73103
/**
74104
* @notice The candidate admin changes the public key.

contracts/interfaces/IRoninGovernanceAdmin.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import "../utils/CommonErrors.sol";
66
interface IRoninGovernanceAdmin {
77
/// @dev Emitted when an emergency exit poll is created.
88
event EmergencyExitPollCreated(
9-
bytes32 _voteHash,
10-
address _consensusAddr,
11-
address _recipientAfterUnlockedFund,
12-
uint256 _requestedAt,
13-
uint256 _expiredAt
9+
bytes32 voteHash,
10+
address validatorId,
11+
address recipientAfterUnlockedFund,
12+
uint256 requestedAt,
13+
uint256 expiredAt
1414
);
1515
/// @dev Emitted when an emergency exit poll is approved.
16-
event EmergencyExitPollApproved(bytes32 _voteHash);
16+
event EmergencyExitPollApproved(bytes32 voteHash);
1717
/// @dev Emitted when an emergency exit poll is expired.
18-
event EmergencyExitPollExpired(bytes32 _voteHash);
18+
event EmergencyExitPollExpired(bytes32 voteHash);
1919
/// @dev Emitted when an emergency exit poll is voted.
20-
event EmergencyExitPollVoted(bytes32 indexed _voteHash, address indexed _voter);
20+
event EmergencyExitPollVoted(bytes32 indexed voteHash, address indexed voter);
2121

2222
/**
2323
* @dev Create a vote to agree that an emergency exit is valid and should return the locked funds back.a
@@ -27,9 +27,9 @@ interface IRoninGovernanceAdmin {
2727
*
2828
*/
2929
function createEmergencyExitPoll(
30-
address _consensusAddr,
31-
address _recipientAfterUnlockedFund,
32-
uint256 _requestedAt,
33-
uint256 _expiredAt
30+
address validatorId,
31+
address recipientAfterUnlockedFund,
32+
uint256 requestedAt,
33+
uint256 expiredAt
3434
) external;
3535
}

0 commit comments

Comments
 (0)