What does _beforeExecute() do in Governor.sol and is _execute() skipping the first element?

_execute() doesn't take any data generated by _beforeExecute(), also, does _execute() skip the i=0 case?

_beforeExecute is a hook.

No, what makes you think this?

1 Like

Regarding _beforeExecute, yes, I was aware it was a hook, but I was not sure what
_governanceCall.pushBack(keccak256(calldatas[i])); was doing there, it's been some time, I will take a closer look.

Regarding _excute(), doesn't ++i instead of i++ skip the i=0 case?
for (uint256 i = 0; i < targets.length; ++i)

1 Like

The code you cite in _beforeExecute was introduced in https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3147. Take a look there to understand the rationale.

No, ++i vs i++ doesn't make a difference there.

The link you gave mentions timelock, If one doesn't use timelock, the function _governanceCall.pushBack(keccak256(calldatas[i])); wouldn't affect things?

Exactly. That code only executes if _executor != this:

This happens when a timelock is involved, in that case the executor is the timelock. If there is no timelock, the executor is the governor itself (i.e. this). Note that there may be other external executors, but timelocks are the only examples included out of the box with OpenZeppelin Contracts.

2 Likes