Skip to content

Commit

Permalink
Move some files to internal
Browse files Browse the repository at this point in the history
  • Loading branch information
connorwstein committed Nov 20, 2024
1 parent 654f326 commit d8fc0dc
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 56 deletions.
9 changes: 4 additions & 5 deletions deployment/ccip/changeset/add_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"math/big"

ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"

"github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms"
Expand All @@ -19,7 +18,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,
Expand Down Expand Up @@ -77,7 +76,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
}
Expand All @@ -90,7 +89,7 @@ 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,
Expand Down Expand Up @@ -129,7 +128,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)
Expand Down
5 changes: 3 additions & 2 deletions deployment/ccip/changeset/add_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

"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"
Expand Down Expand Up @@ -171,12 +172,12 @@ func TestAddChainInbound(t *testing.T) {
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)
setCandidateForExecChangeset, err := internal.SetCandidatePluginChangeset(state, e.Env, nodes, deployment.XXXGenerateTestOCRSecrets(), e.HomeChainSel, e.FeedChainSel, newChain, tokenConfig, types.PluginTypeCCIPExec)
require.NoError(t, err)
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)
donPromoteChangeset, err := internal.PromoteAllCandidatesChangeset(state, e.HomeChainSel, newChain, nodes)
require.NoError(t, err)
ProcessChangeset(t, e.Env, donPromoteChangeset)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package changeset
package internal

import (
"fmt"
Expand All @@ -7,13 +7,14 @@ import (
"github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
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 CCIPOnChainState,
state changeset.CCIPOnChainState,
homeChainSel, newChainSel uint64,
nodes deployment.Nodes,
) (deployment.ChangesetOutput, error) {
Expand All @@ -27,7 +28,7 @@ func PromoteAllCandidatesChangeset(
return deployment.ChangesetOutput{}, err
}

prop, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
prop, err := changeset.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
ChainIdentifier: mcms.ChainIdentifier(homeChainSel),
Batch: promoteCandidateOps,
}}, "promoteCandidate for commit and execution", 0)
Expand All @@ -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 CCIPOnChainState,
state changeset.CCIPOnChainState,
e deployment.Environment,
nodes deployment.Nodes,
ocrSecrets deployment.OCRSecrets,
homeChainSel, feedChainSel, newChainSel uint64,
tokenConfig TokenConfig,
tokenConfig changeset.TokenConfig,
pluginType cctypes.PluginType,
) (deployment.ChangesetOutput, error) {
newDONArgs, err := BuildOCR3ConfigForCCIPHome(
newDONArgs, err := changeset.BuildOCR3ConfigForCCIPHome(
ocrSecrets,
state.Chains[newChainSel].OffRamp,
e.Chains[newChainSel],
Expand Down Expand Up @@ -81,7 +82,7 @@ func SetCandidatePluginChangeset(
return deployment.ChangesetOutput{}, err
}

prop, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
prop, err := changeset.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
ChainIdentifier: mcms.ChainIdentifier(homeChainSel),
Batch: setCandidateMCMSOps,
}}, "SetCandidate for execution", 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package changeset
package internal

import (
"fmt"
Expand All @@ -7,6 +7,7 @@ import (
"github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
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"
Expand All @@ -22,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 := changeset.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 := changeset.CCIPHomeABI.Pack(
"setCandidate",
donID,
pluginConfig.PluginType,
Expand All @@ -45,7 +46,7 @@ func SetCandidateOnExistingDon(
nodes.PeerIDs(),
[]capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{
{
CapabilityId: CCIPCapabilityID,
CapabilityId: changeset.CCIPCapabilityID,
Config: encodedSetCandidateCall,
},
},
Expand Down Expand Up @@ -77,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 := changeset.CCIPHomeABI.Pack(
"promoteCandidateAndRevokeActive",
donID,
pluginType,
Expand All @@ -94,7 +95,7 @@ func PromoteCandidateOp(donID uint32, pluginType uint8, capReg *capabilities_reg
nodes.PeerIDs(),
[]capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{
{
CapabilityId: CCIPCapabilityID,
CapabilityId: changeset.CCIPCapabilityID,
Config: encodedPromotionCall,
},
},
Expand All @@ -119,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 := changeset.DonIDForChain(capReg, ccipHome, chainSelector)
if err != nil {
return nil, fmt.Errorf("fetch don id for chain: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package changeset
package internal

import (
"testing"
Expand All @@ -8,6 +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"

cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
Expand All @@ -25,13 +26,13 @@ func TestActiveCandidate(t *testing.T) {
t.Skipf("to be enabled after latest cl-ccip is compatible")

lggr := logger.TestLogger(t)
tenv := NewMemoryEnvironmentWithJobsAndContracts(t, lggr, 3, 5)
tenv := changeset.NewMemoryEnvironmentWithJobsAndContracts(t, lggr, 3, 5)
e := tenv.Env
state, err := LoadOnchainState(tenv.Env)
state, err := changeset.LoadOnchainState(tenv.Env)
require.NoError(t, err)

// Add all lanes
require.NoError(t, 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.
Expand All @@ -45,7 +46,7 @@ func TestActiveCandidate(t *testing.T) {
require.NoError(t, err)
block := latesthdr.Number.Uint64()
startBlocks[dest] = &block
msgSentEvent := 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,
Expand All @@ -57,43 +58,43 @@ func TestActiveCandidate(t *testing.T) {
}

// Wait for all commit reports to land.
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 {
linkAddress := state.Chains[dest].LinkToken.Address()
feeQuoter := state.Chains[dest].FeeQuoter
timestampedPrice, err := feeQuoter.GetTokenPrice(nil, linkAddress)
require.NoError(t, err)
require.Equal(t, MockLinkPrice, timestampedPrice.Value)
require.Equal(t, changeset.MockLinkPrice, timestampedPrice.Value)
}

//Wait for all exec reports to land
ConfirmExecWithSeqNrForAll(t, e, state, expectedSeqNum, startBlocks)
changeset.ConfirmExecWithSeqNrForAll(t, e, state, expectedSeqNum, startBlocks)

// transfer ownership
TransferAllOwnership(t, state, tenv.HomeChainSel, e)
acceptOwnershipProposal, err := GenerateAcceptOwnershipProposal(state, tenv.HomeChainSel, e.AllChainSelectors())
acceptOwnershipProposal, err := changeset.GenerateAcceptOwnershipProposal(state, tenv.HomeChainSel, e.AllChainSelectors())
require.NoError(t, err)
acceptOwnershipExec := commonchangeset.SignProposal(t, e, acceptOwnershipProposal)
for _, sel := range e.AllChainSelectors() {
commonchangeset.ExecuteProposal(t, e, acceptOwnershipExec, state.Chains[sel].Timelock, sel)
}
// Apply the accept ownership proposal to all the chains.

err = ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 2)
err = changeset.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 := DonIDForChain(capReg, ccipHome, tenv.FeedChainSel)
donID, err := changeset.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 = LoadOnchainState(e)
state, err = changeset.LoadOnchainState(e)
require.NoError(t, err)

// delete a non-bootstrap node
Expand All @@ -113,8 +114,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 := NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds)
ocr3ConfigMap, err := BuildOCR3ConfigForCCIPHome(
tokenConfig := changeset.NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds)
ocr3ConfigMap, err := changeset.BuildOCR3ConfigForCCIPHome(
deployment.XXXGenerateTestOCRSecrets(),
state.Chains[tenv.FeedChainSel].OffRamp,
e.Chains[tenv.FeedChainSel],
Expand All @@ -134,7 +135,7 @@ func TestActiveCandidate(t *testing.T) {
nodes.NonBootstraps(),
)
require.NoError(t, err)
setCommitCandidateProposal, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
setCommitCandidateProposal, err := changeset.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel),
Batch: setCommitCandidateOp,
}}, "set new candidates on commit plugin", 0)
Expand All @@ -152,7 +153,7 @@ func TestActiveCandidate(t *testing.T) {
)
require.NoError(t, err)

setExecCandidateProposal, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
setExecCandidateProposal, err := changeset.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel),
Batch: setExecCandidateOp,
}}, "set new candidates on commit and exec plugins", 0)
Expand All @@ -168,7 +169,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 = ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 3)
err = changeset.ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 3)
require.NoError(t, err)
// [ACTIVE, CANDIDATE] done send successful transaction on active

Expand All @@ -179,7 +180,7 @@ func TestActiveCandidate(t *testing.T) {

promoteOps, err := PromoteAllCandidatesForChainOps(state.Chains[tenv.HomeChainSel].CapabilityRegistry, state.Chains[tenv.HomeChainSel].CCIPHome, tenv.FeedChainSel, nodes.NonBootstraps())
require.NoError(t, err)
promoteProposal, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
promoteProposal, err := changeset.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel),
Batch: promoteOps,
}}, "promote candidates and revoke actives", 0)
Expand All @@ -203,7 +204,7 @@ func TestActiveCandidate(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint32(8), donInfo.ConfigCount)

err = ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 4)
err = changeset.ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 4)
require.NoError(t, err)
// [NEW ACTIVE, NO CANDIDATE] done sending successful request
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package changeset
package internal

import (
"testing"
Expand Down
Loading

0 comments on commit d8fc0dc

Please sign in to comment.