Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCIP- 4158 deploy home changeset #15143

Merged
merged 20 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions deployment/ccip/changeset/cap_reg.go

This file was deleted.

78 changes: 78 additions & 0 deletions deployment/ccip/changeset/home_chain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package changeset

import (
"fmt"

"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"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"
)

var _ deployment.ChangeSet = DeployHomeChain

// DeployHomeChain is a separate changeset because it is a standalone deployment performed once in home chain for the entire CCIP deployment.
func DeployHomeChain(env deployment.Environment, config interface{}) (deployment.ChangesetOutput, error) {
cfg, ok := config.(DeployHomeChainConfig)
if !ok {
return deployment.ChangesetOutput{}, deployment.ErrInvalidConfig
}
err := cfg.Validate()
if err != nil {
return deployment.ChangesetOutput{}, errors.Wrapf(deployment.ErrInvalidConfig, "%v", err)
}
homeChainSel := cfg.HomeChainSel
// Note we also deploy the cap reg.
ab := deployment.NewMemoryAddressBook()
_, err = ccipdeployment.DeployHomeChain(env.Logger, ab, env.Chains[homeChainSel], cfg.RMNStaticConfig, cfg.RMNDynamicConfig, cfg.NodeOperators, cfg.NodeP2PIDsPerNodeOpAdmin)
if err != nil {
env.Logger.Errorw("Failed to deploy cap reg", "err", err, "addresses", ab)
return deployment.ChangesetOutput{}, err
}

return deployment.ChangesetOutput{
Proposals: []timelock.MCMSWithTimelockProposal{},
AddressBook: ab,
JobSpecs: nil,
}, nil
}

type DeployHomeChainConfig struct {
HomeChainSel uint64
RMNStaticConfig rmn_home.RMNHomeStaticConfig
RMNDynamicConfig rmn_home.RMNHomeDynamicConfig
NodeOperators []capabilities_registry.CapabilitiesRegistryNodeOperator
NodeP2PIDsPerNodeOpAdmin map[string][][32]byte
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit/ i've been using p2pkey.PeerID when i want peer ids and converting to [32]byte for the contract when needed specifically for the contract.

have utils we can share/promote if you want to do the same

}

func (c DeployHomeChainConfig) Validate() error {
if c.HomeChainSel == 0 {
return fmt.Errorf("home chain selector must be set")
}
if c.RMNDynamicConfig.OffchainConfig == nil {
return fmt.Errorf("offchain config for RMNHomeDynamicConfig must be set")
}
if c.RMNStaticConfig.OffchainConfig == nil {
return fmt.Errorf("offchain config for RMNHomeStaticConfig must be set")
}
if c.NodeOperators == nil || len(c.NodeOperators) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, but len(slice) == 0 already covers nil slices, so c.NodeOperators == nil is redundant, right?

https://go.dev/play/p/kkDCe54H5Xv

return fmt.Errorf("node operators must be set")
}
for _, nop := range c.NodeOperators {
if nop.Admin == (common.Address{}) {
return fmt.Errorf("node operator admin address must be set")
}
if nop.Name == "" {
return fmt.Errorf("node operator name must be set")
}
if c.NodeP2PIDsPerNodeOpAdmin[nop.Name] == nil || len(c.NodeP2PIDsPerNodeOpAdmin[nop.Name]) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

return fmt.Errorf("node operator %s must have node p2p ids provided", nop.Name)
}
}

return nil
}
63 changes: 63 additions & 0 deletions deployment/ccip/changeset/home_chain_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package changeset

import (
"testing"

chainsel "github.com/smartcontractkit/chain-selectors"
"github.com/stretchr/testify/require"
"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"
)

func TestDeployHomeChain(t *testing.T) {
lggr := logger.TestLogger(t)
e := memory.NewMemoryEnvironment(t, lggr, zapcore.InfoLevel, memory.MemoryEnvironmentConfig{
Bootstraps: 1,
Chains: 2,
Nodes: 4,
})
homeChainSel := e.AllChainSelectors()[0]
nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain)
require.NoError(t, err)
p2pIds := nodes.NonBootstraps().PeerIDs()
homeChainCfg := DeployHomeChainConfig{
HomeChainSel: homeChainSel,
RMNStaticConfig: ccdeploy.NewTestRMNStaticConfig(),
RMNDynamicConfig: ccdeploy.NewTestRMNDynamicConfig(),
NodeOperators: ccdeploy.NewTestNodeOperator(e.Chains[homeChainSel].DeployerKey.From),
NodeP2PIDsPerNodeOpAdmin: map[string][][32]byte{
"NodeOperator": p2pIds,
},
}
output, err := DeployHomeChain(e, homeChainCfg)
require.NoError(t, err)
require.NoError(t, e.ExistingAddresses.Merge(output.AddressBook))
state, err := ccdeploy.LoadOnchainState(e)
require.NoError(t, err)
require.NotNil(t, state.Chains[homeChainSel].CapabilityRegistry)
require.NotNil(t, state.Chains[homeChainSel].CCIPHome)
require.NotNil(t, state.Chains[homeChainSel].RMNHome)
snap, err := state.View([]uint64{homeChainSel})
require.NoError(t, err)
chainid, err := chainsel.ChainIdFromSelector(homeChainSel)
require.NoError(t, err)
chainName, err := chainsel.NameFromChainId(chainid)
require.NoError(t, err)
_, ok := snap[chainName]
require.True(t, ok)
capRegSnap, ok := snap[chainName].CapabilityRegistry[state.Chains[homeChainSel].CapabilityRegistry.Address().String()]
require.True(t, ok)
require.NotNil(t, capRegSnap)
require.Equal(t, capRegSnap.Nops, []v1_0.NopView{
{
Admin: e.Chains[homeChainSel].DeployerKey.From,
Name: "NodeOperator",
},
})
require.Len(t, capRegSnap.Nodes, len(p2pIds))
}
10 changes: 1 addition & 9 deletions deployment/ccip/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
owner_helpers "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers"

"github.com/smartcontractkit/chainlink-common/pkg/logger"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/registry_module_owner_custom"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_home"
Expand Down Expand Up @@ -187,15 +188,6 @@ func DeployCCIPContracts(e deployment.Environment, ab deployment.AddressBook, c
return fmt.Errorf("ccip home address mismatch")
}

// Signal to CR that our nodes support CCIP capability.
if err := AddNodes(
e.Logger,
capReg,
e.Chains[c.HomeChainSel],
nodes.NonBootstraps().PeerIDs(),
); err != nil {
return err
}
rmnHome := existingState.Chains[c.HomeChainSel].RMNHome
if rmnHome == nil {
e.Logger.Errorw("Failed to get rmn home", "err", err)
Expand Down
Loading
Loading