-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: simplify naming and logic in registries and registry coordinator #43
Conversation
… naming and logic
@@ -386,35 +386,26 @@ contract StakeRegistry is StakeRegistryStorage { | |||
return; | |||
} | |||
|
|||
uint96 prevStake; | |||
// Get our last-recorded stake update | |||
uint256 historyLength = _totalStakeHistory[quorumNumber].length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert if 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to add an explicit comment about this, but this method assumes the quorum exists. all calling locations already perform this check, and will revert higher in the stack if it's caught - so we don't necessarily need an explicit check here.
updateStakes
doesnt currently check this, but i'm moving that out of this contract anyway.
|
||
/// @notice Returns the most recent operator count update for a quorum | ||
/// @dev Reverts if the quorum does not exist (history length == 0) | ||
function _latestQuorumUpdate(uint8 quorumNumber) internal view returns (QuorumUpdate storage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_getLatestQuorumUpdate
? same below?
…ry. also fix tests
fromBlockNumber: uint32(block.number) | ||
})); | ||
function _increaseOperatorCount(uint8 quorumNumber) internal returns (uint32) { | ||
QuorumUpdate storage lastUpdate = _latestQuorumUpdate(quorumNumber); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems unrelated to this PR(?) but I think calling this struct 'QuorumUpdate' is super vague. It should probably be an 'OperatorCountUpdate' or something similar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IndexRegistry looking good, really liking the changes to it overall; I added some comments but I don't think anything is big, just nits or discussion points. Will be proceeding with remainder of review.
_verifyChurnApproverSignature({ | ||
registeringOperatorId: operatorIdsToSwap[0], | ||
operatorKickParams: operatorKickParams, | ||
signatureWithSaltAndExpiry: signatureWithSaltAndExpiry | ||
churnApproverSignature: churnApproverSignature |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we maybe do this earlier in this function?
seems like a fairly late revert condition, but I guess those are somewhat difficult to avoid in this design overall.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes :)
i'm doing this in a future PR
/// @notice maps operator address => operator id and status | ||
mapping(address => Operator) internal _operatorInfo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we perhaps name the struct 'OperatorInfo' as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. Will make this change in a future pr.
} | ||
|
||
// set the operatorId to quorum bitmap history | ||
_operatorIdToQuorumBitmapHistory[operatorId].push(QuorumBitmapUpdate({ | ||
_operatorBitmapHistory[operatorId].push(QuorumBitmapUpdate({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we are still pushing an update, as opposed to modifying the previous update (if the block number is the same).
seems fine to implement later, just pointing this out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see TODOs elsewhere so only called out this location
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTM.
Feels fine to merge this as-is; I looked through everything and don't have any substantive issues, mostly just suggestions for further changes.
…nt with corresponding state lookup
Motivation:
RegistryCoordinator.createQuorum
and its associatedinitializeQuorum
methods in each registryThis PR:
initializeQuorum
method)For reviewers, this order may work best:
IndexRegistry
changes in the first commit, which contains the functional changes mentioned above, as well as readability/logical simplification. This is the worst commit to review, sorry! The diff looks intimidating, so I'd recommend opening the new/old IndexRegistry files side by side and comparing like that. 🙏Renaming changes:
IndexRegistry
state vars:operatorIdToIndex
->currentOperatorIndex
_totalOperatorsHistory
->_operatorCountHistory
_indexToOperatorIdHistory
->_indexHistory
IndexRegistry
functions:_getTotalOperatorsForQuorumAtBlockNumber
->_operatorCountAtBlockNumber
_getOperatorIdAtIndexForQuorumAtBlockNumber
->_operatorIdForIndexAtBlockNumber
getOperatorIndexUpdateOfIndexForQuorumAtIndex
->getOperatorUpdateAtIndex
getTotalOperatorsForQuorumAtBlockNumberByIndex
->getTotalOperatorsForIndexAtBlockNumber
getOperatorListForQuorumAtBlockNumber
->getOperatorListAtBlockNumber
StakeRegistry
state vars:operatorIdToStakeHistory
->operatorStakeHistory
strategiesConsideredAndMultipliers
->strategyParams
StakeRegistry
structs:StrategyAndWeightingMultiplier
->StrategyParams
StakeRegistry
functions:strategiesConsideredAndMultipliersLength
->strategyParamsLength
strategyAndWeightingMultiplierForQuorumByIndex
->strategyParamsByIndex
getOperatorIdToStakeHistory
->getOperatorStakeHistory
getLengthOfTotalStakeHistoryForQuorum
->getTotalStakeHistoryLength
getTotalStakeUpdateForQuorumFromIndex
->getTotalStakeUpdateAtIndex
getStakeUpdateIndexForOperatorIdForQuorumAtBlockNumber
->getStakeUpdateIndexForOperatorAtBlockNumber
getTotalStakeIndicesByQuorumNumbersAtBlockNumber
->getTotalStakeIndicesAtBlockNumber
getStakeUpdateForQuorumFromOperatorIdAndIndex
->getStakeUpdateForOperatorAtIndex
getStakeForQuorumAtBlockNumberFromOperatorIdAndIndex
->getOperatorStakeAtBlockNumberAndIndex
getStakeForOperatorIdForQuorumAtBlockNumber
->getOperatorStakeAtBlockNumber
getLengthOfOperatorIdStakeHistoryForQuorum
->getOperatorStakeHistoryLength
BLSRegistryCoordinatorWithIndices
state vars:_quorumOperatorSetParams
->_quorumParams
_operatorIdToQuorumBitmapHistory
->_operatorBitmapHistory
_operators
->_operatorInfo
BLSRegistryCoordinatorWithIndices
state modifying functions:registerOperatorWithCoordinator
->registerOperator
registerOperatorWithCoordinator
->registerOperatorWithChurn
deregisterOperatorWithCoordinator
->deregisterOperator
ejectOperatorFromCoordinator
->ejectOperator
BLSRegistryCoordinatorWithIndices
view functions:getQuorumBitmapIndicesByOperatorIdsAtBlockNumber
->getQuorumBitmapIndicesAtBlockNumber
getQuorumBitmapByOperatorIdAtBlockNumberByIndex
->getQuorumBitmapAtBlockNumberByIndex
getQuorumBitmapUpdateByOperatorIdByIndex
->getQuorumBitmapUpdateByIndex
getCurrentQuorumBitmapByOperatorId
->getCurrentQuorumBitmap
getQuorumBitmapUpdateByOperatorIdLength
->getQuorumBitmapHistoryLength
IndexRegistry
changes:registerOperator
is now_increaseOperatorCount
+_assignOperatorToIndex
. Functional changes:QuorumUpdate/OperatorUpdate
is from this block, we update the last entry rather than pushing a new one.deregisterOperator
is now_decreaseOperatorCount
+_popLastOperator
+_assignOperatorToIndex
. Functional changes:currentOperatorIndex[quorum][OPERATOR_DOES_NOT_EXIST_ID]
to the removed index, and emitted an event for this update. This logic has been removed, since thecurrentOperatorIndex
of the null id doesn't matter. See previous logic vs new logic