Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add getter to return all source chain config #1477

Open
wants to merge 13 commits into
base: ccip-develop
Choose a base branch
from
Open
228 changes: 114 additions & 114 deletions contracts/gas-snapshots/ccip.gas-snapshot

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions contracts/src/v0.8/ccip/offRamp/OffRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {MultiOCR3Base} from "../ocr/MultiOCR3Base.sol";

import {IERC20} from "../../vendor/openzeppelin-solidity/v5.0.2/contracts/token/ERC20/IERC20.sol";
import {ERC165Checker} from "../../vendor/openzeppelin-solidity/v5.0.2/contracts/utils/introspection/ERC165Checker.sol";
import {EnumerableSet} from "../../vendor/openzeppelin-solidity/v5.0.2/contracts/utils/structs/EnumerableSet.sol";

/// @notice OffRamp enables OCR networks to execute multiple messages
/// in an OffRamp in a single transaction.
Expand All @@ -32,6 +33,7 @@ import {ERC165Checker} from "../../vendor/openzeppelin-solidity/v5.0.2/contracts
contract OffRamp is ITypeAndVersion, MultiOCR3Base {
using ERC165Checker for address;
using EnumerableMapAddresses for EnumerableMapAddresses.AddressToAddressMap;
using EnumerableSet for EnumerableSet.UintSet;

error ZeroChainSelectorNotAllowed();
error ExecutionError(bytes32 messageId, bytes err);
Expand Down Expand Up @@ -156,6 +158,9 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
// DYNAMIC CONFIG
DynamicConfig internal s_dynamicConfig;

/// @notice Set of source chain selectors
EnumerableSet.UintSet internal s_sourceChainSelectors;

/// @notice SourceChainConfig per chain
/// (forms lane configurations from sourceChainSelector => StaticConfig.chainSelector)
mapping(uint64 sourceChainSelector => SourceChainConfig sourceChainConfig) private s_sourceChainConfigs;
Expand Down Expand Up @@ -919,6 +924,18 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
return s_sourceChainConfigs[sourceChainSelector];
}

/// @notice Returns all source chain configs
/// @return sourceChainConfigs The source chain configs corresponding to all the supported chain selectors
function getAllSourceChainConfigs() external view returns (uint64[] memory, SourceChainConfig[] memory) {
SourceChainConfig[] memory sourceChainConfigs = new SourceChainConfig[](s_sourceChainSelectors.length());
uint64[] memory sourceChainSelectors = new uint64[](s_sourceChainSelectors.length());
for (uint256 i = 0; i < s_sourceChainSelectors.length(); ++i) {
sourceChainSelectors[i] = uint64(s_sourceChainSelectors.at(i));
sourceChainConfigs[i] = s_sourceChainConfigs[sourceChainSelectors[i]];
}
return (sourceChainSelectors, sourceChainConfigs);
}

/// @notice Updates source configs
/// @param sourceChainConfigUpdates Source chain configs
function applySourceChainConfigUpdates(SourceChainConfigArgs[] memory sourceChainConfigUpdates) external onlyOwner {
Expand Down Expand Up @@ -962,6 +979,9 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
currentConfig.isEnabled = sourceConfigUpdate.isEnabled;
currentConfig.router = sourceConfigUpdate.router;

// We don't need to check the return value, as inserting the item twice has no effect.
s_sourceChainSelectors.add(sourceChainSelector);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this returns a bool for "inserted" or "already exists". maybe add a comment explaining we don't care about the return value as adding it twice should not do anything

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


emit SourceChainConfigSet(sourceChainSelector, currentConfig);
}
}
Expand Down
7 changes: 7 additions & 0 deletions contracts/src/v0.8/ccip/test/helpers/OffRampHelper.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.24;

import {EnumerableSet} from "../../../vendor/openzeppelin-solidity/v5.0.2/contracts/utils/structs/EnumerableSet.sol";
import {Client} from "../../libraries/Client.sol";
import {Internal} from "../../libraries/Internal.sol";
import {OffRamp} from "../../offRamp/OffRamp.sol";
import {IgnoreContractSize} from "./IgnoreContractSize.sol";

contract OffRampHelper is OffRamp, IgnoreContractSize {
using EnumerableSet for EnumerableSet.UintSet;

mapping(uint64 sourceChainSelector => uint256 overrideTimestamp) private s_sourceChainVerificationOverride;

constructor(
Expand Down Expand Up @@ -104,4 +107,8 @@ contract OffRampHelper is OffRamp, IgnoreContractSize {
function setRootTimestamp(uint64 sourceChainSelector, bytes32 root, uint256 timestamp) external {
s_roots[sourceChainSelector][root] = timestamp;
}

function getSourceChainSelectors() external view returns (uint256[] memory chainSelectors) {
return s_sourceChainSelectors.values();
}
}
27 changes: 17 additions & 10 deletions contracts/src/v0.8/ccip/test/offRamp/OffRamp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ contract OffRamp_constructor is OffRampSetup {
onRamp: sourceChainConfigs[1].onRamp
});

uint64[] memory expectedSourceChainSelectors = new uint64[](2);
expectedSourceChainSelectors[0] = SOURCE_CHAIN_SELECTOR_1;
expectedSourceChainSelectors[1] = SOURCE_CHAIN_SELECTOR_1 + 1;

vm.expectEmit();
emit OffRamp.StaticConfigSet(staticConfig);

Expand Down Expand Up @@ -123,17 +127,21 @@ contract OffRamp_constructor is OffRampSetup {
MultiOCR3Base.OCRConfig memory gotOCRConfig = s_offRamp.latestConfigDetails(uint8(Internal.OCRPluginType.Execution));
_assertOCRConfigEquality(expectedOCRConfig, gotOCRConfig);

_assertSourceChainConfigEquality(
s_offRamp.getSourceChainConfig(SOURCE_CHAIN_SELECTOR_1), expectedSourceChainConfig1
);
_assertSourceChainConfigEquality(
s_offRamp.getSourceChainConfig(SOURCE_CHAIN_SELECTOR_1 + 1), expectedSourceChainConfig2
);
(uint64[] memory actualSourceChainSelectors, OffRamp.SourceChainConfig[] memory actualSourceChainConfigs) =
s_offRamp.getAllSourceChainConfigs();

_assertSourceChainConfigEquality(actualSourceChainConfigs[0], expectedSourceChainConfig1);
_assertSourceChainConfigEquality(actualSourceChainConfigs[1], expectedSourceChainConfig2);

// OffRamp initial values
assertEq("OffRamp 1.6.0-dev", s_offRamp.typeAndVersion());
assertEq(OWNER, s_offRamp.owner());
assertEq(0, s_offRamp.getLatestPriceSequenceNumber());

// assertion for source chain selector
for (uint256 i = 0; i < expectedSourceChainSelectors.length; i++) {
assertEq(expectedSourceChainSelectors[i], actualSourceChainSelectors[i]);
}
}

// Revert
Expand Down Expand Up @@ -3005,7 +3013,7 @@ contract OffRamp_applySourceChainConfigUpdates is OffRampSetup {
Vm.Log[] memory logEntries = vm.getRecordedLogs();
assertEq(logEntries.length, 0);

// assertEq(s_offRamp.getSourceChainSelectors().length, 0);
assertEq(s_offRamp.getSourceChainSelectors().length, 0);
}

function test_AddNewChain_Success() public {
Expand Down Expand Up @@ -3058,9 +3066,8 @@ contract OffRamp_applySourceChainConfigUpdates is OffRampSetup {

_assertSourceChainConfigEquality(s_offRamp.getSourceChainConfig(SOURCE_CHAIN_SELECTOR_1), expectedSourceChainConfig);

// uint64[] memory resultSourceChainSelectors = s_offRamp.getSourceChainSelectors();
// assertEq(resultSourceChainSelectors.length, 1);
// assertEq(resultSourceChainSelectors[0], SOURCE_CHAIN_SELECTOR_1);
uint256[] memory resultSourceChainSelectors = s_offRamp.getSourceChainSelectors();
assertEq(resultSourceChainSelectors.length, 1);
}

function test_AddMultipleChains_Success() public {
Expand Down
29 changes: 27 additions & 2 deletions core/gethwrappers/ccip/generated/offramp/offramp.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mock_v3_aggregator_contract: ../../../contracts/solc/v0.8.24/MockV3Aggregator/Mo
multi_aggregate_rate_limiter: ../../../contracts/solc/v0.8.24/MultiAggregateRateLimiter/MultiAggregateRateLimiter.abi ../../../contracts/solc/v0.8.24/MultiAggregateRateLimiter/MultiAggregateRateLimiter.bin 0b541232e49727e947dc164eadf35963c66e67576f21baa0ecaa06a8833148ed
multi_ocr3_helper: ../../../contracts/solc/v0.8.24/MultiOCR3Helper/MultiOCR3Helper.abi ../../../contracts/solc/v0.8.24/MultiOCR3Helper/MultiOCR3Helper.bin 04b6b261dd71925670bf4d904aaf7bf08543452009feefb88e07d4c49d12e969
nonce_manager: ../../../contracts/solc/v0.8.24/NonceManager/NonceManager.abi ../../../contracts/solc/v0.8.24/NonceManager/NonceManager.bin 6f64e1083b356c06ee66b9138e398b9c97a4cd3e8c9ec38cf3010cebc79af536
offramp: ../../../contracts/solc/v0.8.24/OffRamp/OffRamp.abi ../../../contracts/solc/v0.8.24/OffRamp/OffRamp.bin 8d788a8fe2ed337311672a1c832e211a191d3fa4327d9141bc8c0f47bb5e29b4
offramp: ../../../contracts/solc/v0.8.24/OffRamp/OffRamp.abi ../../../contracts/solc/v0.8.24/OffRamp/OffRamp.bin cff099545fa50fcfd411c16c9cac754a0ba71ef2590840c0732d42604224200f
onramp: ../../../contracts/solc/v0.8.24/OnRamp/OnRamp.abi ../../../contracts/solc/v0.8.24/OnRamp/OnRamp.bin cdf282d410d2dc38e47b360d00ab69a262ab240577071a49c2be49aceea5f5fa
ping_pong_demo: ../../../contracts/solc/v0.8.24/PingPongDemo/PingPongDemo.abi ../../../contracts/solc/v0.8.24/PingPongDemo/PingPongDemo.bin c1c2f8a65c7ffd971899cae7fe62f2da57d09e936151e2b92163c4bebe699d6b
price_registry: ../../../contracts/solc/v0.8.24/PriceRegistry/PriceRegistry.abi ../../../contracts/solc/v0.8.24/PriceRegistry/PriceRegistry.bin e7781d600c1bb7aa4620106af7f6e146a109b97f4cb6a7d06c9e15773340ecb2
Expand Down
Loading