Skip to content

Commit

Permalink
feat: CCIP-2594 CCIPCapabilityConfig query with pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshmi kanth committed Jun 27, 2024
1 parent 05a1d3f commit 7ec9e90
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
22 changes: 15 additions & 7 deletions contracts/src/v0.8/ccip/capability/CCIPCapabilityConfiguration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,30 @@ contract CCIPCapabilityConfiguration is ITypeAndVersion, ICapabilityConfiguratio
i_capabilityRegistry = capabilityRegistry;
}


// ================================================================
// │ Config Getters │
// ================================================================

/// @notice Returns all the chain configurations.
/// @return The chain configurations.
// TODO: will this eventually hit the RPC max response size limit?
function getAllChainConfigs() external view returns (ChainConfigInfo[] memory) {
/// @return paginatedChainConfigs chain configurations.
function getAllChainConfigs(uint256 pageIndex, uint256 pageSize) external view returns (ChainConfigInfo[] memory paginatedChainConfigs) {
uint256 totalItems = s_remoteChainSelectors.length(); // Total number of chain selectors
if (pageSize == 0 || pageIndex * pageSize >= totalItems) {
return new ChainConfigInfo[](0); // Return an empty array if pageSize is 0 or pageIndex is out of bounds
}

uint256 startIndex = pageIndex * pageSize;
uint256 endIndex = startIndex + pageSize > totalItems ? totalItems : startIndex + pageSize;

paginatedChainConfigs = new ChainConfigInfo[](endIndex - startIndex);

uint256[] memory chainSelectors = s_remoteChainSelectors.values();
ChainConfigInfo[] memory chainConfigs = new ChainConfigInfo[](s_remoteChainSelectors.length());
for (uint256 i = 0; i < chainSelectors.length; ++i) {
for (uint256 i = startIndex; i < endIndex; ++i) {
uint64 chainSelector = uint64(chainSelectors[i]);
chainConfigs[i] =
paginatedChainConfigs[i - startIndex] =
ChainConfigInfo({chainSelector: chainSelector, chainConfig: s_chainConfigurations[chainSelector]});
}
return chainConfigs;
}

/// @notice Returns the OCR configuration for the given don ID and plugin type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,22 @@ contract CCIPCapabilityConfiguration_chainConfig is CCIPCapabilityConfigurationS
emit CCIPCapabilityConfiguration.ChainConfigSet(2, adds[1].chainConfig);
s_ccipCC.applyChainConfigUpdates(new uint64[](0), adds);

CCIPCapabilityConfiguration.ChainConfigInfo[] memory configs = s_ccipCC.getAllChainConfigs();
CCIPCapabilityConfiguration.ChainConfigInfo[] memory configs = s_ccipCC.getAllChainConfigs(0, 2);
assertEq(configs.length, 2, "chain configs length must be 2");
assertEq(configs[0].chainSelector, 1, "chain selector must match");
assertEq(configs[1].chainSelector, 2, "chain selector must match");

configs = s_ccipCC.getAllChainConfigs(0, 1);
assertEq(configs.length, 1, "chain configs length must be 1");
assertEq(configs[0].chainSelector, 1, "chain selector must match");

configs = s_ccipCC.getAllChainConfigs(0, 10);
assertEq(configs.length, 2, "chain configs length must be 2");
assertEq(configs[0].chainSelector, 1, "chain selector must match");
assertEq(configs[1].chainSelector, 2, "chain selector must match");

configs = s_ccipCC.getAllChainConfigs(1, 1);
assertEq(configs.length, 0, "chain configs length must be 0");
}

function test_applyChainConfigUpdates_removeChainConfigs_Success() public {
Expand Down

0 comments on commit 7ec9e90

Please sign in to comment.