Skip to content

Commit

Permalink
chore: de-duplicate code into an internal function
Browse files Browse the repository at this point in the history
see suggestion here:
#102 (comment)

saves ~0.25kb in code size
  • Loading branch information
ChaoticWalrus committed Dec 13, 2023
1 parent 0db5eb5 commit 891a219
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/RegistryCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,9 @@ contract RegistryCoordinator is
) external onlyWhenNotPaused(PAUSED_REGISTER_OPERATOR) {
/**
* IF the operator has never registered a pubkey before, THEN register their pubkey
* OTHERWISE, simply ignore the provided `params`
* OTHERWISE, simply ignore the provided `params` input
*/
bytes32 operatorId = blsApkRegistry.getOperatorId(msg.sender);
if (operatorId == 0) {
operatorId = blsApkRegistry.registerBLSPublicKey(msg.sender, params, pubkeyRegistrationMessageHash(msg.sender));
}
bytes32 operatorId = _getOrCreateOperatorId(msg.sender, params);

// Register the operator in each of the registry contracts
RegisterResults memory results = _registerOperator({
Expand Down Expand Up @@ -228,12 +225,9 @@ contract RegistryCoordinator is

/**
* IF the operator has never registered a pubkey before, THEN register their pubkey
* OTHERWISE, simply ignore the `pubkeyRegistrationSignature`, `pubkeyG1`, and `pubkeyG2` inputs
* OTHERWISE, simply ignore the provided `params` input
*/
bytes32 operatorId = blsApkRegistry.getOperatorId(msg.sender);
if (operatorId == 0) {
operatorId = blsApkRegistry.registerBLSPublicKey(msg.sender, params, pubkeyRegistrationMessageHash(msg.sender));
}
bytes32 operatorId = _getOrCreateOperatorId(msg.sender, params);

// Verify the churn approver's signature for the registering operator and kick params
_verifyChurnApproverSignature({
Expand Down Expand Up @@ -519,6 +513,17 @@ contract RegistryCoordinator is
});
}

function _getOrCreateOperatorId(
address operator,
IBLSApkRegistry.PubkeyRegistrationParams calldata params
) internal returns (bytes32 operatorId) {
operatorId = blsApkRegistry.getOperatorId(msg.sender);
if (operatorId == 0) {
operatorId = blsApkRegistry.registerBLSPublicKey(msg.sender, params, pubkeyRegistrationMessageHash(msg.sender));
}
return operatorId;
}

function _validateChurn(
uint8 quorumNumber,
uint96 totalQuorumStake,
Expand Down

0 comments on commit 891a219

Please sign in to comment.