Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/contracts/interfaces/ICrossChainRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,18 @@ interface ICrossChainRegistry is ICrossChainRegistryErrors, ICrossChainRegistryE
uint256 endIndex
) external view returns (OperatorSet[] memory);

/**
* @notice Checks if a given operatorSet has an active generation reservation
* @param operatorSet the operatorSet to check
* @return True if the operatorSet has an active generation reservation, false otherwise
*/
function hasActiveGenerationReservation(
OperatorSet memory operatorSet
) external view returns (bool);

/**
* @notice Gets the operatorTableCalculator for a given operatorSet
* @dev You may want to query `hasActiveGenerationReservation` before calling this method
* @param operatorSet the operatorSet to get the operatorTableCalculator for
* @return The operatorTableCalculator for the given operatorSet
*/
Expand All @@ -280,6 +290,7 @@ interface ICrossChainRegistry is ICrossChainRegistryErrors, ICrossChainRegistryE

/**
* @notice Gets the operatorSetConfig for a given operatorSet
* @dev You may want to query `hasActiveGenerationReservation` before calling this method.
* @param operatorSet the operatorSet to get the operatorSetConfig for
* @return The operatorSetConfig for the given operatorSet
*/
Expand All @@ -289,6 +300,7 @@ interface ICrossChainRegistry is ICrossChainRegistryErrors, ICrossChainRegistryE

/**
* @notice Calculates the operatorTableBytes for a given operatorSet
* @dev You may want to query `hasActiveGenerationReservation` before calling this method.
* @param operatorSet the operatorSet to calculate the operator table for
* @return the encoded operatorTableBytes containing:
* - operatorSet details
Expand Down
17 changes: 12 additions & 5 deletions src/contracts/multichain/CrossChainRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ contract CrossChainRegistry is
_;
}

modifier hasActiveGenerationReservation(
modifier checkHasActiveGenerationReservation(
OperatorSet calldata operatorSet
) {
require(_activeGenerationReservations.contains(operatorSet.key()), GenerationReservationDoesNotExist());
require(hasActiveGenerationReservation(operatorSet), GenerationReservationDoesNotExist());
_;
}

Expand Down Expand Up @@ -135,7 +135,7 @@ contract CrossChainRegistry is
onlyWhenNotPaused(PAUSED_GENERATION_RESERVATIONS)
checkCanCall(operatorSet.avs)
isValidOperatorSet(operatorSet)
hasActiveGenerationReservation(operatorSet)
checkHasActiveGenerationReservation(operatorSet)
{
bytes32 operatorSetKey = operatorSet.key();

Expand All @@ -162,7 +162,7 @@ contract CrossChainRegistry is
onlyWhenNotPaused(PAUSED_OPERATOR_TABLE_CALCULATOR)
checkCanCall(operatorSet.avs)
isValidOperatorSet(operatorSet)
hasActiveGenerationReservation(operatorSet)
checkHasActiveGenerationReservation(operatorSet)
{
// Set the operator table calculator
_setOperatorTableCalculator(operatorSet, operatorTableCalculator);
Expand All @@ -177,7 +177,7 @@ contract CrossChainRegistry is
onlyWhenNotPaused(PAUSED_OPERATOR_SET_CONFIG)
checkCanCall(operatorSet.avs)
isValidOperatorSet(operatorSet)
hasActiveGenerationReservation(operatorSet)
checkHasActiveGenerationReservation(operatorSet)
{
// Set the operator set config
_setOperatorSetConfig(operatorSet, config);
Expand Down Expand Up @@ -291,6 +291,13 @@ contract CrossChainRegistry is
return operatorSets;
}

/// @inheritdoc ICrossChainRegistry
function hasActiveGenerationReservation(
OperatorSet memory operatorSet
) public view returns (bool) {
return _activeGenerationReservations.contains(operatorSet.key());
}

/// @inheritdoc ICrossChainRegistry
function getActiveGenerationReservationsByRange(
uint256 startIndex,
Expand Down
17 changes: 17 additions & 0 deletions src/test/unit/CrossChainRegistryUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1046,3 +1046,20 @@ contract CrossChainRegistryUnitTests_getActiveGenerationReservationCount is Cros
assertEq(count, numReservations, "Count should match expected number");
}
}

contract CrossChainRegistryUnitTests_hasActiveGenerationReservation is CrossChainRegistryUnitTests {
function test_hasActiveGenerationReservation_Single() public {
bool hasReservation = crossChainRegistry.hasActiveGenerationReservation(defaultOperatorSet);
assertFalse(hasReservation, "Should not have any reservations");

crossChainRegistry.createGenerationReservation(defaultOperatorSet, defaultCalculator, defaultConfig);

hasReservation = crossChainRegistry.hasActiveGenerationReservation(defaultOperatorSet);
assertTrue(hasReservation, "Should have a reservation");

crossChainRegistry.removeGenerationReservation(defaultOperatorSet);

hasReservation = crossChainRegistry.hasActiveGenerationReservation(defaultOperatorSet);
assertFalse(hasReservation, "Should not have a reservation");
}
}