Skip to content

Commit

Permalink
Get building
Browse files Browse the repository at this point in the history
  • Loading branch information
connorwstein committed Nov 20, 2024
1 parent d8fc0dc commit edb4eb9
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package changeset

import (
"fmt"
Expand All @@ -7,14 +7,13 @@ 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 changeset.CCIPOnChainState,
state CCIPOnChainState,
homeChainSel, newChainSel uint64,
nodes deployment.Nodes,
) (deployment.ChangesetOutput, error) {
Expand All @@ -28,7 +27,7 @@ func PromoteAllCandidatesChangeset(
return deployment.ChangesetOutput{}, err
}

prop, err := changeset.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
prop, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
ChainIdentifier: mcms.ChainIdentifier(homeChainSel),
Batch: promoteCandidateOps,
}}, "promoteCandidate for commit and execution", 0)
Expand All @@ -44,15 +43,15 @@ func PromoteAllCandidatesChangeset(

// SetCandidateExecPluginProposal calls setCandidate on the CCIPHome for setting up OCR3 exec Plugin config for the new chain.
func SetCandidatePluginChangeset(
state changeset.CCIPOnChainState,
state CCIPOnChainState,
e deployment.Environment,
nodes deployment.Nodes,
ocrSecrets deployment.OCRSecrets,
homeChainSel, feedChainSel, newChainSel uint64,
tokenConfig changeset.TokenConfig,
tokenConfig TokenConfig,
pluginType cctypes.PluginType,
) (deployment.ChangesetOutput, error) {
newDONArgs, err := changeset.BuildOCR3ConfigForCCIPHome(
newDONArgs, err := BuildOCR3ConfigForCCIPHome(
ocrSecrets,
state.Chains[newChainSel].OffRamp,
e.Chains[newChainSel],
Expand Down Expand Up @@ -82,7 +81,7 @@ func SetCandidatePluginChangeset(
return deployment.ChangesetOutput{}, err
}

prop, err := changeset.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
prop, err := 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 internal
package changeset

import (
"fmt"
Expand All @@ -7,7 +7,6 @@ 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 @@ -23,12 +22,12 @@ func SetCandidateOnExistingDon(
nodes deployment.Nodes,
) ([]mcms.Operation, error) {
// fetch DON ID for the chain
donID, err := changeset.DonIDForChain(capReg, ccipHome, chainSelector)
donID, err := 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 := changeset.CCIPHomeABI.Pack(
encodedSetCandidateCall, err := CCIPHomeABI.Pack(
"setCandidate",
donID,
pluginConfig.PluginType,
Expand All @@ -46,7 +45,7 @@ func SetCandidateOnExistingDon(
nodes.PeerIDs(),
[]capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{
{
CapabilityId: changeset.CCIPCapabilityID,
CapabilityId: CCIPCapabilityID,
Config: encodedSetCandidateCall,
},
},
Expand Down Expand Up @@ -78,7 +77,7 @@ func PromoteCandidateOp(donID uint32, pluginType uint8, capReg *capabilities_reg
}
fmt.Printf("commit candidate digest after setCandidate: %x\n", allConfigs.CandidateConfig.ConfigDigest)

encodedPromotionCall, err := changeset.CCIPHomeABI.Pack(
encodedPromotionCall, err := CCIPHomeABI.Pack(
"promoteCandidateAndRevokeActive",
donID,
pluginType,
Expand All @@ -95,7 +94,7 @@ func PromoteCandidateOp(donID uint32, pluginType uint8, capReg *capabilities_reg
nodes.PeerIDs(),
[]capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{
{
CapabilityId: changeset.CCIPCapabilityID,
CapabilityId: CCIPCapabilityID,
Config: encodedPromotionCall,
},
},
Expand All @@ -120,7 +119,7 @@ func PromoteAllCandidatesForChainOps(
nodes deployment.Nodes,
) ([]mcms.Operation, error) {
// fetch DON ID for the chain
donID, err := changeset.DonIDForChain(capReg, ccipHome, chainSelector)
donID, err := 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 internal
package changeset

import (
"testing"
Expand All @@ -8,8 +8,6 @@ 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 @@ -26,13 +24,13 @@ func TestActiveCandidate(t *testing.T) {
t.Skipf("to be enabled after latest cl-ccip is compatible")

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

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

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

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

// transfer ownership
TransferAllOwnership(t, state, tenv.HomeChainSel, e)
acceptOwnershipProposal, err := changeset.GenerateAcceptOwnershipProposal(state, tenv.HomeChainSel, e.AllChainSelectors())
acceptOwnershipProposal, err := 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 = changeset.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 := changeset.DonIDForChain(capReg, ccipHome, tenv.FeedChainSel)
donID, err := 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 = changeset.LoadOnchainState(e)
state, err = LoadOnchainState(e)
require.NoError(t, err)

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

setExecCandidateProposal, err := changeset.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)
Expand All @@ -169,7 +167,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 = changeset.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

Expand All @@ -180,7 +178,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 := changeset.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
promoteProposal, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel),
Batch: promoteOps,
}}, "promote candidates and revoke actives", 0)
Expand All @@ -204,7 +202,7 @@ func TestActiveCandidate(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint32(8), donInfo.ConfigCount)

err = changeset.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
}
5 changes: 2 additions & 3 deletions deployment/ccip/changeset/add_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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 @@ -172,12 +171,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 := internal.SetCandidatePluginChangeset(state, e.Env, nodes, deployment.XXXGenerateTestOCRSecrets(), e.HomeChainSel, e.FeedChainSel, newChain, tokenConfig, types.PluginTypeCCIPExec)
setCandidateForExecChangeset, err := 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 := internal.PromoteAllCandidatesChangeset(state, e.HomeChainSel, newChain, nodes)
donPromoteChangeset, err := PromoteAllCandidatesChangeset(state, e.HomeChainSel, newChain, nodes)
require.NoError(t, err)
ProcessChangeset(t, e.Env, donPromoteChangeset)

Expand Down
5 changes: 2 additions & 3 deletions deployment/ccip/changeset/add_lane.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/ethereum/go-ethereum/common"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccipevm"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp"

Expand All @@ -28,11 +27,11 @@ var DefaultInitialPrices = InitialPrices{
GasPrice: ToPackedFee(big.NewInt(8e14), big.NewInt(0)),
}

func AddLaneWithDefaultPrices(e deployment.Environment, state ccipdeployment.CCIPOnChainState, from, to uint64) error {
func AddLaneWithDefaultPrices(e deployment.Environment, state CCIPOnChainState, from, to uint64) error {
return AddLane(e, state, from, to, DefaultInitialPrices)
}

func AddLane(e deployment.Environment, state ccipdeployment.CCIPOnChainState, from, to uint64, initialPrices InitialPrices) error {
func AddLane(e deployment.Environment, state CCIPOnChainState, from, to uint64, initialPrices InitialPrices) error {
// TODO: Batch
tx, err := state.Chains[from].Router.ApplyRampUpdates(e.Chains[from].DeployerKey, []router.RouterOnRamp{
{
Expand Down
3 changes: 1 addition & 2 deletions deployment/ccip/changeset/deploy_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit edb4eb9

Please sign in to comment.