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

Add state getter in TimelockController using OperationState enum #4358

Merged
merged 24 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
82e34fd
first proposal
RenanSouza2 Jun 16, 2023
536628e
Add changeset
RenanSouza2 Jun 16, 2023
a2a6a0c
Merge branch 'master' into timelockControler-getter
RenanSouza2 Jun 16, 2023
b2b6844
Improove getOperationState decision tree
RenanSouza2 Jun 16, 2023
813360d
Merge branch 'master' into timelockControler-getter
RenanSouza2 Jun 17, 2023
c3f0ac1
Merge branch 'master' into timelockControler-getter
RenanSouza2 Jun 28, 2023
832c2d5
Reinstate functions
RenanSouza2 Jun 28, 2023
e0bbaad
Change Pending to Blocked
RenanSouza2 Jun 29, 2023
8e671f9
Change TimelockController error from state to bitmap
RenanSouza2 Jul 1, 2023
de0fb95
Fix tests
RenanSouza2 Jul 1, 2023
ef63f37
Fix linter
RenanSouza2 Jul 1, 2023
7587ab4
Merge branch 'master' into timelockControler-getter
RenanSouza2 Jul 1, 2023
9e8c8ca
Update loud-shrimps-play.md
frangio Jul 4, 2023
cf4a2df
rename error param
frangio Jul 4, 2023
ab10a19
remove isOperationBlocked
frangio Jul 4, 2023
643b549
remove virtual
frangio Jul 4, 2023
86f1724
revert afterCall change
frangio Jul 4, 2023
f9498a9
rename Blocked to Waiting
frangio Jul 4, 2023
84099df
Merge branch 'master' into timelockControler-getter
frangio Jul 4, 2023
220cfc3
Change enum in documentation
RenanSouza2 Jul 4, 2023
bd74728
Remove interfaces from docs
RenanSouza2 Jul 4, 2023
a608384
Update contracts/governance/TimelockController.sol
frangio Jul 4, 2023
bd2f0fa
Update contracts/governance/TimelockController.sol
frangio Jul 4, 2023
8d43f44
Update contracts/governance/TimelockController.sol
frangio Jul 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/loud-shrimps-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

Add state getter in TimelockController using OperationState enum
46 changes: 20 additions & 26 deletions contracts/governance/TimelockController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -169,28 +169,6 @@ contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder {
return getTimestamp(id) > 0;
}

/**
* @dev Returns whether an operation is pending or not. Note that a "pending" operation may also be "ready".
*/
function isOperationPending(bytes32 id) public view virtual returns (bool) {
return getTimestamp(id) > _DONE_TIMESTAMP;
}

/**
* @dev Returns whether an operation is ready for execution. Note that a "ready" operation is also "pending".
*/
function isOperationReady(bytes32 id) public view virtual returns (bool) {
uint256 timestamp = getTimestamp(id);
return timestamp > _DONE_TIMESTAMP && timestamp <= block.timestamp;
}

/**
* @dev Returns whether an operation is done or not.
*/
function isOperationDone(bytes32 id) public view virtual returns (bool) {
return getTimestamp(id) == _DONE_TIMESTAMP;
}

frangio marked this conversation as resolved.
Show resolved Hide resolved
/**
* @dev Returns the timestamp at which an operation becomes ready (0 for
* unset operations, 1 for done operations).
Expand All @@ -199,6 +177,22 @@ contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder {
return _timestamps[id];
}

/**
* @dev Returns operation state.
*/
function getOperationState(bytes32 id) public view virtual returns (OperationState) {
uint timestamp = getTimestamp(id);
RenanSouza2 marked this conversation as resolved.
Show resolved Hide resolved
if (timestamp == 0) {
return OperationState.Unset;
} else if (getTimestamp(id) > _DONE_TIMESTAMP && timestamp > block.timestamp) {
return OperationState.Pending;
} else if (timestamp > _DONE_TIMESTAMP) {
return OperationState.Ready;
} else {
return OperationState.Done;
}
}
RenanSouza2 marked this conversation as resolved.
Show resolved Hide resolved

/**
* @dev Returns the minimum delay for an operation to become valid.
*
Expand Down Expand Up @@ -314,7 +308,7 @@ contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder {
* - the caller must have the 'canceller' role.
*/
function cancel(bytes32 id) public virtual onlyRole(CANCELLER_ROLE) {
if (!isOperationPending(id)) {
if (getOperationState(id) != OperationState.Pending) {
revert TimelockUnexpectedOperationState(id, OperationState.Pending);
}
delete _timestamps[id];
Expand Down Expand Up @@ -397,10 +391,10 @@ contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder {
* @dev Checks before execution of an operation's calls.
*/
function _beforeCall(bytes32 id, bytes32 predecessor) private view {
if (!isOperationReady(id)) {
if (getOperationState(id) != OperationState.Ready) {
revert TimelockUnexpectedOperationState(id, OperationState.Ready);
}
if (predecessor != bytes32(0) && !isOperationDone(predecessor)) {
if (predecessor != bytes32(0) && getOperationState(predecessor) != OperationState.Done) {
revert TimelockUnexecutedPredecessor(predecessor);
}
}
Expand All @@ -409,7 +403,7 @@ contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder {
* @dev Checks after execution of an operation's calls.
*/
function _afterCall(bytes32 id) private {
if (!isOperationReady(id)) {
if (getOperationState(id) != OperationState.Ready) {
revert TimelockUnexpectedOperationState(id, OperationState.Ready);
}
_timestamps[id] = _DONE_TIMESTAMP;
Expand Down
10 changes: 8 additions & 2 deletions contracts/governance/extensions/GovernorTimelockControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ abstract contract GovernorTimelockControl is IGovernorTimelock, Governor {
bytes32 queueid = _timelockIds[proposalId];
if (queueid == bytes32(0)) {
return currentState;
} else if (_timelock.isOperationDone(queueid)) {
}

TimelockController.OperationState _operationState = _timelock.getOperationState(queueid);
if (_operationState == TimelockController.OperationState.Done) {
return ProposalState.Executed;
} else if (_timelock.isOperationPending(queueid)) {
} else if (
_operationState == TimelockController.OperationState.Pending ||
_operationState == TimelockController.OperationState.Ready
) {
frangio marked this conversation as resolved.
Show resolved Hide resolved
return ProposalState.Queued;
} else {
return ProposalState.Canceled;
Expand Down