Keeper assignment and release in RanDAO realisation
Keeper assignment
Choice algorithm
The algorithm for a RanDAO-based choice of a next keeper is encoded in the _assignNextKeeper function. We outline it here
Calling the internal function of keeper assignment
Exogeneously
Exogeneous manual keeper assignment is available to the job(s) owner if needed:
Conditionally (on job credits)
Of more interest is the wrapped conditional keeper assignment, since we do not wish keepers to be assigned to jobs with below-minimum resources with which to pay them. This is handled by the internal function
Cases in which conditional assignment is invoked
The conditional keeper assignment happens when:
The job config is updated, with the credits source having changed or a previously inactive job activating
Credits are deposited to a Job (via the overridden hook
_afterDepositJobCredits(bytes32 jobKey)
invoked in functiondepositJobCredits(bytes32 jobKey_)
in the core contract)
Cases in which unconditional assignment is invoked
Unconditional keeper assignment happens when:
Job execution is successful, and the old keeper needs to be swapped for a new one (inside the
function _afterExecutionSucceeded(bytes32 jobKey, uint256 actualKeeperId_, uint256 binJob_) internal
hook).After a job is registered (inside the
function _afterRegisterJob(bytes32 jobKey) internal
hook)
Keeper release
Technical implementation of releasing a keeper
Keeper release is performed by the internal function _releaseKeeper(bytes32 jobKey_, uint256 keeperId_)
and consists of clearing the Job parameters pertaining to the next keeper and possible slashing and removing the job from the keeper's pending pool:
Calling the keeper release function
We need to exercise utmost care in calling such function so that it does not provide malicious keepers with a way to escape punishment.
Firstly, there is a defined conditional release on insufficiency of Job credits, wrapped into a function releaseKeeperIfRequired
, itself wrapping releaseKeeperIfRequiredBinJob
. Since releaseKeeperIfRequired
is a simple wrapping of a call to releaseKeeperIfRequiredBinJob
with a freshly read binary job representation passed as an argument, we only describe the latter function.
This function is called when:
Assigning a keeper (in keeper assignment, a check of
_releaseKeeperIfRequiredBinJob
(with thecheckAlreadyReleased
flag passed asFalse
) beingFalse
ensures no keeper is assigned for an job with too few tokens)Job credits are withdrawn (via the hook
_afterWithdrawJobCredits(bytes32 jobKey_) internal
)releaseJob
is called by a keeper admin (the check happens before any slashing checks and is the only way for a job to be released without satisfying these checks, e.g. when the admissibility period is not over yet, and the keeper is technically locked by the possibility of being slashed, he still can be released from his duty if the job does not meet the minimum credit demand)The job config is updated, with the credits source having changed, and
_assignNextKeeperIfRequired
returningFalse
.
Unwrapped _releaseKeeperIfRequiredBinJob
is called when:
Assigning a new keeper;
checkAlreadyReleased
is passed asFalse
, so this has the meaning of exiting the keeper assignment process when the job/owner does not have sufficient tokens.
Unconditional release is called when:
The job owner calls
releaseJob
The keeper admin calls
releaseJob
, the Job has sufficient (from the Agent's standpoint) credits, and the admissibility period of slashing has elapsedThe keeper is disabled
After execution of the job being automated reverts
The job is deactivated
After execution of the job being automated succeeds
Last updated
Was this helpful?