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

Cleanup timelockId on execution for gas refund #4118

Merged
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
5 changes: 5 additions & 0 deletions .changeset/hot-plums-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`GovernorTimelockControl`: Clean up timelock id on execution for gas refund.
18 changes: 13 additions & 5 deletions contracts/governance/extensions/GovernorTimelockControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ abstract contract GovernorTimelockControl is IGovernorTimelock, Governor {
bytes32 queueid = _timelockIds[proposalId];
if (queueid == bytes32(0)) {
return currentState;
} else if (_timelock.isOperationDone(queueid)) {
return ProposalState.Executed;
} else if (_timelock.isOperationPending(queueid)) {
return ProposalState.Queued;
} else if (_timelock.isOperationDone(queueid)) {
// This can happen if the proposal is executed directly on the timelock.
return ProposalState.Executed;
frangio marked this conversation as resolved.
Show resolved Hide resolved
} else {
// This can happen if the proposal is canceled directly on the timelock.
return ProposalState.Canceled;
}
}
Expand Down Expand Up @@ -117,13 +119,16 @@ abstract contract GovernorTimelockControl is IGovernorTimelock, Governor {
* @dev Overridden execute function that run the already queued proposal through the timelock.
*/
function _execute(
uint256 /* proposalId */,
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual override {
// execute
_timelock.executeBatch{value: msg.value}(targets, values, calldatas, 0, descriptionHash);
// cleanup for refund
delete _timelockIds[proposalId];
}

/**
Expand All @@ -140,9 +145,12 @@ abstract contract GovernorTimelockControl is IGovernorTimelock, Governor {
bytes32 descriptionHash
) internal virtual override returns (uint256) {
uint256 proposalId = super._cancel(targets, values, calldatas, descriptionHash);
bytes32 timelockId = _timelockIds[proposalId];

if (_timelockIds[proposalId] != 0) {
_timelock.cancel(_timelockIds[proposalId]);
if (timelockId != 0) {
// cancel
_timelock.cancel(timelockId);
// cleanup
delete _timelockIds[proposalId];
}

Expand Down