Skip to content

Commit

Permalink
Implement getTotalChainConfigurations (#1419)
Browse files Browse the repository at this point in the history
## Motivation
The goal of this PR is to add a getter function to the `CCIPConfig`
contract to fetch the total number of chains configured. This value is
necessary to correctly call `getAllChainConfigs` and previously, the
only way to access it was through events.

## Solution
Implement `getTotalChainConfigurations`.
  • Loading branch information
RayXpub authored Sep 10, 2024
1 parent d48e3c0 commit 31a15dd
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 29 deletions.
50 changes: 25 additions & 25 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -36,44 +36,44 @@ BurnWithFromMintTokenPool_lockOrBurn:test_PoolBurn_Success() (gas: 243707)
BurnWithFromMintTokenPool_lockOrBurn:test_Setup_Success() (gas: 23951)
CCIPClientExample_sanity:test_ImmutableExamples_Success() (gas: 2096747)
CCIPConfigSetup:test_getCapabilityConfiguration_Success() (gas: 9539)
CCIPConfig_ConfigStateMachine:test__computeConfigDigest_Success() (gas: 66088)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_InitToRunning_Success() (gas: 358063)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_RunningToStaging_Success() (gas: 474771)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_StagingToRunning_Success() (gas: 441974)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_TooManyOCR3Configs_Reverts() (gas: 33804)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_threeCommitConfigs_Reverts() (gas: 56870)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_threeExecutionConfigs_Reverts() (gas: 56808)
CCIPConfig_ConfigStateMachine:test__computeConfigDigest_Success() (gas: 66000)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_InitToRunning_Success() (gas: 358041)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_RunningToStaging_Success() (gas: 474705)
CCIPConfig_ConfigStateMachine:test__computeNewConfigWithMeta_StagingToRunning_Success() (gas: 441908)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_TooManyOCR3Configs_Reverts() (gas: 33848)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_threeCommitConfigs_Reverts() (gas: 56914)
CCIPConfig_ConfigStateMachine:test__groupByPluginType_threeExecutionConfigs_Reverts() (gas: 56852)
CCIPConfig_ConfigStateMachine:test__stateFromConfigLength_Success() (gas: 11719)
CCIPConfig_ConfigStateMachine:test__validateConfigStateTransition_Success() (gas: 8780)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_InitToRunning_Success() (gas: 309744)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_InitToRunning_WrongConfigCount_Reverts() (gas: 45887)
CCIPConfig_ConfigStateMachine:test__validateConfigStateTransition_Success() (gas: 8849)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_InitToRunning_Success() (gas: 309722)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_InitToRunning_WrongConfigCount_Reverts() (gas: 45865)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_NonExistentConfigTransition_Reverts() (gas: 29690)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_Success() (gas: 370075)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigCount_Reverts() (gas: 111442)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigDigestBlueGreen_Reverts() (gas: 145556)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_Success() (gas: 369851)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_WrongConfigDigest_Reverts() (gas: 145623)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_Success() (gas: 370009)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigCount_Reverts() (gas: 111376)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_RunningToStaging_WrongConfigDigestBlueGreen_Reverts() (gas: 145446)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_Success() (gas: 369785)
CCIPConfig_ConfigStateMachine:test__validateConfigTransition_StagingToRunning_WrongConfigDigest_Reverts() (gas: 145513)
CCIPConfig_ConfigStateMachine:test_getCapabilityConfiguration_Success() (gas: 9627)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitAndExecConfig_Success() (gas: 1752579)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitConfigOnly_Success() (gas: 1019042)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_ExecConfigOnly_Success() (gas: 1019073)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitAndExecConfig_Success() (gas: 1752535)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_CommitConfigOnly_Success() (gas: 1019020)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_ExecConfigOnly_Success() (gas: 1019051)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_OnlyCapabilitiesRegistryCanCall_Reverts() (gas: 9611)
CCIPConfig_beforeCapabilityConfigSet:test_beforeCapabilityConfigSet_ZeroLengthConfig_Success() (gas: 15996)
CCIPConfig_beforeCapabilityConfigSet:test_getCapabilityConfiguration_Success() (gas: 9627)
CCIPConfig_chainConfig:test__applyChainConfigUpdates_FChainNotPositive_Reverts() (gas: 184771)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_addChainConfigs_Success() (gas: 344939)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_addChainConfigs_Success() (gas: 346687)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_nodeNotInRegistry_Reverts() (gas: 20340)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_removeChainConfigs_Success() (gas: 267596)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_removeChainConfigs_Success() (gas: 270334)
CCIPConfig_chainConfig:test_applyChainConfigUpdates_selectorNotFound_Reverts() (gas: 14819)
CCIPConfig_chainConfig:test_getCapabilityConfiguration_Success() (gas: 9648)
CCIPConfig_chainConfig:test_getPaginatedCCIPConfigs_Success() (gas: 370293)
CCIPConfig_constructor:test_constructor_Success() (gas: 3334093)
CCIPConfig_constructor:test_constructor_ZeroAddressNotAllowed_Revert() (gas: 61438)
CCIPConfig_updatePluginConfig:test__updatePluginConfig_InitToRunning_Success() (gas: 1008449)
CCIPConfig_constructor:test_constructor_Success() (gas: 3344515)
CCIPConfig_constructor:test_constructor_ZeroAddressNotAllowed_Revert() (gas: 61446)
CCIPConfig_updatePluginConfig:test__updatePluginConfig_InitToRunning_Success() (gas: 1008427)
CCIPConfig_updatePluginConfig:test__updatePluginConfig_InvalidConfigLength_Reverts() (gas: 25584)
CCIPConfig_updatePluginConfig:test__updatePluginConfig_InvalidConfigStateTransition_Reverts() (gas: 21799)
CCIPConfig_updatePluginConfig:test__updatePluginConfig_RunningToStaging_Success() (gas: 1895621)
CCIPConfig_updatePluginConfig:test__updatePluginConfig_StagingToRunning_Success() (gas: 2465231)
CCIPConfig_updatePluginConfig:test__updatePluginConfig_RunningToStaging_Success() (gas: 1895604)
CCIPConfig_updatePluginConfig:test__updatePluginConfig_StagingToRunning_Success() (gas: 2465196)
CCIPConfig_updatePluginConfig:test_getCapabilityConfiguration_Success() (gas: 9627)
CCIPConfig_validateConfig:test__validateConfig_ABIEncodedAddress_OfframpAddressCannotBeZero_Reverts() (gas: 290828)
CCIPConfig_validateConfig:test__validateConfig_ChainSelectorNotFound_Reverts() (gas: 293559)
Expand Down
6 changes: 6 additions & 0 deletions contracts/src/v0.8/ccip/capability/CCIPConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ contract CCIPConfig is ITypeAndVersion, ICapabilityConfiguration, OwnerIsCreator
return i_capabilitiesRegistry;
}

/// @notice Returns the total number of chains configured.
/// @return The total number of chains configured.
function getNumChainConfigurations() external view returns (uint256) {
return s_remoteChainSelectors.length();
}

/// @notice Returns all the chain configurations.
/// @param pageIndex The page index.
/// @param pageSize The page size.
Expand Down
6 changes: 5 additions & 1 deletion contracts/src/v0.8/ccip/test/capability/CCIPConfig.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.24;

import {SortedSetValidationUtil} from "../../../shared/util/SortedSetValidationUtil.sol";
import {CCIPConfig} from "../../capability/CCIPConfig.sol";
import {ICapabilitiesRegistry} from "../../capability/interfaces/ICapabilitiesRegistry.sol";
import {CCIPConfigTypes} from "../../capability/libraries/CCIPConfigTypes.sol";
Expand Down Expand Up @@ -164,6 +163,7 @@ contract CCIPConfig_chainConfig is CCIPConfigSetup {
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");
assertEq(s_ccipCC.getNumChainConfigurations(), 2, "total chain configs must be 2");
}

function test_getPaginatedCCIPConfigs_Success() public {
Expand Down Expand Up @@ -252,12 +252,16 @@ contract CCIPConfig_chainConfig is CCIPConfigSetup {
emit CCIPConfig.ChainConfigSet(2, adds[1].chainConfig);
s_ccipCC.applyChainConfigUpdates(new uint64[](0), adds);

assertEq(s_ccipCC.getNumChainConfigurations(), 2, "total chain configs must be 2");

uint64[] memory removes = new uint64[](1);
removes[0] = uint64(1);

vm.expectEmit();
emit CCIPConfig.ChainConfigRemoved(1);
s_ccipCC.applyChainConfigUpdates(removes, new CCIPConfigTypes.ChainConfigInfo[](0));

assertEq(s_ccipCC.getNumChainConfigurations(), 1, "total chain configs must be 1");
}

// Reverts.
Expand Down
28 changes: 26 additions & 2 deletions core/gethwrappers/ccip/generated/ccip_config/ccip_config.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ burn_mint_token_pool: ../../../contracts/solc/v0.8.24/BurnMintTokenPool/BurnMint
burn_mint_token_pool_and_proxy: ../../../contracts/solc/v0.8.24/BurnMintTokenPoolAndProxy/BurnMintTokenPoolAndProxy.abi ../../../contracts/solc/v0.8.24/BurnMintTokenPoolAndProxy/BurnMintTokenPoolAndProxy.bin 717c079d5d13300cf3c3ee871c6e5bf9af904411f204fb081a9f3b263cca1391
burn_with_from_mint_token_pool: ../../../contracts/solc/v0.8.24/BurnWithFromMintTokenPool/BurnWithFromMintTokenPool.abi ../../../contracts/solc/v0.8.24/BurnWithFromMintTokenPool/BurnWithFromMintTokenPool.bin 6333d0314d0bd29e75ea5e05fe62a4516ade0c6db91c30b6f93645035db52ed8
burn_with_from_mint_token_pool_and_proxy: ../../../contracts/solc/v0.8.24/BurnWithFromMintTokenPoolAndProxy/BurnWithFromMintTokenPoolAndProxy.abi ../../../contracts/solc/v0.8.24/BurnWithFromMintTokenPoolAndProxy/BurnWithFromMintTokenPoolAndProxy.bin 08ed1235dda921ce8841b26aa18d0c0f36db4884779dd7670857159801b6d597
ccip_config: ../../../contracts/solc/v0.8.24/CCIPConfig/CCIPConfig.abi ../../../contracts/solc/v0.8.24/CCIPConfig/CCIPConfig.bin 75955a3dcfd66b308be07eda54d6036cc79e87d3cdcf3c5c3115813c55912af8
ccip_config: ../../../contracts/solc/v0.8.24/CCIPConfig/CCIPConfig.abi ../../../contracts/solc/v0.8.24/CCIPConfig/CCIPConfig.bin b64994e8719f666101322b32c87d7d569b865be30bc6966aa8751ecb9249bcf4
ccip_reader_tester: ../../../contracts/solc/v0.8.24/CCIPReaderTester/CCIPReaderTester.abi ../../../contracts/solc/v0.8.24/CCIPReaderTester/CCIPReaderTester.bin 481d461f14c98308cd788b64be1151e92bac6f95ddd55eefc926296454316f13
commit_store: ../../../contracts/solc/v0.8.24/CommitStore/CommitStore.abi ../../../contracts/solc/v0.8.24/CommitStore/CommitStore.bin 274d87db70b643e00ab0a7e7845bb4b791f3b613bfc87708d33fc5a8369e2a41
commit_store_helper: ../../../contracts/solc/v0.8.24/CommitStoreHelper/CommitStoreHelper.abi ../../../contracts/solc/v0.8.24/CommitStoreHelper/CommitStoreHelper.bin f7128dcc2ee6dbcbc976288abcc16970ffb19b59412c5202ef6b259d2007f801
Expand Down

0 comments on commit 31a15dd

Please sign in to comment.