-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CCIP- 4158 deploy home changeset (#15143)
* 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
Showing
11 changed files
with
334 additions
and
82 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.