Skip to content

Commit 70097c7

Browse files
authored
feat: add view function for total operator count in quorum (#449)
**Motivation:** Getting the operator count in a quorum at a past block requires 2 calls. This would make it take 1 and improve DEVX for getting this info **Modifications:** Expose the checked mapping and return the data **Result:** Total operator count for quorum available via a view function
1 parent 3a97e4f commit 70097c7

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/IndexRegistry.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,14 @@ contract IndexRegistry is IndexRegistryStorage {
332332
return _latestQuorumUpdate(quorumNumber).numOperators;
333333
}
334334

335+
/// @inheritdoc IIndexRegistry
336+
function totalOperatorsForQuorumAtBlockNumber(
337+
uint8 quorumNumber,
338+
uint32 blockNumber
339+
) external view returns (uint32) {
340+
return _operatorCountAtBlockNumber(quorumNumber, blockNumber);
341+
}
342+
335343
function _checkRegistryCoordinator() internal view {
336344
require(msg.sender == address(registryCoordinator), OnlyRegistryCoordinator());
337345
}

src/interfaces/IIndexRegistry.sol

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,15 @@ interface IIndexRegistry is IIndexRegistryErrors, IIndexRegistryEvents {
175175
function totalOperatorsForQuorum(
176176
uint8 quorumNumber
177177
) external view returns (uint32);
178+
179+
/*
180+
* @notice Returns the total number of operators in quorum `quorumNumber` at block `blockNumber`.
181+
* @param quorumNumber The identifier of the quorum.
182+
* @param blockNumber The block number to query.
183+
* @return The total number of operators at the specified block.
184+
*/
185+
function totalOperatorsForQuorumAtBlockNumber(
186+
uint8 quorumNumber,
187+
uint32 blockNumber
188+
) external view returns (uint32);
178189
}

test/unit/IndexRegistryUnit.t.sol

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,23 @@ contract IndexRegistryUnitTests_configAndGetters is IndexRegistryUnitTests {
424424
assertEq(quorumUpdate.numOperators, 0, "numOperators not 0");
425425
assertEq(quorumUpdate.fromBlockNumber, block.number, "fromBlockNumber not correct");
426426
}
427+
428+
function test_totalOperatorsForQuorumAtBlockNumber() public {
429+
uint8 quorumNumber = nextQuorum;
430+
_initializeQuorum();
431+
uint32 blockNumInit = uint32(block.number);
432+
433+
// Initially, 0 operators
434+
assertEq(indexRegistry.totalOperatorsForQuorumAtBlockNumber(quorumNumber, blockNumInit), 0);
435+
436+
vm.roll(block.number + 5);
437+
uint32 blockNumReg1 = uint32(block.number);
438+
(, bytes32 operatorId1) = _selectNewOperator();
439+
_registerOperatorSingleQuorum(operatorId1, quorumNumber);
440+
// Check count at current and past blocks
441+
assertEq(indexRegistry.totalOperatorsForQuorumAtBlockNumber(quorumNumber, blockNumReg1), 1);
442+
assertEq(indexRegistry.totalOperatorsForQuorumAtBlockNumber(quorumNumber, blockNumInit), 0);
443+
}
427444
}
428445

429446
contract IndexRegistryUnitTests_registerOperator is IndexRegistryUnitTests {
@@ -474,7 +491,7 @@ contract IndexRegistryUnitTests_registerOperator is IndexRegistryUnitTests {
474491
* 2. quorumNumbers ordered in ascending order
475492
* 3. quorumBitmap is <= uint192.max
476493
* 4. quorumNumbers.length != 0
477-
* 5. operator is not already registerd for any quorums being registered for
494+
* 5. operator is not already registered for any quorums being registered for
478495
*/
479496
function test_registerOperator() public {
480497
// register an operator
@@ -601,7 +618,7 @@ contract IndexRegistryUnitTests_registerOperator is IndexRegistryUnitTests {
601618
* 2. quorumNumbers ordered in ascending order
602619
* 3. quorumBitmap is <= uint192.max
603620
* 4. quorumNumbers.length != 0
604-
* 5. operator is not already registerd for any quorums being registered for
621+
* 5. operator is not already registered for any quorums being registered for
605622
*/
606623
function testFuzz_registerOperator_MultipleQuorums(
607624
uint192 bitmap

0 commit comments

Comments
 (0)