Skip to content

Commit

Permalink
CCIP- 4158 deploy home changeset (#15143)
Browse files Browse the repository at this point in the history
* capreg changeset

* add a test

* changes

* review comments

* deploy home chain changeset

* some comments

* fix test

* fix smoke

* remove

* review comments

* test fix

* updates

* fix
  • Loading branch information
AnieeG authored Nov 8, 2024
1 parent 816dcf8 commit 1e84f96
Show file tree
Hide file tree
Showing 11 changed files with 334 additions and 82 deletions.
30 changes: 0 additions & 30 deletions deployment/ccip/changeset/cap_reg.go

This file was deleted.

77 changes: 77 additions & 0 deletions deployment/ccip/changeset/home_chain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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)
}
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)
if err != nil {
env.Logger.Errorw("Failed to deploy cap reg", "err", err, "addresses", env.ExistingAddresses)
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
}

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 len(c.NodeOperators) == 0 {
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 len(c.NodeP2PIDsPerNodeOpAdmin[nop.Name]) == 0 {
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

0 comments on commit 1e84f96

Please sign in to comment.