Skip to content

Commit

Permalink
[CCIP-2639] ccip capability launcher component (#1123)
Browse files Browse the repository at this point in the history
## Motivation

We need a component that consumes capability registry syncer updates and
launches CCIP oracles accordingly.

## Solution

Build a launcher component that implements the `registrysyncer.Launcher`
interface. The setup of the `launcher` package is as follows:

* bluegreen.go: defines structures that encapsulates ccip deployments,
i.e exec and commit oracles, and the blue/green deployment logic.
* diff.go: pure functions that diff registry states in order to
determine if there are any added, updated, or deleted dons that we
should care about.
* launcher.go: defines the `launcher` type which implements the
`registrysyncer.Launcher` interface. The `Launch` function is called by
the registry syncer whenever a new registry state is fetched. Note that
this registry state is not always different, we will most likely be
called with the same state more often than not, as the registry doesn't
change that often. It uses a handful of pure functions and applies state
updates only in a single function, `processDiff`.

On the contracts:
* Break out the types defined in `CCIPConfig.sol` into a separate
CCIPConfigTypes.sol which is then imported in CCIPConfig.sol and the OCR
config encoding interface, a helper used in tests.
* Use `Internal.OCRPluginType` instead of `PluginType` in order to be
consistent with the OCR3Base contracts that will be deployed on dests
  • Loading branch information
makramkd authored Jul 2, 2024
1 parent e319600 commit a6245df
Show file tree
Hide file tree
Showing 38 changed files with 4,620 additions and 4,931 deletions.
1 change: 1 addition & 0 deletions contracts/scripts/native_solc_compile_all_ccip
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ compileContract ccip/ARMProxy.sol
compileContract ccip/tokenAdminRegistry/TokenAdminRegistry.sol
compileContract ccip/tokenAdminRegistry/RegistryModuleOwnerCustom.sol
compileContract ccip/capability/CCIPConfig.sol
compileContract ccip/capability/interfaces/IOCR3ConfigEncoder.sol

# Test helpers
compileContract ccip/test/helpers/BurnMintERC677Helper.sol
Expand Down
170 changes: 68 additions & 102 deletions contracts/src/v0.8/ccip/capability/CCIPConfig.sol

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.24;

interface ICapabilitiesRegistry {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {CCIPConfigTypes} from "../libraries/CCIPConfigTypes.sol";

/// @dev This is so that we can generate gethwrappers and easily encode/decode OCR3Config
/// in the offchain integration tests.
interface IOCR3ConfigEncoder {
/// @dev Encodes an array of OCR3Config into a bytes array. For test usage only.
function exposeOCR3Config(CCIPConfigTypes.OCR3Config[] calldata config) external view returns (bytes memory);
}
56 changes: 56 additions & 0 deletions contracts/src/v0.8/ccip/capability/libraries/CCIPConfigTypes.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {Internal} from "../../libraries/Internal.sol";

library CCIPConfigTypes {
/// @notice ConfigState indicates the state of the configuration.
/// A DON's configuration always starts out in the "Init" state - this is the starting state.
/// The only valid transition from "Init" is to the "Running" state - this is the first ever configuration.
/// The only valid transition from "Running" is to the "Staging" state - this is a blue/green proposal.
/// The only valid transition from "Staging" is back to the "Running" state - this is a promotion.
/// TODO: explain rollbacks?
enum ConfigState {
Init,
Running,
Staging
}

/// @notice Chain configuration.
/// Changes to chain configuration are detected out-of-band in plugins and decoded offchain.
struct ChainConfig {
bytes32[] readers; // The P2P IDs of the readers for the chain. These IDs must be registered in the capabilities registry.
uint8 fChain; // The fault tolerance parameter of the chain.
bytes config; // The chain configuration. This is kept intentionally opaque so as to add fields in the future if needed.
}

/// @notice Chain configuration information struct used in applyChainConfigUpdates and getAllChainConfigs.
struct ChainConfigInfo {
uint64 chainSelector;
ChainConfig chainConfig;
}

/// @notice OCR3 configuration.
struct OCR3Config {
Internal.OCRPluginType pluginType; // ────────╮ The plugin that the configuration is for.
uint64 chainSelector; // | The (remote) chain that the configuration is for.
uint8 F; // | The "big F" parameter for the role DON.
uint64 offchainConfigVersion; // ─────────────╯ The version of the offchain configuration.
bytes offrampAddress; // The remote chain offramp address.
bytes32[] bootstrapP2PIds; // The bootstrap P2P IDs of the oracles that are part of the role DON.
// len(p2pIds) == len(signers) == len(transmitters) == 3 * F + 1
// NOTE: indexes matter here! The p2p ID at index i corresponds to the signer at index i and the transmitter at index i.
// This is crucial in order to build the oracle ID <-> peer ID mapping offchain.
bytes32[] p2pIds; // The P2P IDs of the oracles that are part of the role DON.
bytes[] signers; // The onchain signing keys of nodes in the don.
bytes[] transmitters; // The onchain transmitter keys of nodes in the don.
bytes offchainConfig; // The offchain configuration for the OCR3 protocol. Protobuf encoded.
}

/// @notice OCR3 configuration with metadata, specifically the config count and the config digest.
struct OCR3ConfigWithMeta {
OCR3Config config; // The OCR3 configuration.
uint64 configCount; // The config count used to compute the config digest.
bytes32 configDigest; // The config digest of the OCR3 configuration.
}
}
441 changes: 224 additions & 217 deletions contracts/src/v0.8/ccip/test/capability/CCIPConfig.t.sol

Large diffs are not rendered by default.

37 changes: 23 additions & 14 deletions contracts/src/v0.8/ccip/test/helpers/CCIPConfigHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,65 @@
pragma solidity ^0.8.24;

import {CCIPConfig} from "../../capability/CCIPConfig.sol";
import {CCIPConfigTypes} from "../../capability/libraries/CCIPConfigTypes.sol";
import {Internal} from "../../libraries/Internal.sol";

contract CCIPConfigHelper is CCIPConfig {
constructor(address capabilitiesRegistry) CCIPConfig(capabilitiesRegistry) {}

function stateFromConfigLength(uint256 configLength) public pure returns (ConfigState) {
function stateFromConfigLength(uint256 configLength) public pure returns (CCIPConfigTypes.ConfigState) {
return _stateFromConfigLength(configLength);
}

function validateConfigStateTransition(ConfigState currentState, ConfigState newState) public pure {
function validateConfigStateTransition(
CCIPConfigTypes.ConfigState currentState,
CCIPConfigTypes.ConfigState newState
) public pure {
_validateConfigStateTransition(currentState, newState);
}

function validateConfigTransition(
OCR3ConfigWithMeta[] memory currentConfig,
OCR3ConfigWithMeta[] memory newConfigWithMeta
CCIPConfigTypes.OCR3ConfigWithMeta[] memory currentConfig,
CCIPConfigTypes.OCR3ConfigWithMeta[] memory newConfigWithMeta
) public pure {
_validateConfigTransition(currentConfig, newConfigWithMeta);
}

function computeNewConfigWithMeta(
uint32 donId,
OCR3ConfigWithMeta[] memory currentConfig,
OCR3Config[] memory newConfig,
ConfigState currentState,
ConfigState newState
) public view returns (OCR3ConfigWithMeta[] memory) {
CCIPConfigTypes.OCR3ConfigWithMeta[] memory currentConfig,
CCIPConfigTypes.OCR3Config[] memory newConfig,
CCIPConfigTypes.ConfigState currentState,
CCIPConfigTypes.ConfigState newState
) public view returns (CCIPConfigTypes.OCR3ConfigWithMeta[] memory) {
return _computeNewConfigWithMeta(donId, currentConfig, newConfig, currentState, newState);
}

function groupByPluginType(OCR3Config[] memory ocr3Configs)
function groupByPluginType(CCIPConfigTypes.OCR3Config[] memory ocr3Configs)
public
pure
returns (OCR3Config[] memory commitConfigs, OCR3Config[] memory execConfigs)
returns (CCIPConfigTypes.OCR3Config[] memory commitConfigs, CCIPConfigTypes.OCR3Config[] memory execConfigs)
{
return _groupByPluginType(ocr3Configs);
}

function computeConfigDigest(
uint32 donId,
uint64 configCount,
OCR3Config memory ocr3Config
CCIPConfigTypes.OCR3Config memory ocr3Config
) public pure returns (bytes32) {
return _computeConfigDigest(donId, configCount, ocr3Config);
}

function validateConfig(OCR3Config memory cfg) public view {
function validateConfig(CCIPConfigTypes.OCR3Config memory cfg) public view {
_validateConfig(cfg);
}

function updatePluginConfig(uint32 donId, PluginType pluginType, OCR3Config[] memory newConfig) public {
function updatePluginConfig(
uint32 donId,
Internal.OCRPluginType pluginType,
CCIPConfigTypes.OCR3Config[] memory newConfig
) public {
_updatePluginConfig(donId, pluginType, newConfig);
}
}
2 changes: 1 addition & 1 deletion core/capabilities/remote/types/messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 24 additions & 24 deletions core/gethwrappers/ccip/generated/ccip_config/ccip_config.go

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ burn_from_mint_token_pool: ../../../contracts/solc/v0.8.24/BurnFromMintTokenPool
burn_mint_token_pool: ../../../contracts/solc/v0.8.24/BurnMintTokenPool/BurnMintTokenPool.abi ../../../contracts/solc/v0.8.24/BurnMintTokenPool/BurnMintTokenPool.bin fee3f82935ce7a26c65e12f19a472a4fccdae62755abdb42d8b0a01f0f06981a
burn_mint_token_pool_and_proxy: ../../../contracts/solc/v0.8.24/BurnMintTokenPoolAndProxy/BurnMintTokenPoolAndProxy.abi ../../../contracts/solc/v0.8.24/BurnMintTokenPoolAndProxy/BurnMintTokenPoolAndProxy.bin c7efa00d2be62a97a814730c8e13aa70794ebfdd38a9f3b3c11554a5dfd70478
burn_with_from_mint_token_pool: ../../../contracts/solc/v0.8.24/BurnWithFromMintTokenPool/BurnWithFromMintTokenPool.abi ../../../contracts/solc/v0.8.24/BurnWithFromMintTokenPool/BurnWithFromMintTokenPool.bin a0728e186af74968101135a58a483320ced9ab79b22b1b24ac6994254ee79097
ccip_config: ../../../contracts/solc/v0.8.24/CCIPConfig/CCIPConfig.abi ../../../contracts/solc/v0.8.24/CCIPConfig/CCIPConfig.bin ef9e1f61b288bc31dda1c4e9d0bb8885b7b0bf1fe35bf74af8b12568e7532010
ccip_config: ../../../contracts/solc/v0.8.24/CCIPConfig/CCIPConfig.abi ../../../contracts/solc/v0.8.24/CCIPConfig/CCIPConfig.bin c44460757ca0e1b228734b32b9ab03221b93d77bb9f8e2970830779a8be2cb78
commit_store: ../../../contracts/solc/v0.8.24/CommitStore/CommitStore.abi ../../../contracts/solc/v0.8.24/CommitStore/CommitStore.bin ddc26c10c2a52b59624faae9005827b09b98db4566887a736005e8cc37cf8a51
commit_store_helper: ../../../contracts/solc/v0.8.24/CommitStoreHelper/CommitStoreHelper.abi ../../../contracts/solc/v0.8.24/CommitStoreHelper/CommitStoreHelper.bin ebd8aac686fa28a71d4212bcd25a28f8f640d50dce5e50498b2f6b8534890b69
ether_sender_receiver: ../../../contracts/solc/v0.8.24/EtherSenderReceiver/EtherSenderReceiver.abi ../../../contracts/solc/v0.8.24/EtherSenderReceiver/EtherSenderReceiver.bin 09510a3f773f108a3c231e8d202835c845ded862d071ec54c4f89c12d868b8de
Expand All @@ -23,6 +23,7 @@ mock_usdc_token_transmitter: ../../../contracts/solc/v0.8.24/MockE2EUSDCTransmit
mock_v3_aggregator_contract: ../../../contracts/solc/v0.8.24/MockV3Aggregator/MockV3Aggregator.abi ../../../contracts/solc/v0.8.24/MockV3Aggregator/MockV3Aggregator.bin 518e19efa2ff52b0fefd8e597b05765317ee7638189bfe34ca43de2f6599faf4
multi_aggregate_rate_limiter: ../../../contracts/solc/v0.8.24/MultiAggregateRateLimiter/MultiAggregateRateLimiter.abi ../../../contracts/solc/v0.8.24/MultiAggregateRateLimiter/MultiAggregateRateLimiter.bin abb0ecb1ed8621f26e43b39f5fa25f3d0b6d6c184fa37c404c4389605ecb74e7
nonce_manager: ../../../contracts/solc/v0.8.24/NonceManager/NonceManager.abi ../../../contracts/solc/v0.8.24/NonceManager/NonceManager.bin cdc11c1ab4c1c3fd77f30215e9c579404a6e60eb9adc213d73ca0773c3bb5784
ocr3_config_encoder: ../../../contracts/solc/v0.8.24/IOCR3ConfigEncoder/IOCR3ConfigEncoder.abi ../../../contracts/solc/v0.8.24/IOCR3ConfigEncoder/IOCR3ConfigEncoder.bin e21180898e1ad54a045ee20add85a2793c681425ea06f66d1a9e5cab128b6487
ping_pong_demo: ../../../contracts/solc/v0.8.24/PingPongDemo/PingPongDemo.abi ../../../contracts/solc/v0.8.24/PingPongDemo/PingPongDemo.bin 1588313bb5e781d181a825247d30828f59007700f36b4b9b00391592b06ff4b4
price_registry: ../../../contracts/solc/v0.8.24/PriceRegistry/PriceRegistry.abi ../../../contracts/solc/v0.8.24/PriceRegistry/PriceRegistry.bin 0b3e253684d7085aa11f9179b71453b9db9d11cabea41605d5b4ac4128f85bfb
registry_module_owner_custom: ../../../contracts/solc/v0.8.24/RegistryModuleOwnerCustom/RegistryModuleOwnerCustom.abi ../../../contracts/solc/v0.8.24/RegistryModuleOwnerCustom/RegistryModuleOwnerCustom.bin cbe7698bfd811b485ac3856daf073a7bdebeefdf2583403ca4a19d5b7e2d4ae8
Expand Down
1 change: 1 addition & 0 deletions core/gethwrappers/ccip/go_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ package ccip
//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.24/Router/Router.abi ../../../contracts/solc/v0.8.24/Router/Router.bin Router router
//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.24/PriceRegistry/PriceRegistry.abi ../../../contracts/solc/v0.8.24/PriceRegistry/PriceRegistry.bin PriceRegistry price_registry
//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.24/CCIPConfig/CCIPConfig.abi ../../../contracts/solc/v0.8.24/CCIPConfig/CCIPConfig.bin CCIPConfig ccip_config
//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.24/IOCR3ConfigEncoder/IOCR3ConfigEncoder.abi ../../../contracts/solc/v0.8.24/IOCR3ConfigEncoder/IOCR3ConfigEncoder.bin IOCR3ConfigEncoder ocr3_config_encoder

//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.24/MaybeRevertMessageReceiver/MaybeRevertMessageReceiver.abi ../../../contracts/solc/v0.8.24/MaybeRevertMessageReceiver/MaybeRevertMessageReceiver.bin MaybeRevertMessageReceiver maybe_revert_message_receiver
//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.24/PingPongDemo/PingPongDemo.abi ../../../contracts/solc/v0.8.24/PingPongDemo/PingPongDemo.bin PingPongDemo ping_pong_demo
Expand Down
Loading

0 comments on commit a6245df

Please sign in to comment.