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

Initialization for Crib #15501

Merged
merged 30 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
22fafc1
wip
0xAustinWang Dec 4, 2024
ea946d0
test crib integration flow
0xAustinWang Dec 4, 2024
2deda83
Merge branch 'develop' into aw/cribSetup
0xAustinWang Dec 4, 2024
b05777d
build failures
0xAustinWang Dec 4, 2024
26863f7
changes from ani's comments
0xAustinWang Dec 5, 2024
058bd6e
Merge branch 'develop' into aw/cribSetup
0xAustinWang Dec 5, 2024
6bf1bf6
some changes
0xAustinWang Dec 5, 2024
8b558da
revert isempty check
0xAustinWang Dec 5, 2024
848c49a
go lint and compare integers
0xAustinWang Dec 6, 2024
dc7744b
fix types in test
0xAustinWang Dec 6, 2024
1361cee
check for error if there's already a feeds manager
0xAustinWang Dec 6, 2024
6d799af
check if job distributors exist first
0xAustinWang Dec 9, 2024
5791b42
wip changes
0xAustinWang Dec 9, 2024
df1680c
add retries to consistently failing JD cals
0xAustinWang Dec 10, 2024
af23f93
update retries with static duration
0xAustinWang Dec 10, 2024
c42ac14
remove print statements
0xAustinWang Dec 10, 2024
72c5eed
Merge branch 'develop' into aw/cribSetup
0xAustinWang Dec 10, 2024
52585a6
fix compile error
scheibinger Dec 10, 2024
a05bc79
Merge branch 'develop' into aw/cribSetup
0xAustinWang Dec 10, 2024
50479b7
remove unnecessary mcms changes
0xAustinWang Dec 11, 2024
1083fd0
build issues
0xAustinWang Dec 11, 2024
63c8b1b
passing deployment
0xAustinWang Dec 11, 2024
0dd4fde
clean up code comments
0xAustinWang Dec 11, 2024
791c013
gomodtidy
0xAustinWang Dec 11, 2024
56b5f87
lint
0xAustinWang Dec 11, 2024
1713660
formatting strings
0xAustinWang Dec 11, 2024
a8d7cf9
use the common changeset utilities when deploying home chain as well
0xAustinWang Dec 11, 2024
030ab7a
compare nodes job distributors public key against the one we expect
0xAustinWang Dec 12, 2024
95cd43e
move state reader under deployment module
scheibinger Dec 12, 2024
8b31af9
add RPC type with internal and external rpcs
scheibinger Dec 12, 2024
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
4 changes: 3 additions & 1 deletion deployment/address_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ type AddressBook interface {
Remove(ab AddressBook) error
}

type AddressesByChain map[uint64]map[string]TypeAndVersion

type AddressBookMap struct {
addressesByChain map[uint64]map[string]TypeAndVersion
addressesByChain AddressesByChain
mtx sync.RWMutex
}

Expand Down
13 changes: 4 additions & 9 deletions deployment/ccip/changeset/cs_add_chain_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package changeset

import (
"math/big"
"testing"
"time"

Expand Down Expand Up @@ -51,13 +50,9 @@ func TestAddChainInbound(t *testing.T) {
require.NoError(t, err)
require.NoError(t, e.Env.ExistingAddresses.Merge(newAddresses))

cfg := commontypes.MCMSWithTimelockConfig{
Canceller: commonchangeset.SingleGroupMCMS(t),
Bypasser: commonchangeset.SingleGroupMCMS(t),
Proposer: commonchangeset.SingleGroupMCMS(t),
TimelockExecutors: e.Env.AllDeployerKeys(),
TimelockMinDelay: big.NewInt(0),
}
cfg, err := commonchangeset.CreateMCMSConfig(e.Env.AllDeployerKeys())
require.NoError(t, err)

out, err := commonchangeset.DeployMCMSWithTimelock(e.Env, map[uint64]commontypes.MCMSWithTimelockConfig{
initialDeploy[0]: cfg,
initialDeploy[1]: cfg,
Expand All @@ -72,7 +67,7 @@ func TestAddChainInbound(t *testing.T) {
for _, chain := range initialDeploy {
chainConfig[chain] = DefaultOCRParams(e.FeedChainSel, nil, nil)
}
err = deployCCIPContracts(e.Env, newAddresses, NewChainsConfig{
err = DeployCCIPContracts(e.Env, newAddresses, NewChainsConfig{
HomeChainSel: e.HomeChainSel,
FeedChainSel: e.FeedChainSel,
ChainConfigByChain: chainConfig,
Expand Down
4 changes: 2 additions & 2 deletions deployment/ccip/changeset/cs_deploy_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (c DeployChainContractsConfig) Validate() error {
return nil
}

// deployCCIPContracts assumes the following contracts are deployed:
// DeployCCIPContracts assumes the following contracts are deployed:
// - Capability registry
// - CCIP home
// - RMN home
Expand All @@ -74,7 +74,7 @@ func (c DeployChainContractsConfig) Validate() error {
// It then deploys the rest of the CCIP chain contracts to the selected chains
// registers the nodes with the capability registry and creates a DON for
// each new chain.
func deployCCIPContracts(
func DeployCCIPContracts(
e deployment.Environment,
ab deployment.AddressBook,
c NewChainsConfig) error {
Expand Down
10 changes: 2 additions & 8 deletions deployment/ccip/changeset/cs_deploy_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package changeset
import (
"encoding/json"
"fmt"
"math/big"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -51,13 +50,8 @@ func TestDeployChainContractsChangeset(t *testing.T) {

cfg := make(map[uint64]commontypes.MCMSWithTimelockConfig)
for _, chain := range e.AllChainSelectors() {
cfg[chain] = commontypes.MCMSWithTimelockConfig{
Canceller: commonchangeset.SingleGroupMCMS(t),
Bypasser: commonchangeset.SingleGroupMCMS(t),
Proposer: commonchangeset.SingleGroupMCMS(t),
TimelockExecutors: e.AllDeployerKeys(),
TimelockMinDelay: big.NewInt(0),
}
cfg[chain], err = commonchangeset.CreateMCMSConfig(e.AllDeployerKeys())
require.NoError(t, err)
}
output, err = commonchangeset.DeployMCMSWithTimelock(e, cfg)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions deployment/ccip/changeset/cs_home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func (c DeployHomeChainConfig) Validate() error {
return nil
}

// deployCapReg deploys the CapabilitiesRegistry contract if it is not already deployed
// DeployCapReg deploys the CapabilitiesRegistry contract if it is not already deployed
// and returns a deployment.ContractDeploy struct with the address and contract instance.
func deployCapReg(
func DeployCapReg(
AnieeG marked this conversation as resolved.
Show resolved Hide resolved
lggr logger.Logger,
state CCIPOnChainState,
ab deployment.AddressBook,
Expand Down Expand Up @@ -133,7 +133,7 @@ func deployHomeChain(
return nil, fmt.Errorf("failed to load onchain state: %w", err)
}
// Deploy CapabilitiesRegistry, CCIPHome, RMNHome
capReg, err := deployCapReg(lggr, state, ab, chain)
capReg, err := DeployCapReg(lggr, state, ab, chain)
if err != nil {
return nil, err
}
Expand Down
11 changes: 3 additions & 8 deletions deployment/ccip/changeset/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func DeployTestContracts(t *testing.T,
linkPrice *big.Int,
wethPrice *big.Int,
) deployment.CapabilityRegistryConfig {
capReg, err := deployCapReg(lggr,
capReg, err := DeployCapReg(lggr,
// deploying cap reg for the first time on a blank chain state
CCIPOnChainState{
Chains: make(map[uint64]CCIPChainState),
Expand Down Expand Up @@ -272,13 +272,8 @@ func NewMemoryEnvironmentWithJobsAndContracts(t *testing.T, lggr logger.Logger,
allChains := e.Env.AllChainSelectors()
mcmsCfg := make(map[uint64]commontypes.MCMSWithTimelockConfig)
for _, c := range e.Env.AllChainSelectors() {
mcmsCfg[c] = commontypes.MCMSWithTimelockConfig{
Canceller: commonchangeset.SingleGroupMCMS(t),
Bypasser: commonchangeset.SingleGroupMCMS(t),
Proposer: commonchangeset.SingleGroupMCMS(t),
TimelockExecutors: e.Env.AllDeployerKeys(),
TimelockMinDelay: big.NewInt(0),
}
mcmsCfg[c], err = commonchangeset.CreateMCMSConfig(e.Env.AllDeployerKeys())
require.NoError(t, err)
}
var usdcChains []uint64
if tCfg != nil && tCfg.IsUSDC {
Expand Down
24 changes: 11 additions & 13 deletions deployment/common/changeset/internal/mcms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package internal_test

import (
"encoding/json"
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -23,8 +22,10 @@ func TestDeployMCMSWithConfig(t *testing.T) {
chainsel.TEST_90000001.EvmChainID,
})
ab := deployment.NewMemoryAddressBook()
_, err := internal.DeployMCMSWithConfig(types.ProposerManyChainMultisig,
lggr, chains[chainsel.TEST_90000001.Selector], ab, changeset.SingleGroupMCMS(t))
m, err := changeset.SingleGroupMCMS()
require.NoError(t, err)
_, err = internal.DeployMCMSWithConfig(types.ProposerManyChainMultisig,
lggr, chains[chainsel.TEST_90000001.Selector], ab, m)
require.NoError(t, err)
}

Expand All @@ -34,17 +35,14 @@ func TestDeployMCMSWithTimelockContracts(t *testing.T) {
chainsel.TEST_90000001.EvmChainID,
})
ab := deployment.NewMemoryAddressBook()
_, err := internal.DeployMCMSWithTimelockContracts(lggr,
mcmsConfig, err := changeset.CreateMCMSConfig([]common.Address{
chains[chainsel.TEST_90000001.Selector].DeployerKey.From,
})
require.NoError(t, err)
_, err = internal.DeployMCMSWithTimelockContracts(lggr,
chains[chainsel.TEST_90000001.Selector],
ab, types.MCMSWithTimelockConfig{
Canceller: changeset.SingleGroupMCMS(t),
Bypasser: changeset.SingleGroupMCMS(t),
Proposer: changeset.SingleGroupMCMS(t),
TimelockExecutors: []common.Address{
chains[chainsel.TEST_90000001.Selector].DeployerKey.From,
},
TimelockMinDelay: big.NewInt(0),
})
ab,
mcmsConfig)
require.NoError(t, err)
addresses, err := ab.AddressesForChain(chainsel.TEST_90000001.Selector)
require.NoError(t, err)
Expand Down
33 changes: 30 additions & 3 deletions deployment/common/changeset/mcms_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"context"
"crypto/ecdsa"
commontypes "github.com/smartcontractkit/chainlink/deployment/common/types"
"math/big"
"testing"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -33,15 +35,40 @@ func init() {
TestXXXMCMSSigner = key
}

func SingleGroupMCMS(t *testing.T) config.Config {
func SingleGroupMCMS() (config.Config, error) {
publicKey := TestXXXMCMSSigner.Public().(*ecdsa.PublicKey)
// Convert the public key to an Ethereum address
address := crypto.PubkeyToAddress(*publicKey)
c, err := config.NewConfig(1, []common.Address{address}, []config.Config{})
require.NoError(t, err)
return *c

if err != nil {
return config.Config{}, err
}
return *c, nil
}

func CreateMCMSConfig(depKeys []common.Address) (commontypes.MCMSWithTimelockConfig, error) {
c, err := SingleGroupMCMS()
if err != nil {
return commontypes.MCMSWithTimelockConfig{}, err
}
b, err := SingleGroupMCMS()
if err != nil {
return commontypes.MCMSWithTimelockConfig{}, err
}
p, err := SingleGroupMCMS()
if err != nil {
return commontypes.MCMSWithTimelockConfig{}, err
}
return commontypes.MCMSWithTimelockConfig{
Canceller: c,
Bypasser: b,
Proposer: p,
TimelockExecutors: depKeys,
TimelockMinDelay: big.NewInt(0),
}, nil

}
func SignProposal(t *testing.T, env deployment.Environment, proposal *timelock.MCMSWithTimelockProposal) *mcms.Executor {
executorClients := make(map[mcms.ChainIdentifier]mcms.ContractDeployBackend)
for _, chain := range env.Chains {
Expand Down
158 changes: 158 additions & 0 deletions deployment/environment/crib/ccip_deployer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package crib

import (
"context"
"errors"
chainsel "github.com/smartcontractkit/chain-selectors"
jobv1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job"
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
commontypes "github.com/smartcontractkit/chainlink/deployment/common/types"
"golang.org/x/exp/maps"
"math/big"

"github.com/smartcontractkit/chainlink/deployment/environment/devenv"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
)

// DeployHomeChainContracts deploys the home chain contracts so that the chainlink nodes can be started with the CR address in Capabilities.ExternalRegistry
func DeployHomeChainContracts(lggr logger.Logger, envConfig devenv.EnvironmentConfig, homeChainSel uint64) (deployment.CapabilityRegistryConfig, deployment.AddressBook, error) {
chains, err := devenv.NewChains(lggr, envConfig.Chains)
if err != nil {
return deployment.CapabilityRegistryConfig{}, nil, err
}
ab := deployment.NewMemoryAddressBook()
capReg, err := changeset.DeployCapReg(lggr,
// deploying cap reg for the first time on a blank chain state
changeset.CCIPOnChainState{
Chains: make(map[uint64]changeset.CCIPChainState),
}, ab, chains[homeChainSel])
if err != nil {
return deployment.CapabilityRegistryConfig{}, nil, err
}
evmChainID, err := chainsel.ChainIdFromSelector(homeChainSel)
if err != nil {
return deployment.CapabilityRegistryConfig{}, nil, err
}
return deployment.CapabilityRegistryConfig{
NetworkType: relay.NetworkEVM,
EVMChainID: evmChainID,
Contract: capReg.Address,
}, ab, nil
}

func DeployCCIPAndAddLanes(lggr logger.Logger, envCfg devenv.EnvironmentConfig, homeChainSel, feedChainSel uint64, ab deployment.AddressBook) (DeployCCIPOutput, error) {
ctx := context.Background()
e, _, err := devenv.NewEnvironment(func() context.Context { return context.Background() }, lggr, envCfg)
if err != nil {
return DeployCCIPOutput{}, err
}
if e == nil {
return DeployCCIPOutput{}, errors.New("environment is nil")
}

_, err = changeset.DeployFeeds(lggr, ab, e.Chains[feedChainSel], big.NewInt(9000000), big.NewInt(9000000))
if err != nil {
return DeployCCIPOutput{}, err
}

e.ExistingAddresses = ab
tenv := changeset.DeployedEnv{
Env: *e,
HomeChainSel: homeChainSel,
FeedChainSel: feedChainSel,
}
chains := tenv.Env.AllChainSelectors()
out, err := changeset.DeployPrerequisites(tenv.Env, changeset.DeployPrerequisiteConfig{
ChainSelectors: chains,
})
if err != nil {
return DeployCCIPOutput{}, err
}
err = tenv.Env.ExistingAddresses.Merge(out.AddressBook)
if err != nil {
return DeployCCIPOutput{}, err
}

state, err := changeset.LoadOnchainState(tenv.Env)
if err != nil {
return DeployCCIPOutput{}, err
}
if state.Chains[tenv.HomeChainSel].LinkToken == nil {
return DeployCCIPOutput{}, errors.New("link token not deployed")
}

// Deploy contracts to new chain
cfg, err := commonchangeset.CreateMCMSConfig(tenv.Env.AllDeployerKeys())
if err != nil {
return DeployCCIPOutput{}, err
}
var mcmsConfigs = make(map[uint64]commontypes.MCMSWithTimelockConfig)
for _, chain := range chains {
mcmsConfigs[chain] = cfg
}
out, err = commonchangeset.DeployMCMSWithTimelock(tenv.Env, mcmsConfigs)
if err != nil {
return DeployCCIPOutput{}, err
}
err = tenv.Env.ExistingAddresses.Merge(out.AddressBook)
if err != nil {
return DeployCCIPOutput{}, err
}

chainConfig := make(map[uint64]changeset.CCIPOCRParams)
for _, chain := range chains {
chainConfig[chain] = changeset.DefaultOCRParams(tenv.FeedChainSel, nil, nil)
}
err = changeset.DeployCCIPContracts(tenv.Env, tenv.Env.ExistingAddresses, changeset.NewChainsConfig{
HomeChainSel: tenv.HomeChainSel,
FeedChainSel: tenv.FeedChainSel,
ChainConfigByChain: chainConfig,
OCRSecrets: deployment.XXXGenerateTestOCRSecrets(),
})
if err != nil {
return DeployCCIPOutput{}, err
}
// Get new state after migration.

state, err = changeset.LoadOnchainState(tenv.Env)
if err != nil {
return DeployCCIPOutput{}, err
}

out, err = changeset.CCIPCapabilityJobspec(tenv.Env, struct{}{})
if err != nil {
return DeployCCIPOutput{}, err
}
for nodeID, jobs := range out.JobSpecs {
for _, job := range jobs {
// Note these auto-accept
_, err := tenv.Env.Offchain.ProposeJob(ctx,
&jobv1.ProposeJobRequest{
NodeId: nodeID,
Spec: job,
})
if err != nil {
return DeployCCIPOutput{}, err
}
}
}

// Add all lanes
err = changeset.AddLanesForAll(tenv.Env, state)
if err != nil {
return DeployCCIPOutput{}, err
}

addresses, err := ab.Addresses()
if err != nil {
return DeployCCIPOutput{}, err
}
return DeployCCIPOutput{
AddressBook: *deployment.NewMemoryAddressBookFromMap(addresses),
NodeIDs: maps.Keys(out.JobSpecs),
}, err
}
Loading
Loading