Execution
Overview
The most important part of the PowerAgent operation. This section describes all steps performed by a Keeper and the Agent contract to execute the Job at a given time (or upon satisfying given conditions).
Whenever execution conditions are met, a Keeper is chosen to execute the task. Alternatively, a Keeper can be pre-selected for the next execution when a number of events happen (e.g. the job parameters or credits values change).
Keeper selection
For more information on Keeper selection, see <page>.
Specification
The chosen Keeper calls the function execute_44g58pv of the Agent contract, passing required calldata dependent on the type of the Job and the config for the execution.
The function is heavily optimized for gas savings; inline assembly is used alongside with binary operations.
cfg
0x | name | binary
01 | FLAG_ACCEPT_MAX_BASE_FEE_LIMIT | 0...001
02 | FLAG_ACCRUE_REWARD | 0...010This config is constructed by the Keeper for each execution separately. Setting the flags allows the keeper to override reversion when the block base gas fee exceeds the limit set by the job owner; the second boolean flag determines whether to accrue the reward for the execution on the PowerAgent contract or transfer it to the keeper worker address immediately.
calldata
Calldata passed by the keeper for the target function execution. Read this section for information on execution calldata.
Algorithm
Hooks
The hook functions are used to process execution calls by slashers (INSERT LINK TO SLASHING).
Their implementation varies depending on the realisation of the PowerAgent.
_beforeExecute
This hook is called at the very beginning of the execute function. It executes only if the caller is a slasher.
The purpose of this hook is to ensure that by the time the slasher called this function, the slashing has been initiated and the task has been failed by the assigned keeper. If so, after the hook the execution continues, and the slasher becomes the executor of the task. Otherwise, a corresponding error is thrown, and the slasher is reverted.
_afterExecutionSucceeded
Called at the end if the execution was successful.
_afterExecutionReverted
Called at the end if the transaction was reverted by the Job contract.
Select a Keeper
Flashbots
At the current state of PPagentV2, the keeper to execute the task is selected by the Flashbots: the one offering the highest gas price is chosen, others are reverted with no cost.
RanDAO
Choosing a keeper by random seems like a smart idea.
In the RanDAO version, the choice is made by the following algorithm:
Keeper assignment only takes place at either a corresponding external call by a job owner, after a successful job execution, after a job is registered; if a job changes its activity status or credit amount deposited, the keeper is assigned conditionally if the job has at least the minimal admissible amount of credits (specified by the RanDAO realisation config parameter rdConfig.jobMinCreditsFinney).
Last updated
Was this helpful?