diff --git a/contracts/src/v0.8/ccip/capability/CCIPCapabilityConfiguration.sol b/contracts/src/v0.8/ccip/capability/CCIPCapabilityConfiguration.sol index 515f9343c68..4c5fa842db7 100644 --- a/contracts/src/v0.8/ccip/capability/CCIPCapabilityConfiguration.sol +++ b/contracts/src/v0.8/ccip/capability/CCIPCapabilityConfiguration.sol @@ -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. diff --git a/contracts/src/v0.8/ccip/test/capability/CCIPCapabilityConfiguration.t.sol b/contracts/src/v0.8/ccip/test/capability/CCIPCapabilityConfiguration.t.sol index 25e6d79c881..d7e54c580b9 100644 --- a/contracts/src/v0.8/ccip/test/capability/CCIPCapabilityConfiguration.t.sol +++ b/contracts/src/v0.8/ccip/test/capability/CCIPCapabilityConfiguration.t.sol @@ -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 {