-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Changes from 16 commits
b514a28
14cae84
3a801dc
9172a96
3954203
49c7c9b
4ff47c7
1e3b351
3ace0f2
0689ea2
db836d3
dc7a24b
e375e77
cefbeac
1cfc842
394e1f7
5bb2917
9c58a25
e933453
703feb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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 | ||
} | ||
|
||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, but |
||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} |
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)) | ||
} |
There was a problem hiding this comment.
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