From 789d02195d5f20a7e198402860916182cbfc598f Mon Sep 17 00:00:00 2001 From: Connor Stein Date: Wed, 20 Nov 2024 13:58:33 -0500 Subject: [PATCH] Add ccip/changeset/internal (#15334) * Move files * Move more files * Move the rest * Move some files to internal * Get building * Move a bunch of home chain stuff to internal * Update README * Fix integration tests * More merge conflicts * More merge conflicts --- deployment/README.md | 8 +- deployment/ccip/changeset/active_candidate.go | 19 +- .../active_candidate_helpers.go} | 19 +- .../ccip/changeset/active_candidate_test.go | 51 +- deployment/ccip/changeset/add_chain.go | 23 +- deployment/ccip/changeset/add_chain_test.go | 54 +- deployment/ccip/{ => changeset}/add_lane.go | 2 +- .../ccip/{ => changeset}/add_lane_test.go | 3 +- deployment/ccip/{ => changeset}/consts.go | 2 +- deployment/ccip/{ => changeset}/deploy.go | 15 +- deployment/ccip/changeset/deploy_chain.go | 3 +- .../ccip/changeset/deploy_chain_test.go | 9 +- .../ccip/{ => changeset}/deploy_home_chain.go | 550 +----------------- .../ccip/{ => changeset}/deploy_test.go | 2 +- deployment/ccip/changeset/home_chain.go | 3 +- deployment/ccip/changeset/home_chain_test.go | 9 +- deployment/ccip/changeset/initial_deploy.go | 10 +- .../ccip/changeset/initial_deploy_test.go | 37 +- .../changeset/internal/deploy_home_chain.go | 536 +++++++++++++++++ deployment/ccip/{ => changeset}/jobs.go | 11 +- deployment/ccip/changeset/jobspec.go | 3 +- deployment/ccip/{ => changeset}/ownership.go | 2 +- deployment/ccip/changeset/prerequisites.go | 7 +- .../ccip/changeset/prerequisites_test.go | 3 +- deployment/ccip/{ => changeset}/propose.go | 2 +- .../ccip/changeset/save_existing_test.go | 13 +- deployment/ccip/{ => changeset}/state.go | 3 +- .../ccip/{ => changeset}/test_assertions.go | 2 +- .../ccip/{ => changeset}/test_helpers.go | 16 +- .../ccip/{ => changeset}/test_params.go | 2 +- .../ccip/{ => changeset}/test_usdc_helpers.go | 6 +- deployment/ccip/{ => changeset}/token_info.go | 3 +- deployment/ccip/changeset/view.go | 3 +- .../ccip-tests/testsetups/test_helpers.go | 54 +- .../smoke/ccip_messaging_test.go | 46 +- integration-tests/smoke/ccip_rmn_test.go | 18 +- integration-tests/smoke/ccip_test.go | 40 +- integration-tests/smoke/ccip_usdc_test.go | 28 +- integration-tests/smoke/fee_boosting_test.go | 34 +- 39 files changed, 825 insertions(+), 826 deletions(-) rename deployment/ccip/{active_candidate.go => changeset/active_candidate_helpers.go} (90%) rename deployment/ccip/{ => changeset}/add_lane.go (99%) rename deployment/ccip/{ => changeset}/add_lane_test.go (99%) rename deployment/ccip/{ => changeset}/consts.go (89%) rename deployment/ccip/{ => changeset}/deploy.go (98%) rename deployment/ccip/{ => changeset}/deploy_home_chain.go (51%) rename deployment/ccip/{ => changeset}/deploy_test.go (96%) create mode 100644 deployment/ccip/changeset/internal/deploy_home_chain.go rename deployment/ccip/{ => changeset}/jobs.go (85%) rename deployment/ccip/{ => changeset}/ownership.go (98%) rename deployment/ccip/{ => changeset}/propose.go (99%) rename deployment/ccip/{ => changeset}/state.go (99%) rename deployment/ccip/{ => changeset}/test_assertions.go (99%) rename deployment/ccip/{ => changeset}/test_helpers.go (98%) rename deployment/ccip/{ => changeset}/test_params.go (97%) rename deployment/ccip/{ => changeset}/test_usdc_helpers.go (99%) rename deployment/ccip/{ => changeset}/token_info.go (99%) diff --git a/deployment/README.md b/deployment/README.md index 723397edc1c..c6579ca6205 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -100,10 +100,12 @@ TODO: Add various examples in deployment/example. contracts (like MCMS, LinkToken etc) which can be shared by products. -/deployment/ -- package name `deployment` +/deployment//internal - Internal building blocks for changesets -- TODO: can we make this `internal`? + +/deployment//view +- Hold readonly mappings Go bindings to json marshallable objects. +- Used to generate a view of the system. /deployment//changeset - Think of this as the public API for deployment and configuration diff --git a/deployment/ccip/changeset/active_candidate.go b/deployment/ccip/changeset/active_candidate.go index 9f46b8d20f1..a336cf69536 100644 --- a/deployment/ccip/changeset/active_candidate.go +++ b/deployment/ccip/changeset/active_candidate.go @@ -2,22 +2,23 @@ package changeset import ( "fmt" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms" "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" "github.com/smartcontractkit/chainlink/deployment" - ccdeploy "github.com/smartcontractkit/chainlink/deployment/ccip" + "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" ) // PromoteAllCandidatesChangeset generates a proposal to call promoteCandidate on the CCIPHome through CapReg. // This needs to be called after SetCandidateProposal is executed. func PromoteAllCandidatesChangeset( - state ccdeploy.CCIPOnChainState, + state CCIPOnChainState, homeChainSel, newChainSel uint64, nodes deployment.Nodes, ) (deployment.ChangesetOutput, error) { - promoteCandidateOps, err := ccdeploy.PromoteAllCandidatesForChainOps( + promoteCandidateOps, err := PromoteAllCandidatesForChainOps( state.Chains[homeChainSel].CapabilityRegistry, state.Chains[homeChainSel].CCIPHome, newChainSel, @@ -27,7 +28,7 @@ func PromoteAllCandidatesChangeset( return deployment.ChangesetOutput{}, err } - prop, err := ccdeploy.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ + prop, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ ChainIdentifier: mcms.ChainIdentifier(homeChainSel), Batch: promoteCandidateOps, }}, "promoteCandidate for commit and execution", 0) @@ -43,15 +44,15 @@ func PromoteAllCandidatesChangeset( // SetCandidateExecPluginProposal calls setCandidate on the CCIPHome for setting up OCR3 exec Plugin config for the new chain. func SetCandidatePluginChangeset( - state ccdeploy.CCIPOnChainState, + state CCIPOnChainState, e deployment.Environment, nodes deployment.Nodes, ocrSecrets deployment.OCRSecrets, homeChainSel, feedChainSel, newChainSel uint64, - tokenConfig ccdeploy.TokenConfig, + tokenConfig TokenConfig, pluginType cctypes.PluginType, ) (deployment.ChangesetOutput, error) { - newDONArgs, err := ccdeploy.BuildOCR3ConfigForCCIPHome( + newDONArgs, err := internal.BuildOCR3ConfigForCCIPHome( ocrSecrets, state.Chains[newChainSel].OffRamp, e.Chains[newChainSel], @@ -70,7 +71,7 @@ func SetCandidatePluginChangeset( return deployment.ChangesetOutput{}, fmt.Errorf("missing exec plugin in ocr3Configs") } - setCandidateMCMSOps, err := ccdeploy.SetCandidateOnExistingDon( + setCandidateMCMSOps, err := SetCandidateOnExistingDon( execConfig, state.Chains[homeChainSel].CapabilityRegistry, state.Chains[homeChainSel].CCIPHome, @@ -81,7 +82,7 @@ func SetCandidatePluginChangeset( return deployment.ChangesetOutput{}, err } - prop, err := ccdeploy.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ + prop, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ ChainIdentifier: mcms.ChainIdentifier(homeChainSel), Batch: setCandidateMCMSOps, }}, "SetCandidate for execution", 0) diff --git a/deployment/ccip/active_candidate.go b/deployment/ccip/changeset/active_candidate_helpers.go similarity index 90% rename from deployment/ccip/active_candidate.go rename to deployment/ccip/changeset/active_candidate_helpers.go index c65dac04103..aea488c36b2 100644 --- a/deployment/ccip/active_candidate.go +++ b/deployment/ccip/changeset/active_candidate_helpers.go @@ -1,13 +1,16 @@ -package ccipdeployment +package changeset import ( "fmt" + "math/big" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms" + "github.com/smartcontractkit/chainlink/deployment" + "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_home" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" - "math/big" ) // SetCandidateExecPluginOps calls setCandidate on CCIPHome contract through the UpdateDON call on CapReg contract @@ -20,12 +23,12 @@ func SetCandidateOnExistingDon( nodes deployment.Nodes, ) ([]mcms.Operation, error) { // fetch DON ID for the chain - donID, err := DonIDForChain(capReg, ccipHome, chainSelector) + donID, err := internal.DonIDForChain(capReg, ccipHome, chainSelector) if err != nil { return nil, fmt.Errorf("fetch don id for chain: %w", err) } fmt.Printf("donID: %d", donID) - encodedSetCandidateCall, err := CCIPHomeABI.Pack( + encodedSetCandidateCall, err := internal.CCIPHomeABI.Pack( "setCandidate", donID, pluginConfig.PluginType, @@ -43,7 +46,7 @@ func SetCandidateOnExistingDon( nodes.PeerIDs(), []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ { - CapabilityId: CCIPCapabilityID, + CapabilityId: internal.CCIPCapabilityID, Config: encodedSetCandidateCall, }, }, @@ -75,7 +78,7 @@ func PromoteCandidateOp(donID uint32, pluginType uint8, capReg *capabilities_reg } fmt.Printf("commit candidate digest after setCandidate: %x\n", allConfigs.CandidateConfig.ConfigDigest) - encodedPromotionCall, err := CCIPHomeABI.Pack( + encodedPromotionCall, err := internal.CCIPHomeABI.Pack( "promoteCandidateAndRevokeActive", donID, pluginType, @@ -92,7 +95,7 @@ func PromoteCandidateOp(donID uint32, pluginType uint8, capReg *capabilities_reg nodes.PeerIDs(), []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ { - CapabilityId: CCIPCapabilityID, + CapabilityId: internal.CCIPCapabilityID, Config: encodedPromotionCall, }, }, @@ -117,7 +120,7 @@ func PromoteAllCandidatesForChainOps( nodes deployment.Nodes, ) ([]mcms.Operation, error) { // fetch DON ID for the chain - donID, err := DonIDForChain(capReg, ccipHome, chainSelector) + donID, err := internal.DonIDForChain(capReg, ccipHome, chainSelector) if err != nil { return nil, fmt.Errorf("fetch don id for chain: %w", err) } diff --git a/deployment/ccip/changeset/active_candidate_test.go b/deployment/ccip/changeset/active_candidate_test.go index b6a4d331e9e..7e0b90fecbe 100644 --- a/deployment/ccip/changeset/active_candidate_test.go +++ b/deployment/ccip/changeset/active_candidate_test.go @@ -8,7 +8,7 @@ import ( "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" - + "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" @@ -16,7 +16,6 @@ import ( "github.com/stretchr/testify/require" - ccdeploy "github.com/smartcontractkit/chainlink/deployment/ccip" commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" "github.com/smartcontractkit/chainlink/v2/core/logger" @@ -26,17 +25,17 @@ func TestActiveCandidate(t *testing.T) { t.Skipf("to be enabled after latest cl-ccip is compatible") lggr := logger.TestLogger(t) - tenv := ccdeploy.NewMemoryEnvironmentWithJobsAndContracts(t, lggr, 3, 5) + tenv := NewMemoryEnvironmentWithJobsAndContracts(t, lggr, 3, 5) e := tenv.Env - state, err := ccdeploy.LoadOnchainState(tenv.Env) + state, err := LoadOnchainState(tenv.Env) require.NoError(t, err) // Add all lanes - require.NoError(t, ccdeploy.AddLanesForAll(e, state)) + require.NoError(t, AddLanesForAll(e, state)) // Need to keep track of the block number for each chain so that event subscription can be done from that block. startBlocks := make(map[uint64]*uint64) // Send a message from each chain to every other chain. - expectedSeqNum := make(map[ccdeploy.SourceDestPair]uint64) + expectedSeqNum := make(map[SourceDestPair]uint64) for src := range e.Chains { for dest, destChain := range e.Chains { if src == dest { @@ -46,14 +45,14 @@ func TestActiveCandidate(t *testing.T) { require.NoError(t, err) block := latesthdr.Number.Uint64() startBlocks[dest] = &block - msgSentEvent := ccdeploy.TestSendRequest(t, e, state, src, dest, false, router.ClientEVM2AnyMessage{ + msgSentEvent := TestSendRequest(t, e, state, src, dest, false, router.ClientEVM2AnyMessage{ Receiver: common.LeftPadBytes(state.Chains[dest].Receiver.Address().Bytes(), 32), Data: []byte("hello world"), TokenAmounts: nil, FeeToken: common.HexToAddress("0x0"), ExtraArgs: nil, }) - expectedSeqNum[ccdeploy.SourceDestPair{ + expectedSeqNum[SourceDestPair{ SourceChainSelector: src, DestChainSelector: dest, }] = msgSentEvent.SequenceNumber @@ -61,7 +60,7 @@ func TestActiveCandidate(t *testing.T) { } // Wait for all commit reports to land. - ccdeploy.ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks) + ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks) //After commit is reported on all chains, token prices should be updated in FeeQuoter. for dest := range e.Chains { @@ -69,15 +68,15 @@ func TestActiveCandidate(t *testing.T) { feeQuoter := state.Chains[dest].FeeQuoter timestampedPrice, err := feeQuoter.GetTokenPrice(nil, linkAddress) require.NoError(t, err) - require.Equal(t, ccdeploy.MockLinkPrice, timestampedPrice.Value) + require.Equal(t, MockLinkPrice, timestampedPrice.Value) } //Wait for all exec reports to land - ccdeploy.ConfirmExecWithSeqNrForAll(t, e, state, expectedSeqNum, startBlocks) + ConfirmExecWithSeqNrForAll(t, e, state, expectedSeqNum, startBlocks) // transfer ownership - ccdeploy.TransferAllOwnership(t, state, tenv.HomeChainSel, e) - acceptOwnershipProposal, err := ccdeploy.GenerateAcceptOwnershipProposal(state, tenv.HomeChainSel, e.AllChainSelectors()) + TransferAllOwnership(t, state, tenv.HomeChainSel, e) + acceptOwnershipProposal, err := GenerateAcceptOwnershipProposal(state, tenv.HomeChainSel, e.AllChainSelectors()) require.NoError(t, err) acceptOwnershipExec := commonchangeset.SignProposal(t, e, acceptOwnershipProposal) for _, sel := range e.AllChainSelectors() { @@ -85,19 +84,19 @@ func TestActiveCandidate(t *testing.T) { } // Apply the accept ownership proposal to all the chains. - err = ccdeploy.ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 2) + err = ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 2) require.NoError(t, err) // [ACTIVE, CANDIDATE] setup by setting candidate through cap reg capReg, ccipHome := state.Chains[tenv.HomeChainSel].CapabilityRegistry, state.Chains[tenv.HomeChainSel].CCIPHome - donID, err := ccdeploy.DonIDForChain(capReg, ccipHome, tenv.FeedChainSel) + donID, err := internal.DonIDForChain(capReg, ccipHome, tenv.FeedChainSel) require.NoError(t, err) donInfo, err := state.Chains[tenv.HomeChainSel].CapabilityRegistry.GetDON(nil, donID) require.NoError(t, err) require.Equal(t, 5, len(donInfo.NodeP2PIds)) require.Equal(t, uint32(4), donInfo.ConfigCount) - state, err = ccdeploy.LoadOnchainState(e) + state, err = LoadOnchainState(e) require.NoError(t, err) // delete a non-bootstrap node @@ -117,8 +116,8 @@ func TestActiveCandidate(t *testing.T) { // this will construct ocr3 configurations for the // commit and exec plugin we will be using rmnHomeAddress := state.Chains[tenv.HomeChainSel].RMNHome.Address() - tokenConfig := ccdeploy.NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds) - ocr3ConfigMap, err := ccdeploy.BuildOCR3ConfigForCCIPHome( + tokenConfig := NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds) + ocr3ConfigMap, err := internal.BuildOCR3ConfigForCCIPHome( deployment.XXXGenerateTestOCRSecrets(), state.Chains[tenv.FeedChainSel].OffRamp, e.Chains[tenv.FeedChainSel], @@ -130,7 +129,7 @@ func TestActiveCandidate(t *testing.T) { ) require.NoError(t, err) - setCommitCandidateOp, err := ccdeploy.SetCandidateOnExistingDon( + setCommitCandidateOp, err := SetCandidateOnExistingDon( ocr3ConfigMap[cctypes.PluginTypeCCIPCommit], state.Chains[tenv.HomeChainSel].CapabilityRegistry, state.Chains[tenv.HomeChainSel].CCIPHome, @@ -138,7 +137,7 @@ func TestActiveCandidate(t *testing.T) { nodes.NonBootstraps(), ) require.NoError(t, err) - setCommitCandidateProposal, err := ccdeploy.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ + setCommitCandidateProposal, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel), Batch: setCommitCandidateOp, }}, "set new candidates on commit plugin", 0) @@ -147,7 +146,7 @@ func TestActiveCandidate(t *testing.T) { commonchangeset.ExecuteProposal(t, e, setCommitCandidateSigned, state.Chains[tenv.HomeChainSel].Timelock, tenv.HomeChainSel) // create the op for the commit plugin as well - setExecCandidateOp, err := ccdeploy.SetCandidateOnExistingDon( + setExecCandidateOp, err := SetCandidateOnExistingDon( ocr3ConfigMap[cctypes.PluginTypeCCIPExec], state.Chains[tenv.HomeChainSel].CapabilityRegistry, state.Chains[tenv.HomeChainSel].CCIPHome, @@ -156,7 +155,7 @@ func TestActiveCandidate(t *testing.T) { ) require.NoError(t, err) - setExecCandidateProposal, err := ccdeploy.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ + setExecCandidateProposal, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel), Batch: setExecCandidateOp, }}, "set new candidates on commit and exec plugins", 0) @@ -172,7 +171,7 @@ func TestActiveCandidate(t *testing.T) { // [ACTIVE, CANDIDATE] done setup // [ACTIVE, CANDIDATE] make sure we can still send successful transaction without updating job specs - err = ccdeploy.ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 3) + err = ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 3) require.NoError(t, err) // [ACTIVE, CANDIDATE] done send successful transaction on active @@ -181,9 +180,9 @@ func TestActiveCandidate(t *testing.T) { oldCandidateDigest, err := state.Chains[tenv.HomeChainSel].CCIPHome.GetCandidateDigest(nil, donID, uint8(cctypes.PluginTypeCCIPExec)) require.NoError(t, err) - promoteOps, err := ccdeploy.PromoteAllCandidatesForChainOps(state.Chains[tenv.HomeChainSel].CapabilityRegistry, state.Chains[tenv.HomeChainSel].CCIPHome, tenv.FeedChainSel, nodes.NonBootstraps()) + promoteOps, err := PromoteAllCandidatesForChainOps(state.Chains[tenv.HomeChainSel].CapabilityRegistry, state.Chains[tenv.HomeChainSel].CCIPHome, tenv.FeedChainSel, nodes.NonBootstraps()) require.NoError(t, err) - promoteProposal, err := ccdeploy.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ + promoteProposal, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel), Batch: promoteOps, }}, "promote candidates and revoke actives", 0) @@ -207,7 +206,7 @@ func TestActiveCandidate(t *testing.T) { require.NoError(t, err) require.Equal(t, uint32(8), donInfo.ConfigCount) - err = ccdeploy.ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 4) + err = ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 4) require.NoError(t, err) // [NEW ACTIVE, NO CANDIDATE] done sending successful request } diff --git a/deployment/ccip/changeset/add_chain.go b/deployment/ccip/changeset/add_chain.go index 3ce6d17d24e..cb7d0701973 100644 --- a/deployment/ccip/changeset/add_chain.go +++ b/deployment/ccip/changeset/add_chain.go @@ -4,8 +4,7 @@ import ( "fmt" "math/big" - ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" - + "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms" @@ -20,7 +19,7 @@ import ( // to connect the new chain to the existing chains. func NewChainInboundChangeset( e deployment.Environment, - state ccipdeployment.CCIPOnChainState, + state CCIPOnChainState, homeChainSel uint64, newChainSel uint64, sources []uint64, @@ -42,7 +41,7 @@ func NewChainInboundChangeset( []fee_quoter.FeeQuoterDestChainConfigArgs{ { DestChainSelector: newChainSel, - DestChainConfig: ccipdeployment.DefaultFeeQuoterDestChainConfig(), + DestChainConfig: DefaultFeeQuoterDestChainConfig(), }, }) if err != nil { @@ -66,7 +65,7 @@ func NewChainInboundChangeset( }) } - addChainOp, err := ccipdeployment.ApplyChainConfigUpdatesOp(e, state, homeChainSel, []uint64{newChainSel}) + addChainOp, err := ApplyChainConfigUpdatesOp(e, state, homeChainSel, []uint64{newChainSel}) if err != nil { return deployment.ChangesetOutput{}, err } @@ -78,7 +77,7 @@ func NewChainInboundChangeset( }, }) - prop, err := ccipdeployment.BuildProposalFromBatches(state, batches, "proposal to set new chains", 0) + prop, err := BuildProposalFromBatches(state, batches, "proposal to set new chains", 0) if err != nil { return deployment.ChangesetOutput{}, err } @@ -91,15 +90,15 @@ func NewChainInboundChangeset( // AddDonAndSetCandidateChangeset adds new DON for destination to home chain // and sets the commit plugin config as candidateConfig for the don. func AddDonAndSetCandidateChangeset( - state ccipdeployment.CCIPOnChainState, + state CCIPOnChainState, e deployment.Environment, nodes deployment.Nodes, ocrSecrets deployment.OCRSecrets, homeChainSel, feedChainSel, newChainSel uint64, - tokenConfig ccipdeployment.TokenConfig, + tokenConfig TokenConfig, pluginType types.PluginType, ) (deployment.ChangesetOutput, error) { - newDONArgs, err := ccipdeployment.BuildOCR3ConfigForCCIPHome( + newDONArgs, err := internal.BuildOCR3ConfigForCCIPHome( ocrSecrets, state.Chains[newChainSel].OffRamp, e.Chains[newChainSel], @@ -112,7 +111,7 @@ func AddDonAndSetCandidateChangeset( if err != nil { return deployment.ChangesetOutput{}, err } - latestDon, err := ccipdeployment.LatestCCIPDON(state.Chains[homeChainSel].CapabilityRegistry) + latestDon, err := internal.LatestCCIPDON(state.Chains[homeChainSel].CapabilityRegistry) if err != nil { return deployment.ChangesetOutput{}, err } @@ -121,7 +120,7 @@ func AddDonAndSetCandidateChangeset( return deployment.ChangesetOutput{}, fmt.Errorf("missing commit plugin in ocr3Configs") } donID := latestDon.Id + 1 - addDonOp, err := ccipdeployment.NewDonWithCandidateOp( + addDonOp, err := NewDonWithCandidateOp( donID, commitConfig, state.Chains[homeChainSel].CapabilityRegistry, nodes.NonBootstraps(), @@ -130,7 +129,7 @@ func AddDonAndSetCandidateChangeset( return deployment.ChangesetOutput{}, err } - prop, err := ccipdeployment.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ + prop, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ ChainIdentifier: mcms.ChainIdentifier(homeChainSel), Batch: []mcms.Operation{addDonOp}, }}, "setCandidate for commit and AddDon on new Chain", 0) diff --git a/deployment/ccip/changeset/add_chain_test.go b/deployment/ccip/changeset/add_chain_test.go index 76104871784..aa702a002cd 100644 --- a/deployment/ccip/changeset/add_chain_test.go +++ b/deployment/ccip/changeset/add_chain_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" + "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" commontypes "github.com/smartcontractkit/chainlink/deployment/common/types" "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" @@ -31,15 +31,15 @@ import ( func TestAddChainInbound(t *testing.T) { // 4 chains where the 4th is added after initial deployment. - e := ccipdeployment.NewMemoryEnvironmentWithJobs(t, logger.TestLogger(t), 4, 4) - state, err := ccipdeployment.LoadOnchainState(e.Env) + e := NewMemoryEnvironmentWithJobs(t, logger.TestLogger(t), 4, 4) + state, err := LoadOnchainState(e.Env) require.NoError(t, err) // Take first non-home chain as the new chain. newChain := e.Env.AllChainSelectorsExcluding([]uint64{e.HomeChainSel})[0] // We deploy to the rest. initialDeploy := e.Env.AllChainSelectorsExcluding([]uint64{newChain}) newAddresses := deployment.NewMemoryAddressBook() - err = ccipdeployment.DeployPrerequisiteChainContracts(e.Env, newAddresses, initialDeploy) + err = DeployPrerequisiteChainContracts(e.Env, newAddresses, initialDeploy) require.NoError(t, err) require.NoError(t, e.Env.ExistingAddresses.Merge(newAddresses)) @@ -58,8 +58,8 @@ func TestAddChainInbound(t *testing.T) { require.NoError(t, err) require.NoError(t, e.Env.ExistingAddresses.Merge(out.AddressBook)) newAddresses = deployment.NewMemoryAddressBook() - tokenConfig := ccipdeployment.NewTestTokenConfig(state.Chains[e.FeedChainSel].USDFeeds) - err = ccipdeployment.DeployCCIPContracts(e.Env, newAddresses, ccipdeployment.DeployCCIPContractConfig{ + tokenConfig := NewTestTokenConfig(state.Chains[e.FeedChainSel].USDFeeds) + err = DeployCCIPContracts(e.Env, newAddresses, DeployCCIPContractConfig{ HomeChainSel: e.HomeChainSel, FeedChainSel: e.FeedChainSel, ChainsToDeploy: initialDeploy, @@ -68,19 +68,19 @@ func TestAddChainInbound(t *testing.T) { }) require.NoError(t, err) require.NoError(t, e.Env.ExistingAddresses.Merge(newAddresses)) - state, err = ccipdeployment.LoadOnchainState(e.Env) + state, err = LoadOnchainState(e.Env) require.NoError(t, err) // Connect all the existing lanes. for _, source := range initialDeploy { for _, dest := range initialDeploy { if source != dest { - require.NoError(t, ccipdeployment.AddLaneWithDefaultPrices(e.Env, state, source, dest)) + require.NoError(t, AddLaneWithDefaultPrices(e.Env, state, source, dest)) } } } - rmnHomeAddress, err := deployment.SearchAddressBook(e.Env.ExistingAddresses, e.HomeChainSel, ccipdeployment.RMNHome) + rmnHomeAddress, err := deployment.SearchAddressBook(e.Env.ExistingAddresses, e.HomeChainSel, RMNHome) require.NoError(t, err) require.True(t, common.IsHexAddress(rmnHomeAddress)) rmnHome, err := rmn_home.NewRMNHome(common.HexToAddress(rmnHomeAddress), e.Env.Chains[e.HomeChainSel].Client) @@ -94,15 +94,15 @@ func TestAddChainInbound(t *testing.T) { require.NoError(t, e.Env.ExistingAddresses.Merge(out.AddressBook)) newAddresses = deployment.NewMemoryAddressBook() - err = ccipdeployment.DeployPrerequisiteChainContracts(e.Env, newAddresses, []uint64{newChain}) + err = DeployPrerequisiteChainContracts(e.Env, newAddresses, []uint64{newChain}) require.NoError(t, err) require.NoError(t, e.Env.ExistingAddresses.Merge(newAddresses)) newAddresses = deployment.NewMemoryAddressBook() - err = ccipdeployment.DeployChainContracts(e.Env, + err = deployChainContracts(e.Env, e.Env.Chains[newChain], newAddresses, rmnHome) require.NoError(t, err) require.NoError(t, e.Env.ExistingAddresses.Merge(newAddresses)) - state, err = ccipdeployment.LoadOnchainState(e.Env) + state, err = LoadOnchainState(e.Env) require.NoError(t, err) // Transfer onramp/fq ownership to timelock. @@ -135,7 +135,7 @@ func TestAddChainInbound(t *testing.T) { _, err = deployment.ConfirmIfNoError(e.Env.Chains[e.HomeChainSel], tx, err) require.NoError(t, err) - acceptOwnershipProposal, err := ccipdeployment.GenerateAcceptOwnershipProposal(state, e.HomeChainSel, initialDeploy) + acceptOwnershipProposal, err := GenerateAcceptOwnershipProposal(state, e.HomeChainSel, initialDeploy) require.NoError(t, err) acceptOwnershipExec := commonchangeset.SignProposal(t, e.Env, acceptOwnershipProposal) // Apply the accept ownership proposal to all the chains. @@ -160,7 +160,7 @@ func TestAddChainInbound(t *testing.T) { // Generate and sign inbound proposal to new 4th chain. chainInboundChangeset, err := NewChainInboundChangeset(e.Env, state, e.HomeChainSel, newChain, initialDeploy) require.NoError(t, err) - ccipdeployment.ProcessChangeset(t, e.Env, chainInboundChangeset) + ProcessChangeset(t, e.Env, chainInboundChangeset) // TODO This currently is not working - Able to send the request here but request gets stuck in execution // Send a new message and expect that this is delivered once the chain is completely set up as inbound @@ -169,25 +169,25 @@ func TestAddChainInbound(t *testing.T) { t.Logf("Executing add don and set candidate proposal for commit plugin on chain %d", newChain) addDonChangeset, err := AddDonAndSetCandidateChangeset(state, e.Env, nodes, deployment.XXXGenerateTestOCRSecrets(), e.HomeChainSel, e.FeedChainSel, newChain, tokenConfig, types.PluginTypeCCIPCommit) require.NoError(t, err) - ccipdeployment.ProcessChangeset(t, e.Env, addDonChangeset) + ProcessChangeset(t, e.Env, addDonChangeset) t.Logf("Executing promote candidate proposal for exec plugin on chain %d", newChain) setCandidateForExecChangeset, err := SetCandidatePluginChangeset(state, e.Env, nodes, deployment.XXXGenerateTestOCRSecrets(), e.HomeChainSel, e.FeedChainSel, newChain, tokenConfig, types.PluginTypeCCIPExec) require.NoError(t, err) - ccipdeployment.ProcessChangeset(t, e.Env, setCandidateForExecChangeset) + ProcessChangeset(t, e.Env, setCandidateForExecChangeset) t.Logf("Executing promote candidate proposal for both commit and exec plugins on chain %d", newChain) donPromoteChangeset, err := PromoteAllCandidatesChangeset(state, e.HomeChainSel, newChain, nodes) require.NoError(t, err) - ccipdeployment.ProcessChangeset(t, e.Env, donPromoteChangeset) + ProcessChangeset(t, e.Env, donPromoteChangeset) // verify if the configs are updated - require.NoError(t, ccipdeployment.ValidateCCIPHomeConfigSetUp( + require.NoError(t, ValidateCCIPHomeConfigSetUp( state.Chains[e.HomeChainSel].CapabilityRegistry, state.Chains[e.HomeChainSel].CCIPHome, newChain, )) - replayBlocks, err := ccipdeployment.LatestBlocksByChain(testcontext.Get(t), e.Env.Chains) + replayBlocks, err := LatestBlocksByChain(testcontext.Get(t), e.Env.Chains) require.NoError(t, err) // Now configure the new chain using deployer key (not transferred to timelock yet). @@ -205,9 +205,9 @@ func TestAddChainInbound(t *testing.T) { _, err = deployment.ConfirmIfNoError(e.Env.Chains[newChain], tx, err) require.NoError(t, err) // Set the OCR3 config on new 4th chain to enable the plugin. - latestDON, err := ccipdeployment.LatestCCIPDON(state.Chains[e.HomeChainSel].CapabilityRegistry) + latestDON, err := internal.LatestCCIPDON(state.Chains[e.HomeChainSel].CapabilityRegistry) require.NoError(t, err) - ocrConfigs, err := ccipdeployment.BuildSetOCR3ConfigArgs(latestDON.Id, state.Chains[e.HomeChainSel].CCIPHome, newChain) + ocrConfigs, err := internal.BuildSetOCR3ConfigArgs(latestDON.Id, state.Chains[e.HomeChainSel].CCIPHome, newChain) require.NoError(t, err) tx, err = state.Chains[newChain].OffRamp.SetOCR3Configs(e.Env.Chains[newChain].DeployerKey, ocrConfigs) require.NoError(t, err) @@ -215,7 +215,7 @@ func TestAddChainInbound(t *testing.T) { require.NoError(t, err) // Assert the inbound lanes to the new chain are wired correctly. - state, err = ccipdeployment.LoadOnchainState(e.Env) + state, err = LoadOnchainState(e.Env) require.NoError(t, err) for _, chain := range initialDeploy { cfg, err2 := state.Chains[chain].OnRamp.GetDestChainConfig(nil, newChain) @@ -230,14 +230,14 @@ func TestAddChainInbound(t *testing.T) { } // Ensure job related logs are up to date. time.Sleep(30 * time.Second) - ccipdeployment.ReplayLogs(t, e.Env.Offchain, replayBlocks) + ReplayLogs(t, e.Env.Offchain, replayBlocks) // TODO: Send via all inbound lanes and use parallel helper // Now that the proposal has been executed we expect to be able to send traffic to this new 4th chain. latesthdr, err := e.Env.Chains[newChain].Client.HeaderByNumber(testcontext.Get(t), nil) require.NoError(t, err) startBlock := latesthdr.Number.Uint64() - msgSentEvent := ccipdeployment.TestSendRequest(t, e.Env, state, initialDeploy[0], newChain, true, router.ClientEVM2AnyMessage{ + msgSentEvent := TestSendRequest(t, e.Env, state, initialDeploy[0], newChain, true, router.ClientEVM2AnyMessage{ Receiver: common.LeftPadBytes(state.Chains[newChain].Receiver.Address().Bytes(), 32), Data: []byte("hello world"), TokenAmounts: nil, @@ -245,16 +245,16 @@ func TestAddChainInbound(t *testing.T) { ExtraArgs: nil, }) require.NoError(t, - ccipdeployment.ConfirmCommitWithExpectedSeqNumRange(t, e.Env.Chains[initialDeploy[0]], e.Env.Chains[newChain], state.Chains[newChain].OffRamp, &startBlock, cciptypes.SeqNumRange{ + ConfirmCommitWithExpectedSeqNumRange(t, e.Env.Chains[initialDeploy[0]], e.Env.Chains[newChain], state.Chains[newChain].OffRamp, &startBlock, cciptypes.SeqNumRange{ cciptypes.SeqNum(1), cciptypes.SeqNum(msgSentEvent.SequenceNumber), })) require.NoError(t, - commonutils.JustError(ccipdeployment.ConfirmExecWithSeqNr(t, e.Env.Chains[initialDeploy[0]], e.Env.Chains[newChain], state.Chains[newChain].OffRamp, &startBlock, msgSentEvent.SequenceNumber))) + commonutils.JustError(ConfirmExecWithSeqNr(t, e.Env.Chains[initialDeploy[0]], e.Env.Chains[newChain], state.Chains[newChain].OffRamp, &startBlock, msgSentEvent.SequenceNumber))) linkAddress := state.Chains[newChain].LinkToken.Address() feeQuoter := state.Chains[newChain].FeeQuoter timestampedPrice, err := feeQuoter.GetTokenPrice(nil, linkAddress) require.NoError(t, err) - require.Equal(t, ccipdeployment.MockLinkPrice, timestampedPrice.Value) + require.Equal(t, MockLinkPrice, timestampedPrice.Value) } diff --git a/deployment/ccip/add_lane.go b/deployment/ccip/changeset/add_lane.go similarity index 99% rename from deployment/ccip/add_lane.go rename to deployment/ccip/changeset/add_lane.go index 8af96277fc2..82cf60b77f6 100644 --- a/deployment/ccip/add_lane.go +++ b/deployment/ccip/changeset/add_lane.go @@ -1,4 +1,4 @@ -package ccipdeployment +package changeset import ( "encoding/hex" diff --git a/deployment/ccip/add_lane_test.go b/deployment/ccip/changeset/add_lane_test.go similarity index 99% rename from deployment/ccip/add_lane_test.go rename to deployment/ccip/changeset/add_lane_test.go index 5c87a089a1b..4ad6f992bbd 100644 --- a/deployment/ccip/add_lane_test.go +++ b/deployment/ccip/changeset/add_lane_test.go @@ -1,4 +1,4 @@ -package ccipdeployment +package changeset import ( "testing" @@ -9,7 +9,6 @@ import ( commonutils "github.com/smartcontractkit/chainlink-common/pkg/utils" "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" - "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" diff --git a/deployment/ccip/consts.go b/deployment/ccip/changeset/consts.go similarity index 89% rename from deployment/ccip/consts.go rename to deployment/ccip/changeset/consts.go index 48466bcef46..8d5e64ccde7 100644 --- a/deployment/ccip/consts.go +++ b/deployment/ccip/changeset/consts.go @@ -1,4 +1,4 @@ -package ccipdeployment +package changeset type TokenSymbol string diff --git a/deployment/ccip/deploy.go b/deployment/ccip/changeset/deploy.go similarity index 98% rename from deployment/ccip/deploy.go rename to deployment/ccip/changeset/deploy.go index 0dea0a8b1f8..33459c17678 100644 --- a/deployment/ccip/deploy.go +++ b/deployment/ccip/changeset/deploy.go @@ -1,4 +1,4 @@ -package ccipdeployment +package changeset import ( "fmt" @@ -12,6 +12,7 @@ import ( cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3" "github.com/smartcontractkit/chainlink-ccip/pluginconfig" commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config" + "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_home" @@ -438,15 +439,15 @@ func DeployChainContractsForChains( return fmt.Errorf("capability registry not found") } cr, err := capReg.GetHashedCapabilityId( - &bind.CallOpts{}, CapabilityLabelledName, CapabilityVersion) + &bind.CallOpts{}, internal.CapabilityLabelledName, internal.CapabilityVersion) if err != nil { e.Logger.Errorw("Failed to get hashed capability id", "err", err) return err } - if cr != CCIPCapabilityID { - return fmt.Errorf("capability registry does not support CCIP %s %s", hexutil.Encode(cr[:]), hexutil.Encode(CCIPCapabilityID[:])) + if cr != internal.CCIPCapabilityID { + return fmt.Errorf("capability registry does not support CCIP %s %s", hexutil.Encode(cr[:]), hexutil.Encode(internal.CCIPCapabilityID[:])) } - capability, err := capReg.GetCapability(nil, CCIPCapabilityID) + capability, err := capReg.GetCapability(nil, internal.CCIPCapabilityID) if err != nil { e.Logger.Errorw("Failed to get capability", "err", err) return err @@ -472,7 +473,7 @@ func DeployChainContractsForChains( if existingState.Chains[chainSel].LinkToken == nil || existingState.Chains[chainSel].Weth9 == nil { return fmt.Errorf("fee tokens not found for chain %d", chainSel) } - err := DeployChainContracts(e, chain, ab, rmnHome) + err := deployChainContracts(e, chain, ab, rmnHome) if err != nil { e.Logger.Errorw("Failed to deploy chain contracts", "chain", chainSel, "err", err) return fmt.Errorf("failed to deploy chain contracts for chain %d: %w", chainSel, err) @@ -481,7 +482,7 @@ func DeployChainContractsForChains( return nil } -func DeployChainContracts( +func deployChainContracts( e deployment.Environment, chain deployment.Chain, ab deployment.AddressBook, diff --git a/deployment/ccip/changeset/deploy_chain.go b/deployment/ccip/changeset/deploy_chain.go index 633d01bbf4c..cb60f1ddabd 100644 --- a/deployment/ccip/changeset/deploy_chain.go +++ b/deployment/ccip/changeset/deploy_chain.go @@ -6,14 +6,13 @@ import ( "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" "github.com/smartcontractkit/chainlink/deployment" - ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" ) var _ deployment.ChangeSet[DeployChainContractsConfig] = DeployChainContracts func DeployChainContracts(env deployment.Environment, c DeployChainContractsConfig) (deployment.ChangesetOutput, error) { newAddresses := deployment.NewMemoryAddressBook() - err := ccipdeployment.DeployChainContractsForChains(env, newAddresses, c.HomeChainSelector, c.ChainSelectors) + err := DeployChainContractsForChains(env, newAddresses, c.HomeChainSelector, c.ChainSelectors) if err != nil { env.Logger.Errorw("Failed to deploy CCIP contracts", "err", err, "newAddresses", newAddresses) return deployment.ChangesetOutput{AddressBook: newAddresses}, deployment.MaybeDataErr(err) diff --git a/deployment/ccip/changeset/deploy_chain_test.go b/deployment/ccip/changeset/deploy_chain_test.go index 0e5b7a8d270..acab6fde6cb 100644 --- a/deployment/ccip/changeset/deploy_chain_test.go +++ b/deployment/ccip/changeset/deploy_chain_test.go @@ -8,7 +8,6 @@ import ( "go.uber.org/zap/zapcore" "github.com/smartcontractkit/chainlink/deployment" - ccdeploy "github.com/smartcontractkit/chainlink/deployment/ccip" commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" commontypes "github.com/smartcontractkit/chainlink/deployment/common/types" "github.com/smartcontractkit/chainlink/deployment/environment/memory" @@ -30,9 +29,9 @@ func TestDeployChainContractsChangeset(t *testing.T) { // deploy home chain homeChainCfg := DeployHomeChainConfig{ HomeChainSel: homeChainSel, - RMNStaticConfig: ccdeploy.NewTestRMNStaticConfig(), - RMNDynamicConfig: ccdeploy.NewTestRMNDynamicConfig(), - NodeOperators: ccdeploy.NewTestNodeOperator(e.Chains[homeChainSel].DeployerKey.From), + RMNStaticConfig: NewTestRMNStaticConfig(), + RMNDynamicConfig: NewTestRMNDynamicConfig(), + NodeOperators: NewTestNodeOperator(e.Chains[homeChainSel].DeployerKey.From), NodeP2PIDsPerNodeOpAdmin: map[string][][32]byte{ "NodeOperator": p2pIds, }, @@ -71,7 +70,7 @@ func TestDeployChainContractsChangeset(t *testing.T) { require.NoError(t, e.ExistingAddresses.Merge(output.AddressBook)) // load onchain state - state, err := ccdeploy.LoadOnchainState(e) + state, err := LoadOnchainState(e) require.NoError(t, err) // verify all contracts populated diff --git a/deployment/ccip/deploy_home_chain.go b/deployment/ccip/changeset/deploy_home_chain.go similarity index 51% rename from deployment/ccip/deploy_home_chain.go rename to deployment/ccip/changeset/deploy_home_chain.go index 9c7c65bc9dc..446328c0530 100644 --- a/deployment/ccip/deploy_home_chain.go +++ b/deployment/ccip/changeset/deploy_home_chain.go @@ -1,4 +1,4 @@ -package ccipdeployment +package changeset import ( "bytes" @@ -7,10 +7,7 @@ import ( "encoding/json" "fmt" "math/big" - "os" - "time" - "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" @@ -20,17 +17,11 @@ import ( "github.com/smartcontractkit/chainlink-ccip/chainconfig" "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3" "github.com/smartcontractkit/chainlink-ccip/pluginconfig" - - commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config" "github.com/smartcontractkit/chainlink-common/pkg/logger" - "github.com/smartcontractkit/chainlink-common/pkg/merklemulti" - - confighelper2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper" - "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper" + "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" "github.com/smartcontractkit/chainlink/deployment" cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" - "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_home" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_home" @@ -38,54 +29,6 @@ import ( p2ptypes "github.com/smartcontractkit/chainlink/v2/core/services/p2p/types" ) -const ( - NodeOperatorID = 1 - CapabilityLabelledName = "ccip" - CapabilityVersion = "v1.0.0" - - FirstBlockAge = 8 * time.Hour - RemoteGasPriceBatchWriteFrequency = 30 * time.Minute - TokenPriceBatchWriteFrequency = 30 * time.Minute - BatchGasLimit = 6_500_000 - RelativeBoostPerWaitHour = 1.5 - InflightCacheExpiry = 10 * time.Minute - RootSnoozeTime = 30 * time.Minute - BatchingStrategyID = 0 - DeltaProgress = 30 * time.Second - DeltaResend = 10 * time.Second - DeltaInitial = 20 * time.Second - DeltaRound = 2 * time.Second - DeltaGrace = 2 * time.Second - DeltaCertifiedCommitRequest = 10 * time.Second - DeltaStage = 10 * time.Second - Rmax = 3 - MaxDurationQuery = 500 * time.Millisecond - MaxDurationObservation = 5 * time.Second - MaxDurationShouldAcceptAttestedReport = 10 * time.Second - MaxDurationShouldTransmitAcceptedReport = 10 * time.Second -) - -var ( - CCIPCapabilityID = utils.Keccak256Fixed(MustABIEncode(`[{"type": "string"}, {"type": "string"}]`, CapabilityLabelledName, CapabilityVersion)) - CCIPHomeABI *abi.ABI -) - -func init() { - var err error - CCIPHomeABI, err = ccip_home.CCIPHomeMetaData.GetAbi() - if err != nil { - panic(err) - } -} - -func MustABIEncode(abiString string, args ...interface{}) []byte { - encoded, err := utils.ABIEncode(abiString, args...) - if err != nil { - panic(err) - } - return encoded -} - // DeployCapReg deploys the CapabilitiesRegistry contract if it is not already deployed // and returns a deployment.ContractDeploy struct with the address and contract instance. func DeployCapReg( @@ -121,7 +64,7 @@ func DeployCapReg( return capReg, nil } -func DeployHomeChain( +func deployHomeChain( lggr logger.Logger, e deployment.Environment, ab deployment.AddressBook, @@ -213,8 +156,8 @@ func DeployHomeChain( tx, err = capReg.Contract.AddCapabilities(chain.DeployerKey, []capabilities_registry.CapabilitiesRegistryCapability{ { - LabelledName: CapabilityLabelledName, - Version: CapabilityVersion, + LabelledName: internal.CapabilityLabelledName, + Version: internal.CapabilityVersion, CapabilityType: 2, // consensus. not used (?) ResponseType: 0, // report. not used (?) ConfigurationContract: ccipHome.Address, @@ -260,27 +203,6 @@ func DeployHomeChain( return capReg, nil } -// getNodeOperatorIDMap returns a map of node operator names to their IDs -// If maxNops is greater than the number of node operators, it will return all node operators -func getNodeOperatorIDMap(capReg *capabilities_registry.CapabilitiesRegistry, maxNops uint32) (map[string]uint32, error) { - nopIdByName := make(map[string]uint32) - operators, err := capReg.GetNodeOperators(nil) - if err != nil { - return nil, err - } - if len(operators) < int(maxNops) { - maxNops = uint32(len(operators)) - } - for i := uint32(1); i <= maxNops; i++ { - operator, err := capReg.GetNodeOperator(nil, i) - if err != nil { - return nil, err - } - nopIdByName[operator.Name] = i - } - return nopIdByName, nil -} - func isEqualCapabilitiesRegistryNodeParams(a, b capabilities_registry.CapabilitiesRegistryNodeParams) (bool, error) { aBytes, err := json.Marshal(a) if err != nil { @@ -324,7 +246,7 @@ func AddNodes( Signer: p2pID, // Not used in tests P2pId: p2pID, EncryptionPublicKey: p2pID, // Not used in tests - HashedCapabilityIds: [][32]byte{CCIPCapabilityID}, + HashedCapabilityIds: [][32]byte{internal.CCIPCapabilityID}, } if existing, ok := existingNodeParams[p2pID]; ok { if isEqual, err := isEqualCapabilitiesRegistryNodeParams(existing, nodeParam); err != nil && isEqual { @@ -387,214 +309,6 @@ func AddChainConfig( return chainConfig, nil } -func BuildOCR3ConfigForCCIPHome( - ocrSecrets deployment.OCRSecrets, - offRamp *offramp.OffRamp, - dest deployment.Chain, - feedChainSel uint64, - tokenInfo map[ccipocr3.UnknownEncodedAddress]pluginconfig.TokenInfo, - nodes deployment.Nodes, - rmnHomeAddress common.Address, - configs []pluginconfig.TokenDataObserverConfig, -) (map[cctypes.PluginType]ccip_home.CCIPHomeOCR3Config, error) { - p2pIDs := nodes.PeerIDs() - // Get OCR3 Config from helper - var schedule []int - var oracles []confighelper2.OracleIdentityExtra - for _, node := range nodes { - schedule = append(schedule, 1) - cfg := node.SelToOCRConfig[dest.Selector] - oracles = append(oracles, confighelper2.OracleIdentityExtra{ - OracleIdentity: confighelper2.OracleIdentity{ - OnchainPublicKey: cfg.OnchainPublicKey, - TransmitAccount: cfg.TransmitAccount, - OffchainPublicKey: cfg.OffchainPublicKey, - PeerID: cfg.PeerID.String()[4:], - }, ConfigEncryptionPublicKey: cfg.ConfigEncryptionPublicKey, - }) - } - - // Add DON on capability registry contract - ocr3Configs := make(map[cctypes.PluginType]ccip_home.CCIPHomeOCR3Config) - for _, pluginType := range []cctypes.PluginType{cctypes.PluginTypeCCIPCommit, cctypes.PluginTypeCCIPExec} { - var encodedOffchainConfig []byte - var err2 error - if pluginType == cctypes.PluginTypeCCIPCommit { - encodedOffchainConfig, err2 = pluginconfig.EncodeCommitOffchainConfig(pluginconfig.CommitOffchainConfig{ - RemoteGasPriceBatchWriteFrequency: *commonconfig.MustNewDuration(RemoteGasPriceBatchWriteFrequency), - TokenPriceBatchWriteFrequency: *commonconfig.MustNewDuration(TokenPriceBatchWriteFrequency), - PriceFeedChainSelector: ccipocr3.ChainSelector(feedChainSel), - TokenInfo: tokenInfo, - NewMsgScanBatchSize: merklemulti.MaxNumberTreeLeaves, - MaxReportTransmissionCheckAttempts: 5, - MaxMerkleTreeSize: merklemulti.MaxNumberTreeLeaves, - SignObservationPrefix: "chainlink ccip 1.6 rmn observation", - RMNEnabled: os.Getenv("ENABLE_RMN") == "true", // only enabled in manual test - }) - } else { - encodedOffchainConfig, err2 = pluginconfig.EncodeExecuteOffchainConfig(pluginconfig.ExecuteOffchainConfig{ - BatchGasLimit: BatchGasLimit, - RelativeBoostPerWaitHour: RelativeBoostPerWaitHour, - MessageVisibilityInterval: *commonconfig.MustNewDuration(FirstBlockAge), - InflightCacheExpiry: *commonconfig.MustNewDuration(InflightCacheExpiry), - RootSnoozeTime: *commonconfig.MustNewDuration(RootSnoozeTime), - BatchingStrategyID: BatchingStrategyID, - TokenDataObservers: configs, - }) - } - if err2 != nil { - return nil, err2 - } - signers, transmitters, configF, _, offchainConfigVersion, offchainConfig, err2 := ocr3confighelper.ContractSetConfigArgsDeterministic( - ocrSecrets.EphemeralSk, - ocrSecrets.SharedSecret, - DeltaProgress, - DeltaResend, - DeltaInitial, - DeltaRound, - DeltaGrace, - DeltaCertifiedCommitRequest, - DeltaStage, - Rmax, - schedule, - oracles, - encodedOffchainConfig, - nil, // maxDurationInitialization - MaxDurationQuery, - MaxDurationObservation, - MaxDurationShouldAcceptAttestedReport, - MaxDurationShouldTransmitAcceptedReport, - int(nodes.DefaultF()), - []byte{}, // empty OnChainConfig - ) - if err2 != nil { - return nil, err2 - } - - signersBytes := make([][]byte, len(signers)) - for i, signer := range signers { - signersBytes[i] = signer - } - - transmittersBytes := make([][]byte, len(transmitters)) - for i, transmitter := range transmitters { - parsed, err2 := common.ParseHexOrString(string(transmitter)) - if err2 != nil { - return nil, err2 - } - transmittersBytes[i] = parsed - } - - var ocrNodes []ccip_home.CCIPHomeOCR3Node - for i := range nodes { - ocrNodes = append(ocrNodes, ccip_home.CCIPHomeOCR3Node{ - P2pId: p2pIDs[i], - SignerKey: signersBytes[i], - TransmitterKey: transmittersBytes[i], - }) - } - - _, ok := ocr3Configs[pluginType] - if ok { - return nil, fmt.Errorf("pluginType %s already exists in ocr3Configs", pluginType.String()) - } - - ocr3Configs[pluginType] = ccip_home.CCIPHomeOCR3Config{ - PluginType: uint8(pluginType), - ChainSelector: dest.Selector, - FRoleDON: configF, - OffchainConfigVersion: offchainConfigVersion, - OfframpAddress: offRamp.Address().Bytes(), - Nodes: ocrNodes, - OffchainConfig: offchainConfig, - RmnHomeAddress: rmnHomeAddress.Bytes(), - } - } - - return ocr3Configs, nil -} - -func LatestCCIPDON(registry *capabilities_registry.CapabilitiesRegistry) (*capabilities_registry.CapabilitiesRegistryDONInfo, error) { - dons, err := registry.GetDONs(nil) - if err != nil { - return nil, err - } - var ccipDON capabilities_registry.CapabilitiesRegistryDONInfo - for _, don := range dons { - if len(don.CapabilityConfigurations) == 1 && - don.CapabilityConfigurations[0].CapabilityId == CCIPCapabilityID && - don.Id > ccipDON.Id { - ccipDON = don - } - } - return &ccipDON, nil -} - -// DonIDForChain returns the DON ID for the chain with the given selector -// It looks up with the CCIPHome contract to find the OCR3 configs for the DONs, and returns the DON ID for the chain matching with the given selector from the OCR3 configs -func DonIDForChain(registry *capabilities_registry.CapabilitiesRegistry, ccipHome *ccip_home.CCIPHome, chainSelector uint64) (uint32, error) { - dons, err := registry.GetDONs(nil) - if err != nil { - return 0, err - } - // TODO: what happens if there are multiple dons for one chain (accidentally?) - for _, don := range dons { - if len(don.CapabilityConfigurations) == 1 && - don.CapabilityConfigurations[0].CapabilityId == CCIPCapabilityID { - configs, err := ccipHome.GetAllConfigs(nil, don.Id, uint8(cctypes.PluginTypeCCIPCommit)) - if err != nil { - return 0, err - } - if configs.ActiveConfig.Config.ChainSelector == chainSelector || configs.CandidateConfig.Config.ChainSelector == chainSelector { - return don.Id, nil - } - } - } - return 0, fmt.Errorf("no DON found for chain %d", chainSelector) -} - -func BuildSetOCR3ConfigArgs( - donID uint32, - ccipHome *ccip_home.CCIPHome, - destSelector uint64, -) ([]offramp.MultiOCR3BaseOCRConfigArgs, error) { - var offrampOCR3Configs []offramp.MultiOCR3BaseOCRConfigArgs - for _, pluginType := range []cctypes.PluginType{cctypes.PluginTypeCCIPCommit, cctypes.PluginTypeCCIPExec} { - ocrConfig, err2 := ccipHome.GetAllConfigs(&bind.CallOpts{ - Context: context.Background(), - }, donID, uint8(pluginType)) - if err2 != nil { - return nil, err2 - } - - fmt.Printf("pluginType: %s, destSelector: %d, donID: %d, activeConfig digest: %x, candidateConfig digest: %x\n", - pluginType.String(), destSelector, donID, ocrConfig.ActiveConfig.ConfigDigest, ocrConfig.CandidateConfig.ConfigDigest) - - // we expect only an active config and no candidate config. - if ocrConfig.ActiveConfig.ConfigDigest == [32]byte{} || ocrConfig.CandidateConfig.ConfigDigest != [32]byte{} { - return nil, fmt.Errorf("invalid OCR3 config state, expected active config and no candidate config, donID: %d", donID) - } - - activeConfig := ocrConfig.ActiveConfig - var signerAddresses []common.Address - var transmitterAddresses []common.Address - for _, node := range activeConfig.Config.Nodes { - signerAddresses = append(signerAddresses, common.BytesToAddress(node.SignerKey)) - transmitterAddresses = append(transmitterAddresses, common.BytesToAddress(node.TransmitterKey)) - } - - offrampOCR3Configs = append(offrampOCR3Configs, offramp.MultiOCR3BaseOCRConfigArgs{ - ConfigDigest: activeConfig.ConfigDigest, - OcrPluginType: uint8(pluginType), - F: activeConfig.Config.FRoleDON, - IsSignatureVerificationEnabled: pluginType == cctypes.PluginTypeCCIPCommit, - Signers: signerAddresses, - Transmitters: transmitterAddresses, - }) - } - return offrampOCR3Configs, nil -} - // CreateDON creates one DON with 2 plugins (commit and exec) // It first set a new candidate for the DON with the first plugin type and AddDON on capReg // Then for subsequent operations it uses UpdateDON to promote the first plugin to the active deployment @@ -618,154 +332,26 @@ func CreateDON( return fmt.Errorf("missing exec plugin in ocr3Configs") } - latestDon, err := LatestCCIPDON(capReg) + latestDon, err := internal.LatestCCIPDON(capReg) if err != nil { return err } donID := latestDon.Id + 1 - err = setupCommitDON(donID, commitConfig, capReg, home, nodes, ccipHome) + err = internal.SetupCommitDON(donID, commitConfig, capReg, home, nodes, ccipHome) if err != nil { return fmt.Errorf("setup commit don: %w", err) } // TODO: bug in contract causing this to not work as expected. - err = setupExecDON(donID, execConfig, capReg, home, nodes, ccipHome) + err = internal.SetupExecDON(donID, execConfig, capReg, home, nodes, ccipHome) if err != nil { return fmt.Errorf("setup exec don: %w", err) } return ValidateCCIPHomeConfigSetUp(capReg, ccipHome, newChainSel) } -func setupExecDON( - donID uint32, - execConfig ccip_home.CCIPHomeOCR3Config, - capReg *capabilities_registry.CapabilitiesRegistry, - home deployment.Chain, - nodes deployment.Nodes, - ccipHome *ccip_home.CCIPHome, -) error { - encodedSetCandidateCall, err := CCIPHomeABI.Pack( - "setCandidate", - donID, - execConfig.PluginType, - execConfig, - [32]byte{}, - ) - if err != nil { - return fmt.Errorf("pack set candidate call: %w", err) - } - - // set candidate call - tx, err := capReg.UpdateDON( - home.DeployerKey, - donID, - nodes.PeerIDs(), - []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ - { - CapabilityId: CCIPCapabilityID, - Config: encodedSetCandidateCall, - }, - }, - false, - nodes.DefaultF(), - ) - if err != nil { - return fmt.Errorf("update don w/ exec config: %w", err) - } - - if _, err := deployment.ConfirmIfNoError(home, tx, err); err != nil { - return fmt.Errorf("confirm update don w/ exec config: %w", err) - } - - execCandidateDigest, err := ccipHome.GetCandidateDigest(nil, donID, execConfig.PluginType) - if err != nil { - return fmt.Errorf("get exec candidate digest 1st time: %w", err) - } - - if execCandidateDigest == [32]byte{} { - return fmt.Errorf("candidate digest is empty, expected nonempty") - } - - // promote candidate call - encodedPromotionCall, err := CCIPHomeABI.Pack( - "promoteCandidateAndRevokeActive", - donID, - execConfig.PluginType, - execCandidateDigest, - [32]byte{}, - ) - if err != nil { - return fmt.Errorf("pack promotion call: %w", err) - } - - tx, err = capReg.UpdateDON( - home.DeployerKey, - donID, - nodes.PeerIDs(), - []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ - { - CapabilityId: CCIPCapabilityID, - Config: encodedPromotionCall, - }, - }, - false, - nodes.DefaultF(), - ) - if err != nil { - return fmt.Errorf("update don w/ exec config: %w", err) - } - bn, err := deployment.ConfirmIfNoError(home, tx, err) - if err != nil { - return fmt.Errorf("confirm update don w/ exec config: %w", err) - } - if bn == 0 { - return fmt.Errorf("UpdateDON tx not confirmed") - } - // check if candidate digest is promoted - pEvent, err := ccipHome.FilterConfigPromoted(&bind.FilterOpts{ - Context: context.Background(), - Start: bn, - }, [][32]byte{execCandidateDigest}) - if err != nil { - return fmt.Errorf("filter exec config promoted: %w", err) - } - if !pEvent.Next() { - return fmt.Errorf("exec config not promoted") - } - // check that candidate digest is empty. - execCandidateDigest, err = ccipHome.GetCandidateDigest(nil, donID, execConfig.PluginType) - if err != nil { - return fmt.Errorf("get exec candidate digest 2nd time: %w", err) - } - - if execCandidateDigest != [32]byte{} { - return fmt.Errorf("candidate digest is nonempty after promotion, expected empty") - } - - // check that active digest is non-empty. - execActiveDigest, err := ccipHome.GetActiveDigest(nil, donID, uint8(cctypes.PluginTypeCCIPExec)) - if err != nil { - return fmt.Errorf("get active exec digest: %w", err) - } - - if execActiveDigest == [32]byte{} { - return fmt.Errorf("active exec digest is empty, expected nonempty") - } - - execConfigs, err := ccipHome.GetAllConfigs(nil, donID, uint8(cctypes.PluginTypeCCIPExec)) - if err != nil { - return fmt.Errorf("get all exec configs 2nd time: %w", err) - } - - // print the above info - fmt.Printf("completed exec DON creation and promotion: donID: %d execCandidateDigest: %x, execActiveDigest: %x, execCandidateDigestFromGetAllConfigs: %x, execActiveDigestFromGetAllConfigs: %x\n", - donID, execCandidateDigest, execActiveDigest, execConfigs.CandidateConfig.ConfigDigest, execConfigs.ActiveConfig.ConfigDigest) - - return nil -} - // SetCandidateCommitPluginWithAddDonOps sets the candidate commit config by calling setCandidate on CCIPHome contract through the AddDON call on CapReg contract // This should be done first before calling any other UpdateDON calls // This proposes to set up OCR3 config for the commit plugin for the DON @@ -775,7 +361,7 @@ func NewDonWithCandidateOp( capReg *capabilities_registry.CapabilitiesRegistry, nodes deployment.Nodes, ) (mcms.Operation, error) { - encodedSetCandidateCall, err := CCIPHomeABI.Pack( + encodedSetCandidateCall, err := internal.CCIPHomeABI.Pack( "setCandidate", donID, pluginConfig.PluginType, @@ -787,7 +373,7 @@ func NewDonWithCandidateOp( } addDonTx, err := capReg.AddDON(deployment.SimTransactOpts(), nodes.PeerIDs(), []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ { - CapabilityId: CCIPCapabilityID, + CapabilityId: internal.CCIPCapabilityID, Config: encodedSetCandidateCall, }, }, false, false, nodes.DefaultF()) @@ -808,7 +394,7 @@ func ValidateCCIPHomeConfigSetUp( chainSel uint64, ) error { // fetch DONID - donID, err := DonIDForChain(capReg, ccipHome, chainSel) + donID, err := internal.DonIDForChain(capReg, ccipHome, chainSel) if err != nil { return fmt.Errorf("fetch don id for chain: %w", err) } @@ -851,112 +437,6 @@ func ValidateCCIPHomeConfigSetUp( return nil } -func setupCommitDON( - donID uint32, - commitConfig ccip_home.CCIPHomeOCR3Config, - capReg *capabilities_registry.CapabilitiesRegistry, - home deployment.Chain, - nodes deployment.Nodes, - ccipHome *ccip_home.CCIPHome, -) error { - encodedSetCandidateCall, err := CCIPHomeABI.Pack( - "setCandidate", - donID, - commitConfig.PluginType, - commitConfig, - [32]byte{}, - ) - if err != nil { - return fmt.Errorf("pack set candidate call: %w", err) - } - tx, err := capReg.AddDON(home.DeployerKey, nodes.PeerIDs(), []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ - { - CapabilityId: CCIPCapabilityID, - Config: encodedSetCandidateCall, - }, - }, false, false, nodes.DefaultF()) - if err != nil { - return fmt.Errorf("add don w/ commit config: %w", err) - } - - if _, err := deployment.ConfirmIfNoError(home, tx, err); err != nil { - return fmt.Errorf("confirm add don w/ commit config: %w", err) - } - - commitCandidateDigest, err := ccipHome.GetCandidateDigest(nil, donID, commitConfig.PluginType) - if err != nil { - return fmt.Errorf("get commit candidate digest: %w", err) - } - - if commitCandidateDigest == [32]byte{} { - return fmt.Errorf("candidate digest is empty, expected nonempty") - } - fmt.Printf("commit candidate digest after setCandidate: %x\n", commitCandidateDigest) - - encodedPromotionCall, err := CCIPHomeABI.Pack( - "promoteCandidateAndRevokeActive", - donID, - commitConfig.PluginType, - commitCandidateDigest, - [32]byte{}, - ) - if err != nil { - return fmt.Errorf("pack promotion call: %w", err) - } - - tx, err = capReg.UpdateDON( - home.DeployerKey, - donID, - nodes.PeerIDs(), - []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ - { - CapabilityId: CCIPCapabilityID, - Config: encodedPromotionCall, - }, - }, - false, - nodes.DefaultF(), - ) - if err != nil { - return fmt.Errorf("update don w/ commit config: %w", err) - } - - if _, err := deployment.ConfirmIfNoError(home, tx, err); err != nil { - return fmt.Errorf("confirm update don w/ commit config: %w", err) - } - - // check that candidate digest is empty. - commitCandidateDigest, err = ccipHome.GetCandidateDigest(nil, donID, commitConfig.PluginType) - if err != nil { - return fmt.Errorf("get commit candidate digest 2nd time: %w", err) - } - - if commitCandidateDigest != [32]byte{} { - return fmt.Errorf("candidate digest is nonempty after promotion, expected empty") - } - - // check that active digest is non-empty. - commitActiveDigest, err := ccipHome.GetActiveDigest(nil, donID, uint8(cctypes.PluginTypeCCIPCommit)) - if err != nil { - return fmt.Errorf("get active commit digest: %w", err) - } - - if commitActiveDigest == [32]byte{} { - return fmt.Errorf("active commit digest is empty, expected nonempty") - } - - commitConfigs, err := ccipHome.GetAllConfigs(nil, donID, uint8(cctypes.PluginTypeCCIPCommit)) - if err != nil { - return fmt.Errorf("get all commit configs 2nd time: %w", err) - } - - // print the above information - fmt.Printf("completed commit DON creation and promotion: donID: %d, commitCandidateDigest: %x, commitActiveDigest: %x, commitCandidateDigestFromGetAllConfigs: %x, commitActiveDigestFromGetAllConfigs: %x\n", - donID, commitCandidateDigest, commitActiveDigest, commitConfigs.CandidateConfig.ConfigDigest, commitConfigs.ActiveConfig.ConfigDigest) - - return nil -} - func AddDON( lggr logger.Logger, ocrSecrets deployment.OCRSecrets, @@ -972,7 +452,7 @@ func AddDON( nodes deployment.Nodes, tokenConfigs []pluginconfig.TokenDataObserverConfig, ) error { - ocrConfigs, err := BuildOCR3ConfigForCCIPHome( + ocrConfigs, err := internal.BuildOCR3ConfigForCCIPHome( ocrSecrets, offRamp, dest, feedChainSel, tokenInfo, nodes, rmnHomeAddress, tokenConfigs) if err != nil { return err @@ -981,13 +461,13 @@ func AddDON( if err != nil { return err } - don, err := LatestCCIPDON(capReg) + don, err := internal.LatestCCIPDON(capReg) if err != nil { return err } lggr.Infow("Added DON", "donID", don.Id) - offrampOCR3Configs, err := BuildSetOCR3ConfigArgs(don.Id, ccipHome, dest.Selector) + offrampOCR3Configs, err := internal.BuildSetOCR3ConfigArgs(don.Id, ccipHome, dest.Selector) if err != nil { return err } diff --git a/deployment/ccip/deploy_test.go b/deployment/ccip/changeset/deploy_test.go similarity index 96% rename from deployment/ccip/deploy_test.go rename to deployment/ccip/changeset/deploy_test.go index c2b71e093de..5054ac2dba5 100644 --- a/deployment/ccip/deploy_test.go +++ b/deployment/ccip/changeset/deploy_test.go @@ -1,4 +1,4 @@ -package ccipdeployment +package changeset import ( "encoding/json" diff --git a/deployment/ccip/changeset/home_chain.go b/deployment/ccip/changeset/home_chain.go index 92b5b09c695..e88db2bcfe0 100644 --- a/deployment/ccip/changeset/home_chain.go +++ b/deployment/ccip/changeset/home_chain.go @@ -8,7 +8,6 @@ import ( "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" "github.com/smartcontractkit/chainlink/deployment" - ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_home" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" ) @@ -23,7 +22,7 @@ func DeployHomeChain(env deployment.Environment, cfg DeployHomeChainConfig) (dep } ab := deployment.NewMemoryAddressBook() // Note we also deploy the cap reg. - _, err = ccipdeployment.DeployHomeChain(env.Logger, env, ab, env.Chains[cfg.HomeChainSel], cfg.RMNStaticConfig, cfg.RMNDynamicConfig, cfg.NodeOperators, cfg.NodeP2PIDsPerNodeOpAdmin) + _, err = deployHomeChain(env.Logger, env, ab, env.Chains[cfg.HomeChainSel], cfg.RMNStaticConfig, cfg.RMNDynamicConfig, cfg.NodeOperators, cfg.NodeP2PIDsPerNodeOpAdmin) if err != nil { env.Logger.Errorw("Failed to deploy cap reg", "err", err, "addresses", env.ExistingAddresses) return deployment.ChangesetOutput{ diff --git a/deployment/ccip/changeset/home_chain_test.go b/deployment/ccip/changeset/home_chain_test.go index f0abdc64437..55bc7466837 100644 --- a/deployment/ccip/changeset/home_chain_test.go +++ b/deployment/ccip/changeset/home_chain_test.go @@ -8,7 +8,6 @@ import ( "go.uber.org/zap/zapcore" "github.com/smartcontractkit/chainlink/deployment" - ccdeploy "github.com/smartcontractkit/chainlink/deployment/ccip" "github.com/smartcontractkit/chainlink/deployment/common/view/v1_0" "github.com/smartcontractkit/chainlink/deployment/environment/memory" "github.com/smartcontractkit/chainlink/v2/core/logger" @@ -27,9 +26,9 @@ func TestDeployHomeChain(t *testing.T) { p2pIds := nodes.NonBootstraps().PeerIDs() homeChainCfg := DeployHomeChainConfig{ HomeChainSel: homeChainSel, - RMNStaticConfig: ccdeploy.NewTestRMNStaticConfig(), - RMNDynamicConfig: ccdeploy.NewTestRMNDynamicConfig(), - NodeOperators: ccdeploy.NewTestNodeOperator(e.Chains[homeChainSel].DeployerKey.From), + RMNStaticConfig: NewTestRMNStaticConfig(), + RMNDynamicConfig: NewTestRMNDynamicConfig(), + NodeOperators: NewTestNodeOperator(e.Chains[homeChainSel].DeployerKey.From), NodeP2PIDsPerNodeOpAdmin: map[string][][32]byte{ "NodeOperator": p2pIds, }, @@ -37,7 +36,7 @@ func TestDeployHomeChain(t *testing.T) { output, err := DeployHomeChain(e, homeChainCfg) require.NoError(t, err) require.NoError(t, e.ExistingAddresses.Merge(output.AddressBook)) - state, err := ccdeploy.LoadOnchainState(e) + state, err := LoadOnchainState(e) require.NoError(t, err) require.NotNil(t, state.Chains[homeChainSel].CapabilityRegistry) require.NotNil(t, state.Chains[homeChainSel].CCIPHome) diff --git a/deployment/ccip/changeset/initial_deploy.go b/deployment/ccip/changeset/initial_deploy.go index de17834e8bd..29cfde18ec2 100644 --- a/deployment/ccip/changeset/initial_deploy.go +++ b/deployment/ccip/changeset/initial_deploy.go @@ -4,20 +4,18 @@ import ( "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" "github.com/smartcontractkit/chainlink/deployment" - - ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" ) -var _ deployment.ChangeSet[ccipdeployment.DeployCCIPContractConfig] = InitialDeploy +var _ deployment.ChangeSet[DeployCCIPContractConfig] = InitialDeploy -func InitialDeploy(env deployment.Environment, c ccipdeployment.DeployCCIPContractConfig) (deployment.ChangesetOutput, error) { +func InitialDeploy(env deployment.Environment, c DeployCCIPContractConfig) (deployment.ChangesetOutput, error) { newAddresses := deployment.NewMemoryAddressBook() - err := ccipdeployment.DeployCCIPContracts(env, newAddresses, c) + err := DeployCCIPContracts(env, newAddresses, c) if err != nil { env.Logger.Errorw("Failed to deploy CCIP contracts", "err", err, "newAddresses", newAddresses) return deployment.ChangesetOutput{AddressBook: newAddresses}, deployment.MaybeDataErr(err) } - js, err := ccipdeployment.NewCCIPJobSpecs(env.NodeIDs, env.Offchain) + js, err := NewCCIPJobSpecs(env.NodeIDs, env.Offchain) if err != nil { return deployment.ChangesetOutput{AddressBook: newAddresses}, err } diff --git a/deployment/ccip/changeset/initial_deploy_test.go b/deployment/ccip/changeset/initial_deploy_test.go index 7c64c0c3240..14ce267d646 100644 --- a/deployment/ccip/changeset/initial_deploy_test.go +++ b/deployment/ccip/changeset/initial_deploy_test.go @@ -7,14 +7,11 @@ import ( "github.com/ethereum/go-ethereum/common" jobv1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job" - commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" commontypes "github.com/smartcontractkit/chainlink/deployment/common/types" - "github.com/smartcontractkit/chainlink/deployment" - ccdeploy "github.com/smartcontractkit/chainlink/deployment/ccip" - "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" + "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" "github.com/smartcontractkit/chainlink/v2/core/logger" @@ -24,11 +21,11 @@ import ( func TestInitialDeploy(t *testing.T) { lggr := logger.TestLogger(t) - ctx := ccdeploy.Context(t) - tenv := ccdeploy.NewMemoryEnvironment(t, lggr, 3, 4, ccdeploy.MockLinkPrice, ccdeploy.MockWethPrice) + ctx := Context(t) + tenv := NewMemoryEnvironment(t, lggr, 3, 4, MockLinkPrice, MockWethPrice) e := tenv.Env - state, err := ccdeploy.LoadOnchainState(tenv.Env) + state, err := LoadOnchainState(tenv.Env) require.NoError(t, err) output, err := DeployPrerequisites(e, DeployPrerequisiteConfig{ ChainSelectors: tenv.Env.AllChainSelectors(), @@ -50,21 +47,21 @@ func TestInitialDeploy(t *testing.T) { require.NoError(t, err) require.NoError(t, e.ExistingAddresses.Merge(output.AddressBook)) - output, err = InitialDeploy(tenv.Env, ccdeploy.DeployCCIPContractConfig{ + output, err = InitialDeploy(tenv.Env, DeployCCIPContractConfig{ HomeChainSel: tenv.HomeChainSel, FeedChainSel: tenv.FeedChainSel, ChainsToDeploy: tenv.Env.AllChainSelectors(), - TokenConfig: ccdeploy.NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds), + TokenConfig: NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds), OCRSecrets: deployment.XXXGenerateTestOCRSecrets(), }) require.NoError(t, err) // Get new state after migration. require.NoError(t, tenv.Env.ExistingAddresses.Merge(output.AddressBook)) - state, err = ccdeploy.LoadOnchainState(e) + state, err = LoadOnchainState(e) require.NoError(t, err) require.NotNil(t, state.Chains[tenv.HomeChainSel].LinkToken) // Ensure capreg logs are up to date. - ccdeploy.ReplayLogs(t, e.Offchain, tenv.ReplayBlocks) + ReplayLogs(t, e.Offchain, tenv.ReplayBlocks) // Apply the jobs. for nodeID, jobs := range output.JobSpecs { @@ -80,11 +77,11 @@ func TestInitialDeploy(t *testing.T) { } // Add all lanes - require.NoError(t, ccdeploy.AddLanesForAll(e, state)) + require.NoError(t, AddLanesForAll(e, state)) // Need to keep track of the block number for each chain so that event subscription can be done from that block. startBlocks := make(map[uint64]*uint64) // Send a message from each chain to every other chain. - expectedSeqNum := make(map[ccdeploy.SourceDestPair]uint64) + expectedSeqNum := make(map[SourceDestPair]uint64) for src := range e.Chains { for dest, destChain := range e.Chains { @@ -95,14 +92,14 @@ func TestInitialDeploy(t *testing.T) { require.NoError(t, err) block := latesthdr.Number.Uint64() startBlocks[dest] = &block - msgSentEvent := ccdeploy.TestSendRequest(t, e, state, src, dest, false, router.ClientEVM2AnyMessage{ + msgSentEvent := TestSendRequest(t, e, state, src, dest, false, router.ClientEVM2AnyMessage{ Receiver: common.LeftPadBytes(state.Chains[dest].Receiver.Address().Bytes(), 32), Data: []byte("hello"), TokenAmounts: nil, FeeToken: common.HexToAddress("0x0"), ExtraArgs: nil, }) - expectedSeqNum[ccdeploy.SourceDestPair{ + expectedSeqNum[SourceDestPair{ SourceChainSelector: src, DestChainSelector: dest, }] = msgSentEvent.SequenceNumber @@ -110,14 +107,14 @@ func TestInitialDeploy(t *testing.T) { } // Wait for all commit reports to land. - ccdeploy.ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks) + ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks) // Confirm token and gas prices are updated - ccdeploy.ConfirmTokenPriceUpdatedForAll(t, e, state, startBlocks, - ccdeploy.DefaultInitialPrices.LinkPrice, ccdeploy.DefaultInitialPrices.WethPrice) + ConfirmTokenPriceUpdatedForAll(t, e, state, startBlocks, + DefaultInitialPrices.LinkPrice, DefaultInitialPrices.WethPrice) // TODO: Fix gas prices? - //ccdeploy.ConfirmGasPriceUpdatedForAll(t, e, state, startBlocks) + //ConfirmGasPriceUpdatedForAll(t, e, state, startBlocks) // //// Wait for all exec reports to land - ccdeploy.ConfirmExecWithSeqNrForAll(t, e, state, expectedSeqNum, startBlocks) + ConfirmExecWithSeqNrForAll(t, e, state, expectedSeqNum, startBlocks) } diff --git a/deployment/ccip/changeset/internal/deploy_home_chain.go b/deployment/ccip/changeset/internal/deploy_home_chain.go new file mode 100644 index 00000000000..af41b290828 --- /dev/null +++ b/deployment/ccip/changeset/internal/deploy_home_chain.go @@ -0,0 +1,536 @@ +package internal + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper" + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper" + + "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3" + "github.com/smartcontractkit/chainlink-ccip/pluginconfig" + "github.com/smartcontractkit/chainlink-common/pkg/config" + "github.com/smartcontractkit/chainlink-common/pkg/merklemulti" + "github.com/smartcontractkit/chainlink/deployment" + "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_home" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" +) + +const ( + CapabilityLabelledName = "ccip" + CapabilityVersion = "v1.0.0" + + FirstBlockAge = 8 * time.Hour + RemoteGasPriceBatchWriteFrequency = 30 * time.Minute + TokenPriceBatchWriteFrequency = 30 * time.Minute + BatchGasLimit = 6_500_000 + RelativeBoostPerWaitHour = 1.5 + InflightCacheExpiry = 10 * time.Minute + RootSnoozeTime = 30 * time.Minute + BatchingStrategyID = 0 + DeltaProgress = 30 * time.Second + DeltaResend = 10 * time.Second + DeltaInitial = 20 * time.Second + DeltaRound = 2 * time.Second + DeltaGrace = 2 * time.Second + DeltaCertifiedCommitRequest = 10 * time.Second + DeltaStage = 10 * time.Second + Rmax = 3 + MaxDurationQuery = 500 * time.Millisecond + MaxDurationObservation = 5 * time.Second + MaxDurationShouldAcceptAttestedReport = 10 * time.Second + MaxDurationShouldTransmitAcceptedReport = 10 * time.Second +) + +var ( + CCIPCapabilityID = utils.Keccak256Fixed(MustABIEncode(`[{"type": "string"}, {"type": "string"}]`, CapabilityLabelledName, CapabilityVersion)) + CCIPHomeABI *abi.ABI +) + +func init() { + var err error + CCIPHomeABI, err = ccip_home.CCIPHomeMetaData.GetAbi() + if err != nil { + panic(err) + } +} + +func MustABIEncode(abiString string, args ...interface{}) []byte { + encoded, err := utils.ABIEncode(abiString, args...) + if err != nil { + panic(err) + } + return encoded +} + +// getNodeOperatorIDMap returns a map of node operator names to their IDs +// If maxNops is greater than the number of node operators, it will return all node operators +// Unused now but could be useful in the future. +func getNodeOperatorIDMap(capReg *capabilities_registry.CapabilitiesRegistry, maxNops uint32) (map[string]uint32, error) { + nopIdByName := make(map[string]uint32) + operators, err := capReg.GetNodeOperators(nil) + if err != nil { + return nil, err + } + if len(operators) < int(maxNops) { + maxNops = uint32(len(operators)) + } + for i := uint32(1); i <= maxNops; i++ { + operator, err := capReg.GetNodeOperator(nil, i) + if err != nil { + return nil, err + } + nopIdByName[operator.Name] = i + } + return nopIdByName, nil +} + +func LatestCCIPDON(registry *capabilities_registry.CapabilitiesRegistry) (*capabilities_registry.CapabilitiesRegistryDONInfo, error) { + dons, err := registry.GetDONs(nil) + if err != nil { + return nil, err + } + var ccipDON capabilities_registry.CapabilitiesRegistryDONInfo + for _, don := range dons { + if len(don.CapabilityConfigurations) == 1 && + don.CapabilityConfigurations[0].CapabilityId == CCIPCapabilityID && + don.Id > ccipDON.Id { + ccipDON = don + } + } + return &ccipDON, nil +} + +// DonIDForChain returns the DON ID for the chain with the given selector +// It looks up with the CCIPHome contract to find the OCR3 configs for the DONs, and returns the DON ID for the chain matching with the given selector from the OCR3 configs +func DonIDForChain(registry *capabilities_registry.CapabilitiesRegistry, ccipHome *ccip_home.CCIPHome, chainSelector uint64) (uint32, error) { + dons, err := registry.GetDONs(nil) + if err != nil { + return 0, err + } + // TODO: what happens if there are multiple dons for one chain (accidentally?) + for _, don := range dons { + if len(don.CapabilityConfigurations) == 1 && + don.CapabilityConfigurations[0].CapabilityId == CCIPCapabilityID { + configs, err := ccipHome.GetAllConfigs(nil, don.Id, uint8(types.PluginTypeCCIPCommit)) + if err != nil { + return 0, err + } + if configs.ActiveConfig.Config.ChainSelector == chainSelector || configs.CandidateConfig.Config.ChainSelector == chainSelector { + return don.Id, nil + } + } + } + return 0, fmt.Errorf("no DON found for chain %d", chainSelector) +} + +func BuildSetOCR3ConfigArgs( + donID uint32, + ccipHome *ccip_home.CCIPHome, + destSelector uint64, +) ([]offramp.MultiOCR3BaseOCRConfigArgs, error) { + var offrampOCR3Configs []offramp.MultiOCR3BaseOCRConfigArgs + for _, pluginType := range []types.PluginType{types.PluginTypeCCIPCommit, types.PluginTypeCCIPExec} { + ocrConfig, err2 := ccipHome.GetAllConfigs(&bind.CallOpts{ + Context: context.Background(), + }, donID, uint8(pluginType)) + if err2 != nil { + return nil, err2 + } + + fmt.Printf("pluginType: %s, destSelector: %d, donID: %d, activeConfig digest: %x, candidateConfig digest: %x\n", + pluginType.String(), destSelector, donID, ocrConfig.ActiveConfig.ConfigDigest, ocrConfig.CandidateConfig.ConfigDigest) + + // we expect only an active config and no candidate config. + if ocrConfig.ActiveConfig.ConfigDigest == [32]byte{} || ocrConfig.CandidateConfig.ConfigDigest != [32]byte{} { + return nil, fmt.Errorf("invalid OCR3 config state, expected active config and no candidate config, donID: %d", donID) + } + + activeConfig := ocrConfig.ActiveConfig + var signerAddresses []common.Address + var transmitterAddresses []common.Address + for _, node := range activeConfig.Config.Nodes { + signerAddresses = append(signerAddresses, common.BytesToAddress(node.SignerKey)) + transmitterAddresses = append(transmitterAddresses, common.BytesToAddress(node.TransmitterKey)) + } + + offrampOCR3Configs = append(offrampOCR3Configs, offramp.MultiOCR3BaseOCRConfigArgs{ + ConfigDigest: activeConfig.ConfigDigest, + OcrPluginType: uint8(pluginType), + F: activeConfig.Config.FRoleDON, + IsSignatureVerificationEnabled: pluginType == types.PluginTypeCCIPCommit, + Signers: signerAddresses, + Transmitters: transmitterAddresses, + }) + } + return offrampOCR3Configs, nil +} + +func SetupExecDON( + donID uint32, + execConfig ccip_home.CCIPHomeOCR3Config, + capReg *capabilities_registry.CapabilitiesRegistry, + home deployment.Chain, + nodes deployment.Nodes, + ccipHome *ccip_home.CCIPHome, +) error { + encodedSetCandidateCall, err := CCIPHomeABI.Pack( + "setCandidate", + donID, + execConfig.PluginType, + execConfig, + [32]byte{}, + ) + if err != nil { + return fmt.Errorf("pack set candidate call: %w", err) + } + + // set candidate call + tx, err := capReg.UpdateDON( + home.DeployerKey, + donID, + nodes.PeerIDs(), + []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ + { + CapabilityId: CCIPCapabilityID, + Config: encodedSetCandidateCall, + }, + }, + false, + nodes.DefaultF(), + ) + if err != nil { + return fmt.Errorf("update don w/ exec config: %w", err) + } + + if _, err := deployment.ConfirmIfNoError(home, tx, err); err != nil { + return fmt.Errorf("confirm update don w/ exec config: %w", err) + } + + execCandidateDigest, err := ccipHome.GetCandidateDigest(nil, donID, execConfig.PluginType) + if err != nil { + return fmt.Errorf("get exec candidate digest 1st time: %w", err) + } + + if execCandidateDigest == [32]byte{} { + return fmt.Errorf("candidate digest is empty, expected nonempty") + } + + // promote candidate call + encodedPromotionCall, err := CCIPHomeABI.Pack( + "promoteCandidateAndRevokeActive", + donID, + execConfig.PluginType, + execCandidateDigest, + [32]byte{}, + ) + if err != nil { + return fmt.Errorf("pack promotion call: %w", err) + } + + tx, err = capReg.UpdateDON( + home.DeployerKey, + donID, + nodes.PeerIDs(), + []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ + { + CapabilityId: CCIPCapabilityID, + Config: encodedPromotionCall, + }, + }, + false, + nodes.DefaultF(), + ) + if err != nil { + return fmt.Errorf("update don w/ exec config: %w", err) + } + bn, err := deployment.ConfirmIfNoError(home, tx, err) + if err != nil { + return fmt.Errorf("confirm update don w/ exec config: %w", err) + } + if bn == 0 { + return fmt.Errorf("UpdateDON tx not confirmed") + } + // check if candidate digest is promoted + pEvent, err := ccipHome.FilterConfigPromoted(&bind.FilterOpts{ + Context: context.Background(), + Start: bn, + }, [][32]byte{execCandidateDigest}) + if err != nil { + return fmt.Errorf("filter exec config promoted: %w", err) + } + if !pEvent.Next() { + return fmt.Errorf("exec config not promoted") + } + // check that candidate digest is empty. + execCandidateDigest, err = ccipHome.GetCandidateDigest(nil, donID, execConfig.PluginType) + if err != nil { + return fmt.Errorf("get exec candidate digest 2nd time: %w", err) + } + + if execCandidateDigest != [32]byte{} { + return fmt.Errorf("candidate digest is nonempty after promotion, expected empty") + } + + // check that active digest is non-empty. + execActiveDigest, err := ccipHome.GetActiveDigest(nil, donID, uint8(types.PluginTypeCCIPExec)) + if err != nil { + return fmt.Errorf("get active exec digest: %w", err) + } + + if execActiveDigest == [32]byte{} { + return fmt.Errorf("active exec digest is empty, expected nonempty") + } + + execConfigs, err := ccipHome.GetAllConfigs(nil, donID, uint8(types.PluginTypeCCIPExec)) + if err != nil { + return fmt.Errorf("get all exec configs 2nd time: %w", err) + } + + // print the above info + fmt.Printf("completed exec DON creation and promotion: donID: %d execCandidateDigest: %x, execActiveDigest: %x, execCandidateDigestFromGetAllConfigs: %x, execActiveDigestFromGetAllConfigs: %x\n", + donID, execCandidateDigest, execActiveDigest, execConfigs.CandidateConfig.ConfigDigest, execConfigs.ActiveConfig.ConfigDigest) + + return nil +} + +func SetupCommitDON( + donID uint32, + commitConfig ccip_home.CCIPHomeOCR3Config, + capReg *capabilities_registry.CapabilitiesRegistry, + home deployment.Chain, + nodes deployment.Nodes, + ccipHome *ccip_home.CCIPHome, +) error { + encodedSetCandidateCall, err := CCIPHomeABI.Pack( + "setCandidate", + donID, + commitConfig.PluginType, + commitConfig, + [32]byte{}, + ) + if err != nil { + return fmt.Errorf("pack set candidate call: %w", err) + } + tx, err := capReg.AddDON(home.DeployerKey, nodes.PeerIDs(), []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ + { + CapabilityId: CCIPCapabilityID, + Config: encodedSetCandidateCall, + }, + }, false, false, nodes.DefaultF()) + if err != nil { + return fmt.Errorf("add don w/ commit config: %w", err) + } + + if _, err := deployment.ConfirmIfNoError(home, tx, err); err != nil { + return fmt.Errorf("confirm add don w/ commit config: %w", err) + } + + commitCandidateDigest, err := ccipHome.GetCandidateDigest(nil, donID, commitConfig.PluginType) + if err != nil { + return fmt.Errorf("get commit candidate digest: %w", err) + } + + if commitCandidateDigest == [32]byte{} { + return fmt.Errorf("candidate digest is empty, expected nonempty") + } + fmt.Printf("commit candidate digest after setCandidate: %x\n", commitCandidateDigest) + + encodedPromotionCall, err := CCIPHomeABI.Pack( + "promoteCandidateAndRevokeActive", + donID, + commitConfig.PluginType, + commitCandidateDigest, + [32]byte{}, + ) + if err != nil { + return fmt.Errorf("pack promotion call: %w", err) + } + + tx, err = capReg.UpdateDON( + home.DeployerKey, + donID, + nodes.PeerIDs(), + []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ + { + CapabilityId: CCIPCapabilityID, + Config: encodedPromotionCall, + }, + }, + false, + nodes.DefaultF(), + ) + if err != nil { + return fmt.Errorf("update don w/ commit config: %w", err) + } + + if _, err := deployment.ConfirmIfNoError(home, tx, err); err != nil { + return fmt.Errorf("confirm update don w/ commit config: %w", err) + } + + // check that candidate digest is empty. + commitCandidateDigest, err = ccipHome.GetCandidateDigest(nil, donID, commitConfig.PluginType) + if err != nil { + return fmt.Errorf("get commit candidate digest 2nd time: %w", err) + } + + if commitCandidateDigest != [32]byte{} { + return fmt.Errorf("candidate digest is nonempty after promotion, expected empty") + } + + // check that active digest is non-empty. + commitActiveDigest, err := ccipHome.GetActiveDigest(nil, donID, uint8(types.PluginTypeCCIPCommit)) + if err != nil { + return fmt.Errorf("get active commit digest: %w", err) + } + + if commitActiveDigest == [32]byte{} { + return fmt.Errorf("active commit digest is empty, expected nonempty") + } + + commitConfigs, err := ccipHome.GetAllConfigs(nil, donID, uint8(types.PluginTypeCCIPCommit)) + if err != nil { + return fmt.Errorf("get all commit configs 2nd time: %w", err) + } + + // print the above information + fmt.Printf("completed commit DON creation and promotion: donID: %d, commitCandidateDigest: %x, commitActiveDigest: %x, commitCandidateDigestFromGetAllConfigs: %x, commitActiveDigestFromGetAllConfigs: %x\n", + donID, commitCandidateDigest, commitActiveDigest, commitConfigs.CandidateConfig.ConfigDigest, commitConfigs.ActiveConfig.ConfigDigest) + + return nil +} + +func BuildOCR3ConfigForCCIPHome( + ocrSecrets deployment.OCRSecrets, + offRamp *offramp.OffRamp, + dest deployment.Chain, + feedChainSel uint64, + tokenInfo map[ccipocr3.UnknownEncodedAddress]pluginconfig.TokenInfo, + nodes deployment.Nodes, + rmnHomeAddress common.Address, + configs []pluginconfig.TokenDataObserverConfig, +) (map[types.PluginType]ccip_home.CCIPHomeOCR3Config, error) { + p2pIDs := nodes.PeerIDs() + // Get OCR3 Config from helper + var schedule []int + var oracles []confighelper.OracleIdentityExtra + for _, node := range nodes { + schedule = append(schedule, 1) + cfg := node.SelToOCRConfig[dest.Selector] + oracles = append(oracles, confighelper.OracleIdentityExtra{ + OracleIdentity: confighelper.OracleIdentity{ + OnchainPublicKey: cfg.OnchainPublicKey, + TransmitAccount: cfg.TransmitAccount, + OffchainPublicKey: cfg.OffchainPublicKey, + PeerID: cfg.PeerID.String()[4:], + }, ConfigEncryptionPublicKey: cfg.ConfigEncryptionPublicKey, + }) + } + + // Add DON on capability registry contract + ocr3Configs := make(map[types.PluginType]ccip_home.CCIPHomeOCR3Config) + for _, pluginType := range []types.PluginType{types.PluginTypeCCIPCommit, types.PluginTypeCCIPExec} { + var encodedOffchainConfig []byte + var err2 error + if pluginType == types.PluginTypeCCIPCommit { + encodedOffchainConfig, err2 = pluginconfig.EncodeCommitOffchainConfig(pluginconfig.CommitOffchainConfig{ + RemoteGasPriceBatchWriteFrequency: *config.MustNewDuration(RemoteGasPriceBatchWriteFrequency), + TokenPriceBatchWriteFrequency: *config.MustNewDuration(TokenPriceBatchWriteFrequency), + PriceFeedChainSelector: ccipocr3.ChainSelector(feedChainSel), + TokenInfo: tokenInfo, + NewMsgScanBatchSize: merklemulti.MaxNumberTreeLeaves, + MaxReportTransmissionCheckAttempts: 5, + MaxMerkleTreeSize: merklemulti.MaxNumberTreeLeaves, + SignObservationPrefix: "chainlink ccip 1.6 rmn observation", + RMNEnabled: os.Getenv("ENABLE_RMN") == "true", // only enabled in manual test + }) + } else { + encodedOffchainConfig, err2 = pluginconfig.EncodeExecuteOffchainConfig(pluginconfig.ExecuteOffchainConfig{ + BatchGasLimit: BatchGasLimit, + RelativeBoostPerWaitHour: RelativeBoostPerWaitHour, + MessageVisibilityInterval: *config.MustNewDuration(FirstBlockAge), + InflightCacheExpiry: *config.MustNewDuration(InflightCacheExpiry), + RootSnoozeTime: *config.MustNewDuration(RootSnoozeTime), + BatchingStrategyID: BatchingStrategyID, + TokenDataObservers: configs, + }) + } + if err2 != nil { + return nil, err2 + } + signers, transmitters, configF, _, offchainConfigVersion, offchainConfig, err2 := ocr3confighelper.ContractSetConfigArgsDeterministic( + ocrSecrets.EphemeralSk, + ocrSecrets.SharedSecret, + DeltaProgress, + DeltaResend, + DeltaInitial, + DeltaRound, + DeltaGrace, + DeltaCertifiedCommitRequest, + DeltaStage, + Rmax, + schedule, + oracles, + encodedOffchainConfig, + nil, // maxDurationInitialization + MaxDurationQuery, + MaxDurationObservation, + MaxDurationShouldAcceptAttestedReport, + MaxDurationShouldTransmitAcceptedReport, + int(nodes.DefaultF()), + []byte{}, // empty OnChainConfig + ) + if err2 != nil { + return nil, err2 + } + + signersBytes := make([][]byte, len(signers)) + for i, signer := range signers { + signersBytes[i] = signer + } + + transmittersBytes := make([][]byte, len(transmitters)) + for i, transmitter := range transmitters { + parsed, err2 := common.ParseHexOrString(string(transmitter)) + if err2 != nil { + return nil, err2 + } + transmittersBytes[i] = parsed + } + + var ocrNodes []ccip_home.CCIPHomeOCR3Node + for i := range nodes { + ocrNodes = append(ocrNodes, ccip_home.CCIPHomeOCR3Node{ + P2pId: p2pIDs[i], + SignerKey: signersBytes[i], + TransmitterKey: transmittersBytes[i], + }) + } + + _, ok := ocr3Configs[pluginType] + if ok { + return nil, fmt.Errorf("pluginType %s already exists in ocr3Configs", pluginType.String()) + } + + ocr3Configs[pluginType] = ccip_home.CCIPHomeOCR3Config{ + PluginType: uint8(pluginType), + ChainSelector: dest.Selector, + FRoleDON: configF, + OffchainConfigVersion: offchainConfigVersion, + OfframpAddress: offRamp.Address().Bytes(), + Nodes: ocrNodes, + OffchainConfig: offchainConfig, + RmnHomeAddress: rmnHomeAddress.Bytes(), + } + } + + return ocr3Configs, nil +} diff --git a/deployment/ccip/jobs.go b/deployment/ccip/changeset/jobs.go similarity index 85% rename from deployment/ccip/jobs.go rename to deployment/ccip/changeset/jobs.go index b7ffed45cac..3a5b0e294d8 100644 --- a/deployment/ccip/jobs.go +++ b/deployment/ccip/changeset/jobs.go @@ -1,7 +1,8 @@ -package ccipdeployment +package changeset import ( "github.com/smartcontractkit/chainlink/deployment" + "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/validate" "github.com/smartcontractkit/chainlink/v2/core/services/relay" ) @@ -26,8 +27,8 @@ func NewCCIPJobSpecs(nodeIds []string, oc deployment.OffchainClient) (map[string if !node.IsBootstrap { spec, err = validate.NewCCIPSpecToml(validate.SpecArgs{ P2PV2Bootstrappers: nodes.BootstrapLocators(), - CapabilityVersion: CapabilityVersion, - CapabilityLabelledName: CapabilityLabelledName, + CapabilityVersion: internal.CapabilityVersion, + CapabilityLabelledName: internal.CapabilityLabelledName, OCRKeyBundleIDs: map[string]string{ // TODO: Validate that that all EVM chains are using the same keybundle. relay.NetworkEVM: node.FirstOCRKeybundle().KeyBundleID, @@ -39,8 +40,8 @@ func NewCCIPJobSpecs(nodeIds []string, oc deployment.OffchainClient) (map[string } else { spec, err = validate.NewCCIPSpecToml(validate.SpecArgs{ P2PV2Bootstrappers: []string{}, // Intentionally empty for bootstraps. - CapabilityVersion: CapabilityVersion, - CapabilityLabelledName: CapabilityLabelledName, + CapabilityVersion: internal.CapabilityVersion, + CapabilityLabelledName: internal.CapabilityLabelledName, OCRKeyBundleIDs: map[string]string{}, // TODO: validate that all EVM chains are using the same keybundle P2PKeyID: node.PeerID.String(), diff --git a/deployment/ccip/changeset/jobspec.go b/deployment/ccip/changeset/jobspec.go index 76352ff364f..bd968c97e1e 100644 --- a/deployment/ccip/changeset/jobspec.go +++ b/deployment/ccip/changeset/jobspec.go @@ -5,11 +5,10 @@ import ( "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" "github.com/smartcontractkit/chainlink/deployment" - ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" ) func Jobspec(env deployment.Environment, _ any) (deployment.ChangesetOutput, error) { - js, err := ccipdeployment.NewCCIPJobSpecs(env.NodeIDs, env.Offchain) + js, err := NewCCIPJobSpecs(env.NodeIDs, env.Offchain) if err != nil { return deployment.ChangesetOutput{}, errors.Wrapf(err, "failed to create job specs") } diff --git a/deployment/ccip/ownership.go b/deployment/ccip/changeset/ownership.go similarity index 98% rename from deployment/ccip/ownership.go rename to deployment/ccip/changeset/ownership.go index ebc3ed60d09..4287363b8a6 100644 --- a/deployment/ccip/ownership.go +++ b/deployment/ccip/changeset/ownership.go @@ -1,4 +1,4 @@ -package ccipdeployment +package changeset import ( "testing" diff --git a/deployment/ccip/changeset/prerequisites.go b/deployment/ccip/changeset/prerequisites.go index 20ff7f5a935..3136c5cc35e 100644 --- a/deployment/ccip/changeset/prerequisites.go +++ b/deployment/ccip/changeset/prerequisites.go @@ -8,7 +8,6 @@ import ( "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" "github.com/smartcontractkit/chainlink/deployment" - ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" ) var ( @@ -23,7 +22,7 @@ func DeployPrerequisites(env deployment.Environment, cfg DeployPrerequisiteConfi return deployment.ChangesetOutput{}, errors.Wrapf(deployment.ErrInvalidConfig, "%v", err) } ab := deployment.NewMemoryAddressBook() - err = ccipdeployment.DeployPrerequisiteChainContracts(env, ab, cfg.ChainSelectors) + err = DeployPrerequisiteChainContracts(env, ab, cfg.ChainSelectors) if err != nil { env.Logger.Errorw("Failed to deploy prerequisite contracts", "err", err, "addressBook", ab) return deployment.ChangesetOutput{ @@ -40,8 +39,8 @@ func DeployPrerequisites(env deployment.Environment, cfg DeployPrerequisiteConfi type DeployPrerequisiteConfig struct { ChainSelectors []uint64 // TODO handle tokens and feeds in prerequisite config - Tokens map[ccipdeployment.TokenSymbol]common.Address - Feeds map[ccipdeployment.TokenSymbol]common.Address + Tokens map[TokenSymbol]common.Address + Feeds map[TokenSymbol]common.Address } func (c DeployPrerequisiteConfig) Validate() error { diff --git a/deployment/ccip/changeset/prerequisites_test.go b/deployment/ccip/changeset/prerequisites_test.go index 94d5c8d0581..1a167b2816c 100644 --- a/deployment/ccip/changeset/prerequisites_test.go +++ b/deployment/ccip/changeset/prerequisites_test.go @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" - ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" "github.com/smartcontractkit/chainlink/deployment/environment/memory" "github.com/smartcontractkit/chainlink/v2/core/logger" ) @@ -27,7 +26,7 @@ func TestDeployPrerequisites(t *testing.T) { require.NoError(t, err) err = e.ExistingAddresses.Merge(output.AddressBook) require.NoError(t, err) - state, err := ccipdeployment.LoadOnchainState(e) + state, err := LoadOnchainState(e) require.NoError(t, err) require.NotNil(t, state.Chains[newChain].LinkToken) require.NotNil(t, state.Chains[newChain].Weth9) diff --git a/deployment/ccip/propose.go b/deployment/ccip/changeset/propose.go similarity index 99% rename from deployment/ccip/propose.go rename to deployment/ccip/changeset/propose.go index d7baf9ab542..1b7d928f414 100644 --- a/deployment/ccip/propose.go +++ b/deployment/ccip/changeset/propose.go @@ -1,4 +1,4 @@ -package ccipdeployment +package changeset import ( "fmt" diff --git a/deployment/ccip/changeset/save_existing_test.go b/deployment/ccip/changeset/save_existing_test.go index 5f09c13b272..c3f25870d2e 100644 --- a/deployment/ccip/changeset/save_existing_test.go +++ b/deployment/ccip/changeset/save_existing_test.go @@ -9,7 +9,6 @@ import ( "go.uber.org/zap/zapcore" "github.com/smartcontractkit/chainlink/deployment" - ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" "github.com/smartcontractkit/chainlink/deployment/environment/memory" "github.com/smartcontractkit/chainlink/v2/core/logger" ) @@ -29,27 +28,27 @@ func TestSaveExisting(t *testing.T) { ExistingContracts: []Contract{ { Address: common.BigToAddress(big.NewInt(1)), - TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.LinkToken, deployment.Version1_0_0), + TypeAndVersion: deployment.NewTypeAndVersion(LinkToken, deployment.Version1_0_0), ChainSelector: chain1, }, { Address: common.BigToAddress(big.NewInt(2)), - TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.WETH9, deployment.Version1_0_0), + TypeAndVersion: deployment.NewTypeAndVersion(WETH9, deployment.Version1_0_0), ChainSelector: chain1, }, { Address: common.BigToAddress(big.NewInt(3)), - TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.TokenAdminRegistry, deployment.Version1_5_0), + TypeAndVersion: deployment.NewTypeAndVersion(TokenAdminRegistry, deployment.Version1_5_0), ChainSelector: chain1, }, { Address: common.BigToAddress(big.NewInt(4)), - TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.RegistryModule, deployment.Version1_5_0), + TypeAndVersion: deployment.NewTypeAndVersion(RegistryModule, deployment.Version1_5_0), ChainSelector: chain2, }, { Address: common.BigToAddress(big.NewInt(5)), - TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.Router, deployment.Version1_2_0), + TypeAndVersion: deployment.NewTypeAndVersion(Router, deployment.Version1_2_0), ChainSelector: chain2, }, }, @@ -59,7 +58,7 @@ func TestSaveExisting(t *testing.T) { require.NoError(t, err) err = e.ExistingAddresses.Merge(output.AddressBook) require.NoError(t, err) - state, err := ccipdeployment.LoadOnchainState(e) + state, err := LoadOnchainState(e) require.NoError(t, err) require.Equal(t, state.Chains[chain1].LinkToken.Address(), common.BigToAddress(big.NewInt(1))) require.Equal(t, state.Chains[chain1].Weth9.Address(), common.BigToAddress(big.NewInt(2))) diff --git a/deployment/ccip/state.go b/deployment/ccip/changeset/state.go similarity index 99% rename from deployment/ccip/state.go rename to deployment/ccip/changeset/state.go index f7fad230cc4..a8b3fb04c96 100644 --- a/deployment/ccip/state.go +++ b/deployment/ccip/changeset/state.go @@ -1,7 +1,8 @@ -package ccipdeployment +package changeset import ( "fmt" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/mock_usdc_token_messenger" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/mock_usdc_token_transmitter" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/usdc_token_pool" diff --git a/deployment/ccip/test_assertions.go b/deployment/ccip/changeset/test_assertions.go similarity index 99% rename from deployment/ccip/test_assertions.go rename to deployment/ccip/changeset/test_assertions.go index ac328499e96..693caa3050d 100644 --- a/deployment/ccip/test_assertions.go +++ b/deployment/ccip/changeset/test_assertions.go @@ -1,4 +1,4 @@ -package ccipdeployment +package changeset import ( "context" diff --git a/deployment/ccip/test_helpers.go b/deployment/ccip/changeset/test_helpers.go similarity index 98% rename from deployment/ccip/test_helpers.go rename to deployment/ccip/changeset/test_helpers.go index f858164e720..ffc7e9a1a1f 100644 --- a/deployment/ccip/test_helpers.go +++ b/deployment/ccip/changeset/test_helpers.go @@ -1,4 +1,4 @@ -package ccipdeployment +package changeset import ( "context" @@ -197,7 +197,7 @@ func NewMemoryEnvironment( envNodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) require.NoError(t, err) e.ExistingAddresses = ab - _, err = DeployHomeChain(lggr, e, e.ExistingAddresses, chains[homeChainSel], + _, err = deployHomeChain(lggr, e, e.ExistingAddresses, chains[homeChainSel], NewTestRMNStaticConfig(), NewTestRMNDynamicConfig(), NewTestNodeOperator(chains[homeChainSel].DeployerKey.From), @@ -296,18 +296,6 @@ func NewMemoryEnvironmentWithJobsAndContracts(t *testing.T, lggr logger.Logger, return e } -func NewMemoryEnvironmentWithJobsAndPrices( - t *testing.T, - lggr logger.Logger, - numChains int, - numNodes int, - linkPrice *big.Int, - wethPrice *big.Int) DeployedEnv { - e := NewMemoryEnvironment(t, lggr, numChains, numNodes, linkPrice, wethPrice) - e.SetupJobs(t) - return e -} - func CCIPSendRequest( e deployment.Environment, state CCIPOnChainState, diff --git a/deployment/ccip/test_params.go b/deployment/ccip/changeset/test_params.go similarity index 97% rename from deployment/ccip/test_params.go rename to deployment/ccip/changeset/test_params.go index 531c48532f1..eea0f8eb183 100644 --- a/deployment/ccip/test_params.go +++ b/deployment/ccip/changeset/test_params.go @@ -1,4 +1,4 @@ -package ccipdeployment +package changeset import ( "github.com/ethereum/go-ethereum/common" diff --git a/deployment/ccip/test_usdc_helpers.go b/deployment/ccip/changeset/test_usdc_helpers.go similarity index 99% rename from deployment/ccip/test_usdc_helpers.go rename to deployment/ccip/changeset/test_usdc_helpers.go index 787ca328a8e..88e9c07f06a 100644 --- a/deployment/ccip/test_usdc_helpers.go +++ b/deployment/ccip/changeset/test_usdc_helpers.go @@ -1,7 +1,10 @@ -package ccipdeployment +package changeset import ( + "math/big" + "github.com/ethereum/go-ethereum/common" + "github.com/smartcontractkit/chainlink-ccip/pkg/reader" "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink/deployment" @@ -10,7 +13,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/mock_usdc_token_transmitter" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/usdc_token_pool" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/burn_mint_erc677" - "math/big" ) func ConfigureUSDCTokenPools( diff --git a/deployment/ccip/token_info.go b/deployment/ccip/changeset/token_info.go similarity index 99% rename from deployment/ccip/token_info.go rename to deployment/ccip/changeset/token_info.go index 559c961e3d4..c658ffa2b2f 100644 --- a/deployment/ccip/token_info.go +++ b/deployment/ccip/changeset/token_info.go @@ -1,9 +1,8 @@ -package ccipdeployment +package changeset import ( "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3" "github.com/smartcontractkit/chainlink-ccip/pluginconfig" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/weth9" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/aggregator_v3_interface" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/burn_mint_erc677" diff --git a/deployment/ccip/changeset/view.go b/deployment/ccip/changeset/view.go index 9d3eb8260c7..1fd8fdbe38f 100644 --- a/deployment/ccip/changeset/view.go +++ b/deployment/ccip/changeset/view.go @@ -4,7 +4,6 @@ import ( "encoding/json" "github.com/smartcontractkit/chainlink/deployment" - ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" ccipview "github.com/smartcontractkit/chainlink/deployment/ccip/view" "github.com/smartcontractkit/chainlink/deployment/common/view" ) @@ -12,7 +11,7 @@ import ( var _ deployment.ViewState = ViewCCIP func ViewCCIP(e deployment.Environment) (json.Marshaler, error) { - state, err := ccipdeployment.LoadOnchainState(e) + state, err := LoadOnchainState(e) if err != nil { return nil, err } diff --git a/integration-tests/ccip-tests/testsetups/test_helpers.go b/integration-tests/ccip-tests/testsetups/test_helpers.go index e82195f19c9..4700c6fd14f 100644 --- a/integration-tests/ccip-tests/testsetups/test_helpers.go +++ b/integration-tests/ccip-tests/testsetups/test_helpers.go @@ -21,12 +21,10 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/ptr" "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" "github.com/smartcontractkit/chainlink-testing-framework/seth" - commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" - commontypes "github.com/smartcontractkit/chainlink/deployment/common/types" - "github.com/smartcontractkit/chainlink/deployment" - ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset" + commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" + commontypes "github.com/smartcontractkit/chainlink/deployment/common/types" "github.com/smartcontractkit/chainlink/deployment/environment/devenv" clclient "github.com/smartcontractkit/chainlink/deployment/environment/nodeclient" "github.com/smartcontractkit/chainlink/integration-tests/actions" @@ -52,7 +50,7 @@ import ( // DeployedLocalDevEnvironment is a helper struct for setting up a local dev environment with docker type DeployedLocalDevEnvironment struct { - ccipdeployment.DeployedEnv + changeset.DeployedEnv testEnv *test_env.CLClusterTestEnv DON *devenv.DON } @@ -78,14 +76,14 @@ func (d DeployedLocalDevEnvironment) RestartChainlinkNodes(t *testing.T) error { func NewLocalDevEnvironmentWithDefaultPrice( t *testing.T, - lggr logger.Logger) (ccipdeployment.DeployedEnv, *test_env.CLClusterTestEnv, testconfig.TestConfig) { - return NewLocalDevEnvironment(t, lggr, ccipdeployment.MockLinkPrice, ccipdeployment.MockWethPrice) + lggr logger.Logger) (changeset.DeployedEnv, *test_env.CLClusterTestEnv, testconfig.TestConfig) { + return NewLocalDevEnvironment(t, lggr, changeset.MockLinkPrice, changeset.MockWethPrice) } func NewLocalDevEnvironment( t *testing.T, lggr logger.Logger, - linkPrice, wethPrice *big.Int) (ccipdeployment.DeployedEnv, *test_env.CLClusterTestEnv, testconfig.TestConfig) { + linkPrice, wethPrice *big.Int) (changeset.DeployedEnv, *test_env.CLClusterTestEnv, testconfig.TestConfig) { ctx := testcontext.Get(t) // create a local docker environment with simulated chains and job-distributor // we cannot create the chainlink nodes yet as we need to deploy the capability registry first @@ -100,11 +98,11 @@ func NewLocalDevEnvironment( require.NotEmpty(t, homeChainSel, "homeChainSel should not be empty") feedSel := envConfig.FeedChainSelector require.NotEmpty(t, feedSel, "feedSel should not be empty") - replayBlocks, err := ccipdeployment.LatestBlocksByChain(ctx, chains) + replayBlocks, err := changeset.LatestBlocksByChain(ctx, chains) require.NoError(t, err) ab := deployment.NewMemoryAddressBook() - crConfig := ccipdeployment.DeployTestContracts(t, lggr, ab, homeChainSel, feedSel, chains, linkPrice, wethPrice) + crConfig := changeset.DeployTestContracts(t, lggr, ab, homeChainSel, feedSel, chains, linkPrice, wethPrice) // start the chainlink nodes with the CR address err = StartChainlinkNodes(t, envConfig, @@ -118,15 +116,19 @@ func NewLocalDevEnvironment( envNodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) require.NoError(t, err) - _, err = ccipdeployment.DeployHomeChain(lggr, *e, e.ExistingAddresses, chains[homeChainSel], - ccipdeployment.NewTestRMNStaticConfig(), - ccipdeployment.NewTestRMNDynamicConfig(), - ccipdeployment.NewTestNodeOperator(chains[homeChainSel].DeployerKey.From), - map[string][][32]byte{ - "NodeOperator": envNodes.NonBootstraps().PeerIDs(), + out, err := changeset.DeployHomeChain(*e, + changeset.DeployHomeChainConfig{ + HomeChainSel: homeChainSel, + RMNStaticConfig: changeset.NewTestRMNStaticConfig(), + RMNDynamicConfig: changeset.NewTestRMNDynamicConfig(), + NodeOperators: changeset.NewTestNodeOperator(chains[homeChainSel].DeployerKey.From), + NodeP2PIDsPerNodeOpAdmin: map[string][][32]byte{ + "NodeOperator": envNodes.NonBootstraps().PeerIDs(), + }, }, ) require.NoError(t, err) + require.NoError(t, e.ExistingAddresses.Merge(out.AddressBook)) zeroLogLggr := logging.GetTestLogger(t) // fund the nodes FundNodes(t, zeroLogLggr, testEnv, cfg, don.PluginNodes()) @@ -150,7 +152,7 @@ func NewLocalDevEnvironment( require.NoError(t, err) require.NoError(t, e.ExistingAddresses.Merge(output.AddressBook)) - state, err := ccipdeployment.LoadOnchainState(*e) + state, err := changeset.LoadOnchainState(*e) require.NoError(t, err) var endpoint string @@ -158,17 +160,17 @@ func NewLocalDevEnvironment( require.NoError(t, err) endpoint = testEnv.MockAdapter.InternalEndpoint - tokenConfig := ccipdeployment.NewTestTokenConfig(state.Chains[feedSel].USDFeeds) + tokenConfig := changeset.NewTestTokenConfig(state.Chains[feedSel].USDFeeds) // Apply migration - output, err = changeset.InitialDeploy(*e, ccipdeployment.DeployCCIPContractConfig{ + output, err = changeset.InitialDeploy(*e, changeset.DeployCCIPContractConfig{ HomeChainSel: homeChainSel, FeedChainSel: feedSel, ChainsToDeploy: e.AllChainSelectors(), TokenConfig: tokenConfig, OCRSecrets: deployment.XXXGenerateTestOCRSecrets(), - USDCConfig: ccipdeployment.USDCConfig{ + USDCConfig: changeset.USDCConfig{ Enabled: true, - USDCAttestationConfig: ccipdeployment.USDCAttestationConfig{ + USDCAttestationConfig: changeset.USDCAttestationConfig{ API: endpoint, APITimeout: commonconfig.MustNewDuration(time.Second), APIInterval: commonconfig.MustNewDuration(500 * time.Millisecond), @@ -179,7 +181,7 @@ func NewLocalDevEnvironment( require.NoError(t, e.ExistingAddresses.Merge(output.AddressBook)) // Ensure capreg logs are up to date. - ccipdeployment.ReplayLogs(t, e.Offchain, replayBlocks) + changeset.ReplayLogs(t, e.Offchain, replayBlocks) // Apply the jobs. for nodeID, jobs := range output.JobSpecs { @@ -194,7 +196,7 @@ func NewLocalDevEnvironment( } } - return ccipdeployment.DeployedEnv{ + return changeset.DeployedEnv{ Env: *e, HomeChainSel: homeChainSel, FeedChainSel: feedSel, @@ -206,7 +208,7 @@ func NewLocalDevEnvironmentWithRMN( t *testing.T, lggr logger.Logger, numRmnNodes int, -) (ccipdeployment.DeployedEnv, devenv.RMNCluster) { +) (changeset.DeployedEnv, devenv.RMNCluster) { tenv, dockerenv, testCfg := NewLocalDevEnvironmentWithDefaultPrice(t, lggr) l := logging.GetTestLogger(t) config := GenerateTestRMNConfig(t, numRmnNodes, tenv, MustNetworksToRPCMap(dockerenv.EVMNetworks)) @@ -253,14 +255,14 @@ func MustCCIPNameToRMNName(a string) string { return v } -func GenerateTestRMNConfig(t *testing.T, nRMNNodes int, tenv ccipdeployment.DeployedEnv, rpcMap map[uint64]string) map[string]devenv.RMNConfig { +func GenerateTestRMNConfig(t *testing.T, nRMNNodes int, tenv changeset.DeployedEnv, rpcMap map[uint64]string) map[string]devenv.RMNConfig { // Find the bootstrappers. nodes, err := deployment.NodeInfo(tenv.Env.NodeIDs, tenv.Env.Offchain) require.NoError(t, err) bootstrappers := nodes.BootstrapLocators() // Just set all RMN nodes to support all chains. - state, err := ccipdeployment.LoadOnchainState(tenv.Env) + state, err := changeset.LoadOnchainState(tenv.Env) require.NoError(t, err) var chainParams []devenv.ChainParam var remoteChains []devenv.RemoteChains diff --git a/integration-tests/smoke/ccip_messaging_test.go b/integration-tests/smoke/ccip_messaging_test.go index 4c797946f54..654946d620a 100644 --- a/integration-tests/smoke/ccip_messaging_test.go +++ b/integration-tests/smoke/ccip_messaging_test.go @@ -16,7 +16,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/merklemulti" "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" "github.com/smartcontractkit/chainlink/deployment" - ccdeploy "github.com/smartcontractkit/chainlink/deployment/ccip" + "github.com/smartcontractkit/chainlink/deployment/ccip/changeset" "github.com/smartcontractkit/chainlink/integration-tests/ccip-tests/testsetups" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/onramp" @@ -27,8 +27,8 @@ import ( type testCaseSetup struct { t *testing.T sender []byte - deployedEnv ccdeploy.DeployedEnv - onchainState ccdeploy.CCIPOnChainState + deployedEnv changeset.DeployedEnv + onchainState changeset.CCIPOnChainState sourceChain, destChain uint64 } @@ -47,10 +47,10 @@ type messagingTestCaseOutput struct { func Test_CCIPMessaging(t *testing.T) { // Setup 2 chains and a single lane. lggr := logger.TestLogger(t) - ctx := ccdeploy.Context(t) + ctx := changeset.Context(t) e, _, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr) - state, err := ccdeploy.LoadOnchainState(e.Env) + state, err := changeset.LoadOnchainState(e.Env) require.NoError(t, err) allChainSelectors := maps.Keys(e.Env.Chains) @@ -64,7 +64,7 @@ func Test_CCIPMessaging(t *testing.T) { ", dest chain selector:", destChain, ) // connect a single lane, source to dest - require.NoError(t, ccdeploy.AddLaneWithDefaultPrices(e.Env, state, sourceChain, destChain)) + require.NoError(t, changeset.AddLaneWithDefaultPrices(e.Env, state, sourceChain, destChain)) var ( replayed bool @@ -89,8 +89,8 @@ func Test_CCIPMessaging(t *testing.T) { }, common.HexToAddress("0xdead"), []byte("hello eoa"), - nil, // default extraArgs - ccdeploy.EXECUTION_STATE_SUCCESS, // success because offRamp won't call an EOA + nil, // default extraArgs + changeset.EXECUTION_STATE_SUCCESS, // success because offRamp won't call an EOA ) }) @@ -103,8 +103,8 @@ func Test_CCIPMessaging(t *testing.T) { }, state.Chains[destChain].FeeQuoter.Address(), []byte("hello FeeQuoter"), - nil, // default extraArgs - ccdeploy.EXECUTION_STATE_SUCCESS, // success because offRamp won't call a contract not implementing CCIPReceiver + nil, // default extraArgs + changeset.EXECUTION_STATE_SUCCESS, // success because offRamp won't call a contract not implementing CCIPReceiver ) }) @@ -120,7 +120,7 @@ func Test_CCIPMessaging(t *testing.T) { state.Chains[destChain].Receiver.Address(), []byte("hello CCIPReceiver"), nil, // default extraArgs - ccdeploy.EXECUTION_STATE_SUCCESS, + changeset.EXECUTION_STATE_SUCCESS, func(t *testing.T) { iter, err := state.Chains[destChain].Receiver.FilterMessageReceived(&bind.FilterOpts{ Context: ctx, @@ -144,8 +144,8 @@ func Test_CCIPMessaging(t *testing.T) { }, state.Chains[destChain].Receiver.Address(), []byte("hello CCIPReceiver with low exec gas"), - ccdeploy.MakeEVMExtraArgsV2(1, false), // 1 gas is too low. - ccdeploy.EXECUTION_STATE_FAILURE, // state would be failed onchain due to low gas + changeset.MakeEVMExtraArgsV2(1, false), // 1 gas is too low. + changeset.EXECUTION_STATE_FAILURE, // state would be failed onchain due to low gas ) manuallyExecute(ctx, t, latestHead.Number.Uint64(), state, destChain, out, sourceChain, e, sender) @@ -159,11 +159,11 @@ func manuallyExecute( ctx context.Context, t *testing.T, startBlock uint64, - state ccdeploy.CCIPOnChainState, + state changeset.CCIPOnChainState, destChain uint64, out messagingTestCaseOutput, sourceChain uint64, - e ccdeploy.DeployedEnv, + e changeset.DeployedEnv, sender []byte, ) { merkleRoot := getMerkleRoot( @@ -230,7 +230,7 @@ func manuallyExecute( newExecutionState, err := state.Chains[destChain].OffRamp.GetExecutionState(&bind.CallOpts{Context: ctx}, sourceChain, out.msgSentEvent.SequenceNumber) require.NoError(t, err) - require.Equal(t, uint8(ccdeploy.EXECUTION_STATE_SUCCESS), newExecutionState) + require.Equal(t, uint8(changeset.EXECUTION_STATE_SUCCESS), newExecutionState) } func getMerkleRoot( @@ -286,12 +286,12 @@ func getMessageHash( return iter.Event.MessageHash } -func sleepAndReplay(t *testing.T, e ccdeploy.DeployedEnv, sourceChain, destChain uint64) { +func sleepAndReplay(t *testing.T, e changeset.DeployedEnv, sourceChain, destChain uint64) { time.Sleep(30 * time.Second) replayBlocks := make(map[uint64]uint64) replayBlocks[sourceChain] = 1 replayBlocks[destChain] = 1 - ccdeploy.ReplayLogs(t, e.Env.Offchain, replayBlocks) + changeset.ReplayLogs(t, e.Env.Offchain, replayBlocks) } func runMessagingTestCase( @@ -310,15 +310,15 @@ func runMessagingTestCase( require.Equal(tc.t, tc.nonce, latestNonce) startBlocks := make(map[uint64]*uint64) - msgSentEvent := ccdeploy.TestSendRequest(tc.t, tc.deployedEnv.Env, tc.onchainState, tc.sourceChain, tc.destChain, false, router.ClientEVM2AnyMessage{ + msgSentEvent := changeset.TestSendRequest(tc.t, tc.deployedEnv.Env, tc.onchainState, tc.sourceChain, tc.destChain, false, router.ClientEVM2AnyMessage{ Receiver: common.LeftPadBytes(receiver.Bytes(), 32), Data: msgData, TokenAmounts: nil, FeeToken: common.HexToAddress("0x0"), ExtraArgs: extraArgs, }) - expectedSeqNum := make(map[ccdeploy.SourceDestPair]uint64) - expectedSeqNum[ccdeploy.SourceDestPair{ + expectedSeqNum := make(map[changeset.SourceDestPair]uint64) + expectedSeqNum[changeset.SourceDestPair{ SourceChainSelector: tc.sourceChain, DestChainSelector: tc.destChain, }] = msgSentEvent.SequenceNumber @@ -330,8 +330,8 @@ func runMessagingTestCase( out.replayed = true } - ccdeploy.ConfirmCommitForAllWithExpectedSeqNums(tc.t, tc.deployedEnv.Env, tc.onchainState, expectedSeqNum, startBlocks) - execStates := ccdeploy.ConfirmExecWithSeqNrForAll(tc.t, tc.deployedEnv.Env, tc.onchainState, expectedSeqNum, startBlocks) + changeset.ConfirmCommitForAllWithExpectedSeqNums(tc.t, tc.deployedEnv.Env, tc.onchainState, expectedSeqNum, startBlocks) + execStates := changeset.ConfirmExecWithSeqNrForAll(tc.t, tc.deployedEnv.Env, tc.onchainState, expectedSeqNum, startBlocks) require.Equalf( tc.t, diff --git a/integration-tests/smoke/ccip_rmn_test.go b/integration-tests/smoke/ccip_rmn_test.go index 4f903e84caf..6b7d54e0224 100644 --- a/integration-tests/smoke/ccip_rmn_test.go +++ b/integration-tests/smoke/ccip_rmn_test.go @@ -15,9 +15,9 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/osutil" "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" + "github.com/smartcontractkit/chainlink/deployment/ccip/changeset" "github.com/smartcontractkit/chainlink/deployment" - ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_home" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_remote" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" @@ -231,7 +231,7 @@ func runRmnTestCase(t *testing.T, tc rmnTestCase) { }) } - onChainState, err := ccipdeployment.LoadOnchainState(envWithRMN.Env) + onChainState, err := changeset.LoadOnchainState(envWithRMN.Env) require.NoError(t, err) t.Logf("onChainState: %#v", onChainState) @@ -335,26 +335,26 @@ func runRmnTestCase(t *testing.T, tc rmnTestCase) { } } - ccipdeployment.ReplayLogs(t, envWithRMN.Env.Offchain, envWithRMN.ReplayBlocks) + changeset.ReplayLogs(t, envWithRMN.Env.Offchain, envWithRMN.ReplayBlocks) // Add all lanes - require.NoError(t, ccipdeployment.AddLanesForAll(envWithRMN.Env, onChainState)) + require.NoError(t, changeset.AddLanesForAll(envWithRMN.Env, onChainState)) // Need to keep track of the block number for each chain so that event subscription can be done from that block. startBlocks := make(map[uint64]*uint64) - expectedSeqNum := make(map[ccipdeployment.SourceDestPair]uint64) + expectedSeqNum := make(map[changeset.SourceDestPair]uint64) for _, msg := range tc.messagesToSend { fromChain := chainSelectors[msg.fromChainIdx] toChain := chainSelectors[msg.toChainIdx] for i := 0; i < msg.count; i++ { - msgSentEvent := ccipdeployment.TestSendRequest(t, envWithRMN.Env, onChainState, fromChain, toChain, false, router.ClientEVM2AnyMessage{ + msgSentEvent := changeset.TestSendRequest(t, envWithRMN.Env, onChainState, fromChain, toChain, false, router.ClientEVM2AnyMessage{ Receiver: common.LeftPadBytes(onChainState.Chains[toChain].Receiver.Address().Bytes(), 32), Data: []byte("hello world"), TokenAmounts: nil, FeeToken: common.HexToAddress("0x0"), ExtraArgs: nil, }) - expectedSeqNum[ccipdeployment.SourceDestPair{ + expectedSeqNum[changeset.SourceDestPair{ SourceChainSelector: fromChain, DestChainSelector: toChain, }] = msgSentEvent.SequenceNumber @@ -368,7 +368,7 @@ func runRmnTestCase(t *testing.T, tc rmnTestCase) { commitReportReceived := make(chan struct{}) go func() { - ccipdeployment.ConfirmCommitForAllWithExpectedSeqNums(t, envWithRMN.Env, onChainState, expectedSeqNum, startBlocks) + changeset.ConfirmCommitForAllWithExpectedSeqNums(t, envWithRMN.Env, onChainState, expectedSeqNum, startBlocks) commitReportReceived <- struct{}{} }() @@ -390,7 +390,7 @@ func runRmnTestCase(t *testing.T, tc rmnTestCase) { if tc.waitForExec { t.Logf("⌛ Waiting for exec reports...") - ccipdeployment.ConfirmExecWithSeqNrForAll(t, envWithRMN.Env, onChainState, expectedSeqNum, startBlocks) + changeset.ConfirmExecWithSeqNrForAll(t, envWithRMN.Env, onChainState, expectedSeqNum, startBlocks) t.Logf("✅ Exec report") } } diff --git a/integration-tests/smoke/ccip_test.go b/integration-tests/smoke/ccip_test.go index ed0093ffbb0..7996a4ccf0a 100644 --- a/integration-tests/smoke/ccip_test.go +++ b/integration-tests/smoke/ccip_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" - ccdeploy "github.com/smartcontractkit/chainlink/deployment/ccip" + "github.com/smartcontractkit/chainlink/deployment/ccip/changeset" "github.com/smartcontractkit/chainlink/integration-tests/ccip-tests/testsetups" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" "github.com/smartcontractkit/chainlink/v2/core/logger" @@ -19,15 +19,15 @@ func TestInitialDeployOnLocal(t *testing.T) { lggr := logger.TestLogger(t) tenv, _, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr) e := tenv.Env - state, err := ccdeploy.LoadOnchainState(e) + state, err := changeset.LoadOnchainState(e) require.NoError(t, err) // Add all lanes - require.NoError(t, ccdeploy.AddLanesForAll(e, state)) + require.NoError(t, changeset.AddLanesForAll(e, state)) // Need to keep track of the block number for each chain so that event subscription can be done from that block. startBlocks := make(map[uint64]*uint64) // Send a message from each chain to every other chain. - expectedSeqNum := make(map[ccdeploy.SourceDestPair]uint64) + expectedSeqNum := make(map[changeset.SourceDestPair]uint64) for src := range e.Chains { for dest, destChain := range e.Chains { if src == dest { @@ -37,14 +37,14 @@ func TestInitialDeployOnLocal(t *testing.T) { require.NoError(t, err) block := latesthdr.Number.Uint64() startBlocks[dest] = &block - msgSentEvent := ccdeploy.TestSendRequest(t, e, state, src, dest, false, router.ClientEVM2AnyMessage{ + msgSentEvent := changeset.TestSendRequest(t, e, state, src, dest, false, router.ClientEVM2AnyMessage{ Receiver: common.LeftPadBytes(state.Chains[dest].Receiver.Address().Bytes(), 32), Data: []byte("hello world"), TokenAmounts: nil, FeeToken: common.HexToAddress("0x0"), ExtraArgs: nil, }) - expectedSeqNum[ccdeploy.SourceDestPair{ + expectedSeqNum[changeset.SourceDestPair{ SourceChainSelector: src, DestChainSelector: dest, }] = msgSentEvent.SequenceNumber @@ -52,7 +52,7 @@ func TestInitialDeployOnLocal(t *testing.T) { } // Wait for all commit reports to land. - ccdeploy.ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks) + changeset.ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks) // After commit is reported on all chains, token prices should be updated in FeeQuoter. for dest := range e.Chains { @@ -60,11 +60,11 @@ func TestInitialDeployOnLocal(t *testing.T) { feeQuoter := state.Chains[dest].FeeQuoter timestampedPrice, err := feeQuoter.GetTokenPrice(nil, linkAddress) require.NoError(t, err) - require.Equal(t, ccdeploy.MockLinkPrice, timestampedPrice.Value) + require.Equal(t, changeset.MockLinkPrice, timestampedPrice.Value) } // Wait for all exec reports to land - ccdeploy.ConfirmExecWithSeqNrForAll(t, e, state, expectedSeqNum, startBlocks) + changeset.ConfirmExecWithSeqNrForAll(t, e, state, expectedSeqNum, startBlocks) // TODO: Apply the proposal. } @@ -74,10 +74,10 @@ func TestTokenTransfer(t *testing.T) { lggr := logger.TestLogger(t) tenv, _, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr) e := tenv.Env - state, err := ccdeploy.LoadOnchainState(e) + state, err := changeset.LoadOnchainState(e) require.NoError(t, err) - srcToken, _, dstToken, _, err := ccdeploy.DeployTransferableToken( + srcToken, _, dstToken, _, err := changeset.DeployTransferableToken( lggr, tenv.Env.Chains, tenv.HomeChainSel, @@ -89,11 +89,11 @@ func TestTokenTransfer(t *testing.T) { require.NoError(t, err) // Add all lanes - require.NoError(t, ccdeploy.AddLanesForAll(e, state)) + require.NoError(t, changeset.AddLanesForAll(e, state)) // Need to keep track of the block number for each chain so that event subscription can be done from that block. startBlocks := make(map[uint64]*uint64) // Send a message from each chain to every other chain. - expectedSeqNum := make(map[ccdeploy.SourceDestPair]uint64) + expectedSeqNum := make(map[changeset.SourceDestPair]uint64) twoCoins := new(big.Int).Mul(big.NewInt(1e18), big.NewInt(2)) tx, err := srcToken.Mint( @@ -150,26 +150,26 @@ func TestTokenTransfer(t *testing.T) { feeToken = common.HexToAddress("0x0") ) if src == tenv.HomeChainSel && dest == tenv.FeedChainSel { - msgSentEvent := ccdeploy.TestSendRequest(t, e, state, src, dest, false, router.ClientEVM2AnyMessage{ + msgSentEvent := changeset.TestSendRequest(t, e, state, src, dest, false, router.ClientEVM2AnyMessage{ Receiver: receiver, Data: data, TokenAmounts: tokens[src], FeeToken: feeToken, ExtraArgs: nil, }) - expectedSeqNum[ccdeploy.SourceDestPair{ + expectedSeqNum[changeset.SourceDestPair{ SourceChainSelector: src, DestChainSelector: dest, }] = msgSentEvent.SequenceNumber } else { - msgSentEvent := ccdeploy.TestSendRequest(t, e, state, src, dest, false, router.ClientEVM2AnyMessage{ + msgSentEvent := changeset.TestSendRequest(t, e, state, src, dest, false, router.ClientEVM2AnyMessage{ Receiver: receiver, Data: data, TokenAmounts: nil, FeeToken: feeToken, ExtraArgs: nil, }) - expectedSeqNum[ccdeploy.SourceDestPair{ + expectedSeqNum[changeset.SourceDestPair{ SourceChainSelector: src, DestChainSelector: dest, }] = msgSentEvent.SequenceNumber @@ -178,7 +178,7 @@ func TestTokenTransfer(t *testing.T) { } // Wait for all commit reports to land. - ccdeploy.ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks) + changeset.ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks) // After commit is reported on all chains, token prices should be updated in FeeQuoter. for dest := range e.Chains { @@ -186,11 +186,11 @@ func TestTokenTransfer(t *testing.T) { feeQuoter := state.Chains[dest].FeeQuoter timestampedPrice, err := feeQuoter.GetTokenPrice(nil, linkAddress) require.NoError(t, err) - require.Equal(t, ccdeploy.MockLinkPrice, timestampedPrice.Value) + require.Equal(t, changeset.MockLinkPrice, timestampedPrice.Value) } // Wait for all exec reports to land - ccdeploy.ConfirmExecWithSeqNrForAll(t, e, state, expectedSeqNum, startBlocks) + changeset.ConfirmExecWithSeqNrForAll(t, e, state, expectedSeqNum, startBlocks) balance, err := dstToken.BalanceOf(nil, state.Chains[tenv.FeedChainSel].Receiver.Address()) require.NoError(t, err) diff --git a/integration-tests/smoke/ccip_usdc_test.go b/integration-tests/smoke/ccip_usdc_test.go index bc527925c16..aef2c916842 100644 --- a/integration-tests/smoke/ccip_usdc_test.go +++ b/integration-tests/smoke/ccip_usdc_test.go @@ -14,7 +14,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" "github.com/smartcontractkit/chainlink/deployment" - ccdeploy "github.com/smartcontractkit/chainlink/deployment/ccip" + "github.com/smartcontractkit/chainlink/deployment/ccip/changeset" "github.com/smartcontractkit/chainlink/integration-tests/ccip-tests/testsetups" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" @@ -28,17 +28,17 @@ func TestUSDCTokenTransfer(t *testing.T) { tenv, _, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr) e := tenv.Env - state, err := ccdeploy.LoadOnchainState(e) + state, err := changeset.LoadOnchainState(e) require.NoError(t, err) allChainSelectors := maps.Keys(e.Chains) sourceChain := allChainSelectors[0] destChain := allChainSelectors[1] - srcUSDC, dstUSDC, err := ccdeploy.ConfigureUSDCTokenPools(lggr, e.Chains, sourceChain, destChain, state) + srcUSDC, dstUSDC, err := changeset.ConfigureUSDCTokenPools(lggr, e.Chains, sourceChain, destChain, state) require.NoError(t, err) - srcToken, _, dstToken, _, err := ccdeploy.DeployTransferableToken( + srcToken, _, dstToken, _, err := changeset.DeployTransferableToken( lggr, tenv.Env.Chains, sourceChain, @@ -50,17 +50,17 @@ func TestUSDCTokenTransfer(t *testing.T) { require.NoError(t, err) // Add all lanes - require.NoError(t, ccdeploy.AddLanesForAll(e, state)) + require.NoError(t, changeset.AddLanesForAll(e, state)) mintAndAllow(t, e, state, map[uint64][]*burn_mint_erc677.BurnMintERC677{ sourceChain: {srcUSDC, srcToken}, destChain: {dstUSDC, dstToken}, }) - err = ccdeploy.UpdateFeeQuoterForUSDC(lggr, e.Chains[sourceChain], state.Chains[sourceChain], destChain, srcUSDC) + err = changeset.UpdateFeeQuoterForUSDC(lggr, e.Chains[sourceChain], state.Chains[sourceChain], destChain, srcUSDC) require.NoError(t, err) - err = ccdeploy.UpdateFeeQuoterForUSDC(lggr, e.Chains[destChain], state.Chains[destChain], sourceChain, dstUSDC) + err = changeset.UpdateFeeQuoterForUSDC(lggr, e.Chains[destChain], state.Chains[destChain], sourceChain, dstUSDC) require.NoError(t, err) // MockE2EUSDCTransmitter always mint 1, see MockE2EUSDCTransmitter.sol for more details @@ -178,7 +178,7 @@ func TestUSDCTokenTransfer(t *testing.T) { func mintAndAllow( t *testing.T, e deployment.Environment, - state ccdeploy.CCIPOnChainState, + state changeset.CCIPOnChainState, tkMap map[uint64][]*burn_mint_erc677.BurnMintERC677, ) { for chain, tokens := range tkMap { @@ -206,37 +206,37 @@ func mintAndAllow( func transferAndWaitForSuccess( t *testing.T, env deployment.Environment, - state ccdeploy.CCIPOnChainState, + state changeset.CCIPOnChainState, sourceChain, destChain uint64, tokens []router.ClientEVMTokenAmount, receiver common.Address, data []byte, ) { startBlocks := make(map[uint64]*uint64) - expectedSeqNum := make(map[ccdeploy.SourceDestPair]uint64) + expectedSeqNum := make(map[changeset.SourceDestPair]uint64) latesthdr, err := env.Chains[destChain].Client.HeaderByNumber(testcontext.Get(t), nil) require.NoError(t, err) block := latesthdr.Number.Uint64() startBlocks[destChain] = &block - msgSentEvent := ccdeploy.TestSendRequest(t, env, state, sourceChain, destChain, false, router.ClientEVM2AnyMessage{ + msgSentEvent := changeset.TestSendRequest(t, env, state, sourceChain, destChain, false, router.ClientEVM2AnyMessage{ Receiver: common.LeftPadBytes(receiver.Bytes(), 32), Data: data, TokenAmounts: tokens, FeeToken: common.HexToAddress("0x0"), ExtraArgs: nil, }) - expectedSeqNum[ccdeploy.SourceDestPair{ + expectedSeqNum[changeset.SourceDestPair{ SourceChainSelector: sourceChain, DestChainSelector: destChain, }] = msgSentEvent.SequenceNumber // Wait for all commit reports to land. - ccdeploy.ConfirmCommitForAllWithExpectedSeqNums(t, env, state, expectedSeqNum, startBlocks) + changeset.ConfirmCommitForAllWithExpectedSeqNums(t, env, state, expectedSeqNum, startBlocks) // Wait for all exec reports to land - ccdeploy.ConfirmExecWithSeqNrForAll(t, env, state, expectedSeqNum, startBlocks) + changeset.ConfirmExecWithSeqNrForAll(t, env, state, expectedSeqNum, startBlocks) } func waitForTheTokenBalance( diff --git a/integration-tests/smoke/fee_boosting_test.go b/integration-tests/smoke/fee_boosting_test.go index 9101fe04dc8..087715a80a2 100644 --- a/integration-tests/smoke/fee_boosting_test.go +++ b/integration-tests/smoke/fee_boosting_test.go @@ -10,7 +10,7 @@ import ( "golang.org/x/exp/maps" "github.com/smartcontractkit/chainlink/deployment" - ccdeploy "github.com/smartcontractkit/chainlink/deployment/ccip" + "github.com/smartcontractkit/chainlink/deployment/ccip/changeset" "github.com/smartcontractkit/chainlink/integration-tests/ccip-tests/testsetups" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" "github.com/smartcontractkit/chainlink/v2/core/logger" @@ -19,9 +19,9 @@ import ( type feeboostTestCase struct { t *testing.T sender []byte - deployedEnv ccdeploy.DeployedEnv - onchainState ccdeploy.CCIPOnChainState - initialPrices ccdeploy.InitialPrices + deployedEnv changeset.DeployedEnv + onchainState changeset.CCIPOnChainState + initialPrices changeset.InitialPrices priceFeedPrices priceFeedPrices sourceChain, destChain uint64 } @@ -33,13 +33,13 @@ type priceFeedPrices struct { // TODO: find a way to reuse the same test setup for all tests func Test_CCIPFeeBoosting(t *testing.T) { - setupTestEnv := func(t *testing.T, numChains int) (ccdeploy.DeployedEnv, ccdeploy.CCIPOnChainState, []uint64) { + setupTestEnv := func(t *testing.T, numChains int) (changeset.DeployedEnv, changeset.CCIPOnChainState, []uint64) { e, _, _ := testsetups.NewLocalDevEnvironment( t, logger.TestLogger(t), deployment.E18Mult(5), big.NewInt(9e8)) - state, err := ccdeploy.LoadOnchainState(e.Env) + state, err := changeset.LoadOnchainState(e.Env) require.NoError(t, err) allChainSelectors := maps.Keys(e.Env.Chains) @@ -54,10 +54,10 @@ func Test_CCIPFeeBoosting(t *testing.T) { sender: common.LeftPadBytes(e.Env.Chains[chains[0]].DeployerKey.From.Bytes(), 32), deployedEnv: e, onchainState: state, - initialPrices: ccdeploy.InitialPrices{ + initialPrices: changeset.InitialPrices{ LinkPrice: deployment.E18Mult(5), WethPrice: deployment.E18Mult(9), - GasPrice: ccdeploy.ToPackedFee(big.NewInt(1.8e11), big.NewInt(0)), + GasPrice: changeset.ToPackedFee(big.NewInt(1.8e11), big.NewInt(0)), }, priceFeedPrices: priceFeedPrices{ linkPrice: deployment.E18Mult(5), @@ -75,10 +75,10 @@ func Test_CCIPFeeBoosting(t *testing.T) { sender: common.LeftPadBytes(e.Env.Chains[chains[0]].DeployerKey.From.Bytes(), 32), deployedEnv: e, onchainState: state, - initialPrices: ccdeploy.InitialPrices{ + initialPrices: changeset.InitialPrices{ LinkPrice: deployment.E18Mult(5), WethPrice: deployment.E18Mult(9), - GasPrice: ccdeploy.ToPackedFee(big.NewInt(1.8e11), big.NewInt(0)), + GasPrice: changeset.ToPackedFee(big.NewInt(1.8e11), big.NewInt(0)), }, priceFeedPrices: priceFeedPrices{ linkPrice: big.NewInt(4.5e18), // decrease from 5e18 to 4.5e18 @@ -91,18 +91,18 @@ func Test_CCIPFeeBoosting(t *testing.T) { } func runFeeboostTestCase(tc feeboostTestCase) { - require.NoError(tc.t, ccdeploy.AddLane(tc.deployedEnv.Env, tc.onchainState, tc.sourceChain, tc.destChain, tc.initialPrices)) + require.NoError(tc.t, changeset.AddLane(tc.deployedEnv.Env, tc.onchainState, tc.sourceChain, tc.destChain, tc.initialPrices)) startBlocks := make(map[uint64]*uint64) - expectedSeqNum := make(map[ccdeploy.SourceDestPair]uint64) - msgSentEvent := ccdeploy.TestSendRequest(tc.t, tc.deployedEnv.Env, tc.onchainState, tc.sourceChain, tc.destChain, false, router.ClientEVM2AnyMessage{ + expectedSeqNum := make(map[changeset.SourceDestPair]uint64) + msgSentEvent := changeset.TestSendRequest(tc.t, tc.deployedEnv.Env, tc.onchainState, tc.sourceChain, tc.destChain, false, router.ClientEVM2AnyMessage{ Receiver: common.LeftPadBytes(tc.onchainState.Chains[tc.destChain].Receiver.Address().Bytes(), 32), Data: []byte("message that needs fee boosting"), TokenAmounts: nil, FeeToken: common.HexToAddress("0x0"), ExtraArgs: nil, }) - expectedSeqNum[ccdeploy.SourceDestPair{ + expectedSeqNum[changeset.SourceDestPair{ SourceChainSelector: tc.sourceChain, DestChainSelector: tc.destChain, }] = msgSentEvent.SequenceNumber @@ -112,8 +112,8 @@ func runFeeboostTestCase(tc feeboostTestCase) { replayBlocks := make(map[uint64]uint64) replayBlocks[tc.sourceChain] = 1 replayBlocks[tc.destChain] = 1 - ccdeploy.ReplayLogs(tc.t, tc.deployedEnv.Env.Offchain, replayBlocks) + changeset.ReplayLogs(tc.t, tc.deployedEnv.Env.Offchain, replayBlocks) - ccdeploy.ConfirmCommitForAllWithExpectedSeqNums(tc.t, tc.deployedEnv.Env, tc.onchainState, expectedSeqNum, startBlocks) - ccdeploy.ConfirmExecWithSeqNrForAll(tc.t, tc.deployedEnv.Env, tc.onchainState, expectedSeqNum, startBlocks) + changeset.ConfirmCommitForAllWithExpectedSeqNums(tc.t, tc.deployedEnv.Env, tc.onchainState, expectedSeqNum, startBlocks) + changeset.ConfirmExecWithSeqNrForAll(tc.t, tc.deployedEnv.Env, tc.onchainState, expectedSeqNum, startBlocks) }