Skip to main content

ConfigTimelockBatchQueue

Git Source

Inherits: TimelockBatchQueue, IConfigTimelockBatchQueue

Title: ConfigTimelockBatchQueue

Base contract for configuration timelocks. It prevents conflicting changes from being queued together and prevents queued changes from executing after their underlying configuration has changed.

Each sub-action identifies its destination and the configuration it depends on with one or more keys. The contract scopes every key to that destination, reserves the scoped keys, and records their current state hashes at queue time. A reserved key cannot be used by another unresolved action. At execution, the destination and every current state hash must still match. Keys are released only after the whole batch executes or is cancelled. Product contracts customize validation, destinations, keys, hashes, and dispatch through the config-specific hooks below.

State Variables​

_pendingActionIds​

The unresolved action holding a destination-scoped configuration key.

mapping(bytes32 key => uint64 actionId) internal _pendingActionIds;

_queuedConfigStates​

Configuration states recorded for each sub-action at queue time, by local key.

mapping(uint64 actionId => mapping(uint256 index => QueuedConfigState[] states))
internal _queuedConfigStates;

_queuedConfigDestinations​

Destination recorded for each sub-action at queue time.

mapping(uint64 actionId => mapping(uint256 index => address destination))
internal _queuedConfigDestinations;

Functions​

constructor​

constructor(uint48 initialTimelockDelay_) TimelockBatchQueue(initialTimelockDelay_);

Parameters

NameTypeDescription
initialTimelockDelay_uint48

pendingActionId​

Return the unresolved action that owns a destination-scoped key, or zero if free.

function pendingActionId(bytes32 key_) external view returns (uint64 actionId);

Parameters

NameTypeDescription
key_bytes32

Returns

NameTypeDescription
actionIduint64

maxConfigKeysPerBatch​

Return the maximum total configuration keys a batch may reserve.

function maxConfigKeysPerBatch() external view returns (uint256 maximum);

Returns

NameTypeDescription
maximumuint256

getQueuedConfigStateCount​

Return the number of configuration guards stored for a sub-action.

function getQueuedConfigStateCount(
uint64 actionId_,
uint256 index_
) external view returns (uint256 length);

Parameters

NameTypeDescription
actionId_uint64
index_uint256

Returns

NameTypeDescription
lengthuint256

getQueuedConfigDestination​

Return the destination selected by the subclass when a sub-action was queued.

function getQueuedConfigDestination(
uint64 actionId_,
uint256 index_
) external view returns (address destination);

Parameters

NameTypeDescription
actionId_uint64
index_uint256

Returns

NameTypeDescription
destinationaddress

getQueuedConfigState​

Return a stored destination-scoped key and its queue-time canonical state hash.

function getQueuedConfigState(
uint64 actionId_,
uint256 index_,
uint256 configStateIndex_
) external view returns (bytes32 key, bytes32 expectedStateHash);

Parameters

NameTypeDescription
actionId_uint64
index_uint256
configStateIndex_uint256

Returns

NameTypeDescription
keybytes32
expectedStateHashbytes32

_onSubActionQueued​

Hook invoked once per sub-action at queue time, before the batch is stored.

Derived contracts must revert on failure. Implementations are expected to validate the target, selector, and payload of the sub-action in isolation, and may record per-sub-action state. Cross sub-action invariants belong in _onBatchQueued. The caller is passed explicitly for clarity and to support derived contracts that centralize authorization around actor params.

function _onSubActionQueued(
address caller_,
uint64 actionId_,
uint256 index_,
ITimelockBatchQueue.BatchAction memory action_
) internal override;

Parameters

NameTypeDescription
caller_addressThe account queueing the action.
actionId_uint64The id the batch will be stored under.
index_uint256The position of the sub-action within the batch.
action_ITimelockBatchQueue.BatchActionThe sub-action being queued.

_onBatchQueued​

function _onBatchQueued(
address caller_,
uint64 actionId_,
ITimelockBatchQueue.BatchAction[] memory actions_
) internal view override;

Parameters

NameTypeDescription
caller_address
actionId_uint64
actions_ITimelockBatchQueue.BatchAction[]

_executeSubAction​

Execute a single sub-action of a batched queued action.

Derived contracts must revert on failure. Called by the base contract once per sub-action in array order; the action has already been marked executed, so a revert in any iteration reverts the entire batch and rolls back that flag. Derived contracts must not rely on the base contract calling this hook in any other order.

function _executeSubAction(
uint64 actionId_,
uint256 index_,
ITimelockBatchQueue.BatchAction memory action_
) internal override;

Parameters

NameTypeDescription
actionId_uint64The queued action ID.
index_uint256The position of the sub-action within the batch.
action_ITimelockBatchQueue.BatchActionThe sub-action to execute.

_onActionExecuted​

Hook invoked once after every sub-action has executed successfully and before the stored sub-actions are cleared.

Default implementation is a no-op. A revert rolls back the complete batch, including target state changes and the action's executed flag. Derived contracts may use this hook to clear state that must remain available throughout execution.

function _onActionExecuted(uint64 actionId_, uint256 subActionCount_) internal override;

Parameters

NameTypeDescription
actionId_uint64The executed action ID.
subActionCount_uint256The number of successfully executed sub-actions.

_onActionCancelled​

Hook invoked once when a queued action is cancelled, after the stored sub-actions have been cleared.

Default implementation is a no-op. Derived contracts override to clear any per-sub-action state recorded at queue time by _onSubActionQueued. The sub-action count is captured before the stored array is deleted, so implementations can iterate the indices that were recorded.

function _onActionCancelled(uint64 actionId_, uint256 subActionCount_) internal override;

Parameters

NameTypeDescription
actionId_uint64The cancelled action ID.
subActionCount_uint256The number of sub-actions the action held before clearing.

_releaseConfigKeys​

function _releaseConfigKeys(uint64 actionId_, uint256 subActionCount_) private;

Parameters

NameTypeDescription
actionId_uint64
subActionCount_uint256

_queuedConfigKeyCount​

function _queuedConfigKeyCount(
uint64 actionId_,
uint256 endIndex_
) private view returns (uint256 count);

Parameters

NameTypeDescription
actionId_uint64
endIndex_uint256

Returns

NameTypeDescription
countuint256

_validateConfigQueue​

Validates queue-wide authorization and lifecycle requirements.

Called once, before the first sub-action acquires configuration keys. Implementations must revert when the caller or current product lifecycle cannot queue the batch.

function _validateConfigQueue(address caller_) internal view virtual;

Parameters

NameTypeDescription
caller_addressAccount queueing the batch.

_validateConfigSubAction​

Validates one sub-action before its destination and configuration keys are stored.

Implementations must revert for unsupported targets, selectors, payloads, or product state. Any state recorded by an earlier sub-action is rolled back if validation fails.

function _validateConfigSubAction(
address caller_,
uint64 actionId_,
uint256 index_,
ITimelockBatchQueue.BatchAction memory action_
) internal view virtual;

Parameters

NameTypeDescription
caller_addressAccount queueing the batch.
actionId_uint64Action ID reserved for the batch.
index_uint256Position of the sub-action within the batch.
action_ITimelockBatchQueue.BatchActionSub-action to validate.

_configDestination​

Selects the destination that namespaces this sub-action's configuration keys.

The base stores this address at queue time and requires the hook to return the same address at execution. Returning a new address after rotation creates a distinct key namespace for new actions and makes existing actions non-executable.

function _configDestination(
ITimelockBatchQueue.BatchAction memory action_
) internal view virtual returns (address destination);

Parameters

NameTypeDescription
action_ITimelockBatchQueue.BatchAction

Returns

NameTypeDescription
destinationaddress

_configKeys​

Selects the destination-local configuration domains used by a sub-action.

The base rejects zero or duplicate local keys and scopes every key with the address returned by _configDestination before acquiring ownership.

function _configKeys(
ITimelockBatchQueue.BatchAction memory action_
) internal view virtual returns (bytes32[] memory keys);

Parameters

NameTypeDescription
action_ITimelockBatchQueue.BatchAction

Returns

NameTypeDescription
keysbytes32[]

_currentConfigStateHash​

Hashes the live configuration state guarded by one local key.

Called when queueing to store the expected hash and again immediately before execution to detect stale state. Implementations must hash the same canonical fields on both paths and exclude values that may legitimately change during the timelock delay.

function _currentConfigStateHash(
uint64 actionId_,
uint256 index_,
bytes32 key_,
ITimelockBatchQueue.BatchAction memory action_
) internal view virtual returns (bytes32 stateHash);

Parameters

NameTypeDescription
actionId_uint64ID of the queued action.
index_uint256Position of the sub-action within the batch.
key_bytes32Destination-local configuration key being guarded.
action_ITimelockBatchQueue.BatchActionSub-action whose live configuration state is hashed.

Returns

NameTypeDescription
stateHashbytes32Canonical hash of the guarded live state.

_validateConfigBatch​

Validates invariants spanning the complete batch after all guards are acquired.

The default implementation is a no-op. An override must revert on invalid cross-action state; the revert rolls back every guard acquired for the batch.

function _validateConfigBatch(
address caller_,
uint64 actionId_,
ITimelockBatchQueue.BatchAction[] memory actions_
) internal view virtual;

Parameters

NameTypeDescription
caller_addressAccount queueing the batch.
actionId_uint64Action ID reserved for the batch.
actions_ITimelockBatchQueue.BatchAction[]Complete ordered set of queued sub-actions.

_executeConfigSubAction​

Subclasses must not perform a state-changing external call before the intended target dispatch. Such a call could make the already-validated state stale.

function _executeConfigSubAction(
uint64 actionId_,
uint256 index_,
ITimelockBatchQueue.BatchAction memory action_
) internal virtual;

Parameters

NameTypeDescription
actionId_uint64
index_uint256
action_ITimelockBatchQueue.BatchAction

_maxConfigKeysPerBatch​

Maximum aggregate number of configuration keys a batch may reserve.

Defaults to the maximum number of sub-actions. Products supporting composite multi-domain sub-actions should override this batch-wide bound.

function _maxConfigKeysPerBatch() internal view virtual returns (uint256 maximum);

Returns

NameTypeDescription
maximumuint256

supportsInterface​

Query if a contract implements an interface.

Does not revert.

function supportsInterface(
bytes4 interfaceId_
) public view virtual override(TimelockBatchQueue) returns (bool);

Parameters

NameTypeDescription
interfaceId_bytes4The interface identifier, as specified in ERC-165.

Returns

NameTypeDescription
<none>boolbool True if the contract implements interfaceId_.

Structs​

QueuedConfigState​

struct QueuedConfigState {
bytes32 localKey;
bytes32 expectedStateHash;
}

Properties

NameTypeDescription
localKeybytes32
expectedStateHashbytes32