Cleanup timelockId on execution for gas refund (#4118)
Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
5
.changeset/hot-plums-approve.md
Normal file
5
.changeset/hot-plums-approve.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'openzeppelin-solidity': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
`GovernorTimelockControl`: Clean up timelock id on execution for gas refund.
|
||||||
@ -60,11 +60,13 @@ abstract contract GovernorTimelockControl is IGovernorTimelock, Governor {
|
|||||||
bytes32 queueid = _timelockIds[proposalId];
|
bytes32 queueid = _timelockIds[proposalId];
|
||||||
if (queueid == bytes32(0)) {
|
if (queueid == bytes32(0)) {
|
||||||
return currentState;
|
return currentState;
|
||||||
} else if (_timelock.isOperationDone(queueid)) {
|
|
||||||
return ProposalState.Executed;
|
|
||||||
} else if (_timelock.isOperationPending(queueid)) {
|
} else if (_timelock.isOperationPending(queueid)) {
|
||||||
return ProposalState.Queued;
|
return ProposalState.Queued;
|
||||||
|
} else if (_timelock.isOperationDone(queueid)) {
|
||||||
|
// This can happen if the proposal is executed directly on the timelock.
|
||||||
|
return ProposalState.Executed;
|
||||||
} else {
|
} else {
|
||||||
|
// This can happen if the proposal is canceled directly on the timelock.
|
||||||
return ProposalState.Canceled;
|
return ProposalState.Canceled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,13 +119,16 @@ abstract contract GovernorTimelockControl is IGovernorTimelock, Governor {
|
|||||||
* @dev Overridden execute function that run the already queued proposal through the timelock.
|
* @dev Overridden execute function that run the already queued proposal through the timelock.
|
||||||
*/
|
*/
|
||||||
function _execute(
|
function _execute(
|
||||||
uint256 /* proposalId */,
|
uint256 proposalId,
|
||||||
address[] memory targets,
|
address[] memory targets,
|
||||||
uint256[] memory values,
|
uint256[] memory values,
|
||||||
bytes[] memory calldatas,
|
bytes[] memory calldatas,
|
||||||
bytes32 descriptionHash
|
bytes32 descriptionHash
|
||||||
) internal virtual override {
|
) internal virtual override {
|
||||||
|
// execute
|
||||||
_timelock.executeBatch{value: msg.value}(targets, values, calldatas, 0, descriptionHash);
|
_timelock.executeBatch{value: msg.value}(targets, values, calldatas, 0, descriptionHash);
|
||||||
|
// cleanup for refund
|
||||||
|
delete _timelockIds[proposalId];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,9 +145,12 @@ abstract contract GovernorTimelockControl is IGovernorTimelock, Governor {
|
|||||||
bytes32 descriptionHash
|
bytes32 descriptionHash
|
||||||
) internal virtual override returns (uint256) {
|
) internal virtual override returns (uint256) {
|
||||||
uint256 proposalId = super._cancel(targets, values, calldatas, descriptionHash);
|
uint256 proposalId = super._cancel(targets, values, calldatas, descriptionHash);
|
||||||
|
bytes32 timelockId = _timelockIds[proposalId];
|
||||||
|
|
||||||
if (_timelockIds[proposalId] != 0) {
|
if (timelockId != 0) {
|
||||||
_timelock.cancel(_timelockIds[proposalId]);
|
// cancel
|
||||||
|
_timelock.cancel(timelockId);
|
||||||
|
// cleanup
|
||||||
delete _timelockIds[proposalId];
|
delete _timelockIds[proposalId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user