Skip to content

Commit 6ddacdb

Browse files
Amxxfrangio
andauthored
Cleanup timelockId on execution for gas refund (#4118)
Co-authored-by: Francisco <fg@frang.io>
1 parent dac2457 commit 6ddacdb

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

.changeset/hot-plums-approve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openzeppelin-solidity': minor
3+
---
4+
5+
`GovernorTimelockControl`: Clean up timelock id on execution for gas refund.

contracts/governance/extensions/GovernorTimelockControl.sol

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ abstract contract GovernorTimelockControl is IGovernorTimelock, Governor {
6060
bytes32 queueid = _timelockIds[proposalId];
6161
if (queueid == bytes32(0)) {
6262
return currentState;
63-
} else if (_timelock.isOperationDone(queueid)) {
64-
return ProposalState.Executed;
6563
} else if (_timelock.isOperationPending(queueid)) {
6664
return ProposalState.Queued;
65+
} else if (_timelock.isOperationDone(queueid)) {
66+
// This can happen if the proposal is executed directly on the timelock.
67+
return ProposalState.Executed;
6768
} else {
69+
// This can happen if the proposal is canceled directly on the timelock.
6870
return ProposalState.Canceled;
6971
}
7072
}
@@ -117,13 +119,16 @@ abstract contract GovernorTimelockControl is IGovernorTimelock, Governor {
117119
* @dev Overridden execute function that run the already queued proposal through the timelock.
118120
*/
119121
function _execute(
120-
uint256 /* proposalId */,
122+
uint256 proposalId,
121123
address[] memory targets,
122124
uint256[] memory values,
123125
bytes[] memory calldatas,
124126
bytes32 descriptionHash
125127
) internal virtual override {
128+
// execute
126129
_timelock.executeBatch{value: msg.value}(targets, values, calldatas, 0, descriptionHash);
130+
// cleanup for refund
131+
delete _timelockIds[proposalId];
127132
}
128133

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

144-
if (_timelockIds[proposalId] != 0) {
145-
_timelock.cancel(_timelockIds[proposalId]);
150+
if (timelockId != 0) {
151+
// cancel
152+
_timelock.cancel(timelockId);
153+
// cleanup
146154
delete _timelockIds[proposalId];
147155
}
148156

0 commit comments

Comments
 (0)