-
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 chain contract changeset (#15294)
* initial deploy chain * more updates * rename * fix DeployChainContracts
- Loading branch information
Showing
10 changed files
with
265 additions
and
63 deletions.
There are no files selected for viewing
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,44 @@ | ||
package changeset | ||
|
||
import ( | ||
"fmt" | ||
|
||
"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, c.MCMSCfg) | ||
if err != nil { | ||
env.Logger.Errorw("Failed to deploy CCIP contracts", "err", err, "newAddresses", newAddresses) | ||
return deployment.ChangesetOutput{AddressBook: newAddresses}, deployment.MaybeDataErr(err) | ||
} | ||
return deployment.ChangesetOutput{ | ||
Proposals: []timelock.MCMSWithTimelockProposal{}, | ||
AddressBook: newAddresses, | ||
JobSpecs: nil, | ||
}, nil | ||
} | ||
|
||
type DeployChainContractsConfig struct { | ||
ChainSelectors []uint64 | ||
HomeChainSelector uint64 | ||
MCMSCfg ccipdeployment.MCMSConfig | ||
} | ||
|
||
func (c DeployChainContractsConfig) Validate() error { | ||
for _, cs := range c.ChainSelectors { | ||
if err := deployment.IsValidChainSelector(cs); err != nil { | ||
return fmt.Errorf("invalid chain selector: %d - %w", cs, err) | ||
} | ||
} | ||
if err := deployment.IsValidChainSelector(c.HomeChainSelector); err != nil { | ||
return fmt.Errorf("invalid home chain selector: %d - %w", c.HomeChainSelector, err) | ||
} | ||
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,78 @@ | ||
package changeset | ||
|
||
import ( | ||
"testing" | ||
|
||
"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/environment/memory" | ||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
) | ||
|
||
func TestDeployChainContractsChangeset(t *testing.T) { | ||
lggr := logger.TestLogger(t) | ||
e := memory.NewMemoryEnvironment(t, lggr, zapcore.InfoLevel, memory.MemoryEnvironmentConfig{ | ||
Bootstraps: 1, | ||
Chains: 2, | ||
Nodes: 4, | ||
}) | ||
selectors := e.AllChainSelectors() | ||
homeChainSel := selectors[0] | ||
nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) | ||
require.NoError(t, err) | ||
p2pIds := nodes.NonBootstraps().PeerIDs() | ||
// deploy home chain | ||
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)) | ||
|
||
// deploy pre-requisites | ||
prerequisites, err := DeployPrerequisites(e, DeployPrerequisiteConfig{ | ||
ChainSelectors: selectors, | ||
}) | ||
require.NoError(t, err) | ||
require.NoError(t, e.ExistingAddresses.Merge(prerequisites.AddressBook)) | ||
|
||
// deploy ccip chain contracts | ||
output, err = DeployChainContracts(e, DeployChainContractsConfig{ | ||
ChainSelectors: selectors, | ||
HomeChainSelector: homeChainSel, | ||
MCMSCfg: ccdeploy.NewTestMCMSConfig(t, e), | ||
}) | ||
require.NoError(t, err) | ||
require.NoError(t, e.ExistingAddresses.Merge(output.AddressBook)) | ||
|
||
// load onchain state | ||
state, err := ccdeploy.LoadOnchainState(e) | ||
require.NoError(t, err) | ||
|
||
// verify all contracts populated | ||
require.NotNil(t, state.Chains[homeChainSel].CapabilityRegistry) | ||
require.NotNil(t, state.Chains[homeChainSel].CCIPHome) | ||
require.NotNil(t, state.Chains[homeChainSel].RMNHome) | ||
for _, sel := range selectors { | ||
require.NotNil(t, state.Chains[sel].LinkToken) | ||
require.NotNil(t, state.Chains[sel].Weth9) | ||
require.NotNil(t, state.Chains[sel].TokenAdminRegistry) | ||
require.NotNil(t, state.Chains[sel].RegistryModule) | ||
require.NotNil(t, state.Chains[sel].Router) | ||
require.NotNil(t, state.Chains[sel].RMNRemote) | ||
require.NotNil(t, state.Chains[sel].TestRouter) | ||
require.NotNil(t, state.Chains[sel].NonceManager) | ||
require.NotNil(t, state.Chains[sel].FeeQuoter) | ||
require.NotNil(t, state.Chains[sel].OffRamp) | ||
require.NotNil(t, state.Chains[sel].OnRamp) | ||
} | ||
} |
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
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,21 @@ | ||
package changeset | ||
|
||
import ( | ||
"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" | ||
) | ||
|
||
func Jobspec(env deployment.Environment, _ any) (deployment.ChangesetOutput, error) { | ||
js, err := ccipdeployment.NewCCIPJobSpecs(env.NodeIDs, env.Offchain) | ||
if err != nil { | ||
return deployment.ChangesetOutput{}, errors.Wrapf(err, "failed to create job specs") | ||
} | ||
return deployment.ChangesetOutput{ | ||
Proposals: []timelock.MCMSWithTimelockProposal{}, | ||
AddressBook: deployment.NewMemoryAddressBook(), | ||
JobSpecs: js, | ||
}, 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,35 @@ | ||
package changeset | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap/zapcore" | ||
|
||
"github.com/smartcontractkit/chainlink/deployment" | ||
"github.com/smartcontractkit/chainlink/deployment/environment/memory" | ||
ccip "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/validate" | ||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
) | ||
|
||
func TestJobSpecChangeset(t *testing.T) { | ||
lggr := logger.TestLogger(t) | ||
e := memory.NewMemoryEnvironment(t, lggr, zapcore.InfoLevel, memory.MemoryEnvironmentConfig{ | ||
Chains: 1, | ||
Nodes: 4, | ||
}) | ||
output, err := Jobspec(e, nil) | ||
require.NoError(t, err) | ||
require.NotNil(t, output.JobSpecs) | ||
nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) | ||
require.NoError(t, err) | ||
for _, node := range nodes { | ||
jobs, exists := output.JobSpecs[node.NodeID] | ||
require.True(t, exists) | ||
require.NotNil(t, jobs) | ||
for _, job := range jobs { | ||
_, err = ccip.ValidatedCCIPSpec(job) | ||
require.NoError(t, err) | ||
} | ||
} | ||
} |
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
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
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.