Keeper assignment and release in RanDAO realisation
Keeper assignment
Choice algorithm
function _assignNextKeeper(bytes32 jobKey_) internal {
//get the randao realisation for the current block, stored in the block.difficulty
uint256 pseudoRandom = _getPseudoRandom();
//get the cardinality of the keeper set so that the index may be taken modulo it
uint256 totalActiveKeepers = activeKeepers.length();
//get the minimal CVP stake demanded of the keeper by the job
uint256 _jobMinKeeperCvp = jobMinKeeperCvp[jobKey_];
//obtain the index by taking the pseudorandom input, adding the job key so that variance in chosen keeper indices is observed within any single block, and mapping the result into the keeper index set by taking the modulo operation
//the resultant variable index is the index of the keeper selected for execution
uint256 index;
unchecked {
index = ((pseudoRandom + uint256(jobKey_)) % totalActiveKeepers);
}
//iterate over all the keepers, starting with the randomly selected one, until a keeper admissible for the job at hand is found or all gas has been expended
while (true) {
//effectively modulo operation
if (index >= totalActiveKeepers) {
index = 0;
}
//obtain the ID of the next keeper by the index selected
uint256 _nextExecutionKeeperId = activeKeepers.at(index);
//required stake is set to be the global minimal demanded CVP unless the job has a specification of its own
uint256 requiredStake = _jobMinKeeperCvp > 0 ? _jobMinKeeperCvp : minKeeperCvp;
//load the keeper object at the selected ID
Keeper memory keeper = keepers[_nextExecutionKeeperId];
//if the keeper is admissible, i.e. active and has sufficient stake, then assign him as the next keeper of the job and terminate the passage
if (keeper.isActive && keeper.cvpStake >= requiredStake) {
jobNextKeeperId[jobKey_] = _nextExecutionKeeperId;
keeperLocksByJob[_nextExecutionKeeperId].add(jobKey_);
emit KeeperJobLock(_nextExecutionKeeperId, jobKey_);
return;
}
index += 1;
}
}
}Calling the internal function of keeper assignment
Exogeneously
Conditionally (on job credits)
Cases in which conditional assignment is invoked
Cases in which unconditional assignment is invoked
Keeper release
Technical implementation of releasing a keeper
Calling the keeper release function
Last updated
Was this helpful?