Skip to content

Commit

Permalink
more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG committed Dec 17, 2024
1 parent 9b85a7b commit cb923b0
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 173 deletions.
20 changes: 0 additions & 20 deletions deployment/ccip/changeset/cs_deploy_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_home"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/maybe_revert_message_receiver"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/nonce_manager"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/onramp"
Expand Down Expand Up @@ -181,25 +180,6 @@ func deployChainContracts(
e.Logger.Errorw("RMNProxy not found", "chain", chain.String())
return fmt.Errorf("rmn proxy not found for chain %s, deploy the prerequisites first", chain.String())
}
if chainState.Receiver == nil {
_, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*maybe_revert_message_receiver.MaybeRevertMessageReceiver] {
receiverAddr, tx, receiver, err2 := maybe_revert_message_receiver.DeployMaybeRevertMessageReceiver(
chain.DeployerKey,
chain.Client,
false,
)
return deployment.ContractDeploy[*maybe_revert_message_receiver.MaybeRevertMessageReceiver]{
receiverAddr, receiver, tx, deployment.NewTypeAndVersion(CCIPReceiver, deployment.Version1_0_0), err2,
}
})
if err != nil {
e.Logger.Errorw("Failed to deploy receiver", "chain", chain.String(), "err", err)
return err
}
} else {
e.Logger.Infow("receiver already deployed", "addr", chainState.Receiver.Address, "chain", chain.String())
}
var rmnLegacyAddr common.Address
if chainState.MockRMN != nil {
rmnLegacyAddr = chainState.MockRMN.Address()
Expand Down
20 changes: 20 additions & 0 deletions deployment/ccip/changeset/cs_prerequisites.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"golang.org/x/sync/errgroup"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/maybe_revert_message_receiver"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/mock_rmn_contract"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/price_registry_1_2_0"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/registry_module_owner_custom"
Expand Down Expand Up @@ -384,6 +385,25 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address
"messenger", messenger.Address(),
)
}
if chainState.Receiver == nil {
_, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*maybe_revert_message_receiver.MaybeRevertMessageReceiver] {
receiverAddr, tx, receiver, err2 := maybe_revert_message_receiver.DeployMaybeRevertMessageReceiver(
chain.DeployerKey,
chain.Client,
false,
)
return deployment.ContractDeploy[*maybe_revert_message_receiver.MaybeRevertMessageReceiver]{
receiverAddr, receiver, tx, deployment.NewTypeAndVersion(CCIPReceiver, deployment.Version1_0_0), err2,
}
})
if err != nil {
e.Logger.Errorw("Failed to deploy receiver", "chain", chain.String(), "err", err)
return err
}
} else {
e.Logger.Infow("receiver already deployed", "addr", chainState.Receiver.Address, "chain", chain.String())
}
// Only applicable if setting up for 1.5 version, remove this once we have fully migrated to 1.6
if deployOpts.LegacyDeploymentCfg != nil {
if chainState.PriceRegistry == nil {
Expand Down
160 changes: 160 additions & 0 deletions deployment/ccip/changeset/v1_5/cs_jobspec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package v1_5

import (
"fmt"
"strconv"

chain_selectors "github.com/smartcontractkit/chain-selectors"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config"
integrationtesthelpers "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/testhelpers/integration"
)

type JobSpecsForLanesConfig struct {
Configs []JobSpecInput
}

func (c JobSpecsForLanesConfig) Validate() error {
for _, cfg := range c.Configs {
if err := cfg.Validate(); err != nil {
return fmt.Errorf("invalid JobSpecInput: %w", err)
}
}
return nil
}

type JobSpecInput struct {
SourceChainSelector uint64
DestinationChainSelector uint64
DestinationStartBlock uint64
TokenPricesUSDPipeline string
PriceGetterConfigJson string
USDCAttestationAPI string
USDCCfg *config.USDCConfig
}

func (j JobSpecInput) Validate() error {
if err := deployment.IsValidChainSelector(j.SourceChainSelector); err != nil {
return fmt.Errorf("SourceChainSelector is invalid: %w", err)
}
if err := deployment.IsValidChainSelector(j.DestinationChainSelector); err != nil {
return fmt.Errorf("DestinationChainSelector is invalid: %w", err)
}
if j.TokenPricesUSDPipeline == "" && j.PriceGetterConfigJson == "" {
return fmt.Errorf("TokenPricesUSDPipeline or PriceGetterConfigJson is required")
}
if j.USDCCfg != nil {
if err := j.USDCCfg.ValidateUSDCConfig(); err != nil {
return fmt.Errorf("USDCCfg is invalid: %w", err)
}
if j.USDCAttestationAPI == "" {
return fmt.Errorf("USDCAttestationAPI is required")
}
}
return nil
}

func JobSpecsForLanes(env deployment.Environment, c JobSpecsForLanesConfig) (deployment.ChangesetOutput, error) {
if err := c.Validate(); err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("invalid JobSpecsForLanesConfig: %w", err)
}
state, err := changeset.LoadOnchainState(env)
if err != nil {
return deployment.ChangesetOutput{}, err
}
nodesToJobSpecs, err := jobSpecsForLane(env, state, c)
if err != nil {
return deployment.ChangesetOutput{}, err
}
return deployment.ChangesetOutput{
JobSpecs: nodesToJobSpecs,
}, nil
}

func jobSpecsForLane(
env deployment.Environment,
state changeset.CCIPOnChainState,
lanesCfg JobSpecsForLanesConfig,
) (map[string][]string, error) {
nodes, err := deployment.NodeInfo(env.NodeIDs, env.Offchain)
if err != nil {
return nil, err
}
nodesToJobSpecs := make(map[string][]string)
for _, node := range nodes {
var specs []string
for _, cfg := range lanesCfg.Configs {
var err error
destChainState := state.Chains[cfg.DestinationChainSelector]
sourceChain := env.Chains[cfg.SourceChainSelector]
destChain := env.Chains[cfg.DestinationChainSelector]
destEVMChainIdStr, err := chain_selectors.GetChainIDFromSelector(cfg.DestinationChainSelector)
if err != nil {
return nil, fmt.Errorf("failed to get chain ID from selector for chain %s: %w", destChain.String(), err)
}
destEVMChainId, err := strconv.ParseUint(destEVMChainIdStr, 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to parse chain ID %s for chain %s: %w", destEVMChainIdStr, destChain.String(), err)
}
destChainDetails, err := chain_selectors.GetChainDetailsByChainIDAndFamily(destEVMChainIdStr, chain_selectors.FamilyEVM)
if err != nil {
return nil, fmt.Errorf("failed to get chain details for chain ID %s: %w", destEVMChainIdStr, err)
}
ccipJobParam := integrationtesthelpers.CCIPJobSpecParams{
OffRamp: destChainState.EVM2EVMOffRamp[cfg.SourceChainSelector].Address(),
CommitStore: destChainState.CommitStore[cfg.SourceChainSelector].Address(),
SourceChainName: sourceChain.Name(),
DestChainName: destChain.Name(),
DestEvmChainId: destEVMChainId,
TokenPricesUSDPipeline: cfg.TokenPricesUSDPipeline,
PriceGetterConfig: cfg.PriceGetterConfigJson,
DestStartBlock: cfg.DestinationStartBlock,
USDCAttestationAPI: cfg.USDCAttestationAPI,
USDCConfig: cfg.USDCCfg,
P2PV2Bootstrappers: nodes.BootstrapLocators(),
}
if !node.IsBootstrap {
ocrCfg := node.SelToOCRConfig[destChainDetails]
ocrKeyBundleID := ocrCfg.KeyBundleID
transmitterID := ocrCfg.TransmitAccount
commitSpec, err := ccipJobParam.CommitJobSpec()
if err != nil {
return nil, fmt.Errorf("failed to generate commit job spec for source %s and destination %s: %w",
sourceChain.String(), destChain.String(), err)
}
commitSpec.OCR2OracleSpec.OCRKeyBundleID.SetValid(ocrKeyBundleID)
commitSpec.OCR2OracleSpec.TransmitterID.SetValid(string(transmitterID))
commitSpecStr, err := commitSpec.String()
if err != nil {
return nil, fmt.Errorf("failed to convert commit job spec to string for source %s and destination %s: %w",
sourceChain.String(), destChain.String(), err)
}
execSpec, err := ccipJobParam.ExecutionJobSpec()
if err != nil {
return nil, fmt.Errorf("failed to generate execution job spec for source %s and destination %s: %w",
sourceChain.String(), destChain.String(), err)
}
execSpec.OCR2OracleSpec.OCRKeyBundleID.SetValid(ocrKeyBundleID)
execSpec.OCR2OracleSpec.TransmitterID.SetValid(string(transmitterID))
execSpecStr, err := execSpec.String()
if err != nil {
return nil, fmt.Errorf("failed to convert execution job spec to string for source %s and destination %s: %w",
sourceChain.String(), destChain.String(), err)
}
specs = append(specs, commitSpecStr, execSpecStr)
} else {
bootstrapSpec := ccipJobParam.BootstrapJob(destChainState.CommitStore[cfg.SourceChainSelector].Address().String())
bootstrapSpecStr, err := bootstrapSpec.String()
if err != nil {
return nil, fmt.Errorf("failed to convert bootstrap job spec to string for source %s and destination %s: %w",
sourceChain.String(), destChain.String(), err)
}
specs = append(specs, bootstrapSpecStr)
}
}
nodesToJobSpecs[node.NodeID] = append(nodesToJobSpecs[node.NodeID], specs...)
}
return nodesToJobSpecs, nil
}
Loading

0 comments on commit cb923b0

Please sign in to comment.