Skip to content

Commit

Permalink
more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG committed Nov 20, 2024
1 parent 7fba91d commit b53d58a
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 116 deletions.
2 changes: 1 addition & 1 deletion deployment/ccip/changeset/active_candidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestActiveCandidate(t *testing.T) {
t.Skipf("to be enabled after latest cl-ccip is compatible")

lggr := logger.TestLogger(t)
tenv := NewMemoryEnvironmentWithJobsAndContracts(t, lggr, 3, 5)
tenv := NewMemoryEnvironmentWithJobsAndContracts(t, lggr, 3, 5, false)
e := tenv.Env
state, err := LoadOnchainState(tenv.Env)
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion deployment/ccip/changeset/add_lane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

commonutils "github.com/smartcontractkit/chainlink-common/pkg/utils"
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
Expand All @@ -20,7 +21,7 @@ import (
func TestAddLane(t *testing.T) {
t.Parallel()
// We add more chains to the chainlink nodes than the number of chains where CCIP is deployed.
e := NewMemoryEnvironmentWithJobsAndContracts(t, logger.TestLogger(t), 2, 4)
e := NewMemoryEnvironmentWithJobsAndContracts(t, logger.TestLogger(t), 2, 4, false)
// Here we have CR + nodes set up, but no CCIP contracts deployed.
state, err := LoadOnchainState(e.Env)
require.NoError(t, err)
Expand Down
10 changes: 8 additions & 2 deletions deployment/ccip/changeset/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/smartcontractkit/chainlink-ccip/pluginconfig"
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal"

"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal"

Expand Down Expand Up @@ -469,6 +468,11 @@ func DeployCCIPContracts(
e.Logger.Errorw("Failed to deploy chain contracts", "err", err)
return err
}
err = e.ExistingAddresses.Merge(ab)
if err != nil {
e.Logger.Errorw("Failed to merge address book", "err", err)
return err
}
err = ConfigureChain(e, c)
if err != nil {
e.Logger.Errorw("Failed to add chain", "err", err)
Expand Down Expand Up @@ -501,7 +505,9 @@ func DeployChainContractsForChains(
return err
}
if cr != internal.CCIPCapabilityID {
return fmt.Errorf("capability registry does not support CCIP %s %s", hexutil.Encode(cr[:]), hexutil.Encode(internal.CCIPCapabilityID[:]))
return fmt.Errorf("unexpected mismatch between calculated ccip capability id (%s) and expected ccip capability id constant (%s)",
hexutil.Encode(cr[:]),
hexutil.Encode(internal.CCIPCapabilityID[:]))
}
capability, err := capReg.GetCapability(nil, internal.CCIPCapabilityID)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions deployment/ccip/changeset/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import (

func TestDeployCCIPContracts(t *testing.T) {
lggr := logger.TestLogger(t)
e := NewMemoryEnvironmentWithJobsAndContracts(t, lggr,
2,
4,
)
e := NewMemoryEnvironmentWithJobsAndContracts(t, lggr, 2, 4, false)
// Deploy all the CCIP contracts.
state, err := LoadOnchainState(e.Env)
require.NoError(t, err)
Expand Down
28 changes: 0 additions & 28 deletions deployment/ccip/changeset/initial_deploy.go

This file was deleted.

60 changes: 2 additions & 58 deletions deployment/ccip/changeset/initial_deploy_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package changeset

import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"

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"

"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"
"github.com/smartcontractkit/chainlink/deployment"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand All @@ -21,61 +15,11 @@ import (

func TestInitialDeploy(t *testing.T) {
lggr := logger.TestLogger(t)
ctx := Context(t)
tenv := NewMemoryEnvironment(t, lggr, 3, 4, MockLinkPrice, MockWethPrice)
tenv := NewMemoryEnvironmentWithJobsAndContracts(t, lggr, 3, 4, false)
e := tenv.Env

state, err := LoadOnchainState(tenv.Env)
require.NoError(t, err)
output, err := DeployPrerequisites(e, DeployPrerequisiteConfig{
ChainSelectors: tenv.Env.AllChainSelectors(),
})
require.NoError(t, err)
require.NoError(t, tenv.Env.ExistingAddresses.Merge(output.AddressBook))

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),
}
}
output, err = commonchangeset.DeployMCMSWithTimelock(e, cfg)
require.NoError(t, err)
require.NoError(t, e.ExistingAddresses.Merge(output.AddressBook))

output, err = InitialDeploy(tenv.Env, DeployCCIPContractConfig{
HomeChainSel: tenv.HomeChainSel,
FeedChainSel: tenv.FeedChainSel,
ChainsToDeploy: tenv.Env.AllChainSelectors(),
TokenConfig: NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds),
OCRSecrets: deployment.XXXGenerateTestOCRSecrets(),
})
require.NoError(t, err)
// Get new state after migration.
require.NoError(t, tenv.Env.ExistingAddresses.Merge(output.AddressBook))
state, err = LoadOnchainState(e)
state, err := LoadOnchainState(e)
require.NoError(t, err)
require.NotNil(t, state.Chains[tenv.HomeChainSel].LinkToken)
// Ensure capreg logs are up to date.
ReplayLogs(t, e.Offchain, tenv.ReplayBlocks)

// Apply the jobs.
for nodeID, jobs := range output.JobSpecs {
for _, job := range jobs {
// Note these auto-accept
_, err := e.Offchain.ProposeJob(ctx,
&jobv1.ProposeJobRequest{
NodeId: nodeID,
Spec: job,
})
require.NoError(t, err)
}
}

// Add all lanes
require.NoError(t, AddLanesForAll(e, state))
// Need to keep track of the block number for each chain so that event subscription can be done from that block.
Expand Down
4 changes: 3 additions & 1 deletion deployment/ccip/changeset/jobspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/smartcontractkit/chainlink/deployment"
)

var _ deployment.ChangeSet[any] = CCIPCapabilityJobspec

// CCIPCapabilityJobspec returns the job specs for the CCIP capability.
// The caller needs to propose these job specs to the offchain system.
func CCIPCapabilityJobspec(env deployment.Environment, _ any) (deployment.ChangesetOutput, error) {
Expand All @@ -16,7 +18,7 @@ func CCIPCapabilityJobspec(env deployment.Environment, _ any) (deployment.Change
}
return deployment.ChangesetOutput{
Proposals: []timelock.MCMSWithTimelockProposal{},
AddressBook: deployment.NewMemoryAddressBook(),
AddressBook: nil,
JobSpecs: js,
}, nil
}
60 changes: 44 additions & 16 deletions deployment/ccip/changeset/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,9 @@ func mockAttestationResponse() *httptest.Server {
return server
}

func NewMemoryEnvironmentWithJobsAndContracts(t *testing.T, lggr logger.Logger, numChains int, numNodes int) DeployedEnv {
func NewMemoryEnvironmentWithJobsAndContracts(t *testing.T, lggr logger.Logger, numChains int, numNodes int, isUSDC bool) DeployedEnv {
var err error
e := NewMemoryEnvironment(t, lggr, numChains, numNodes, MockLinkPrice, MockWethPrice)
e.SetupJobs(t)
allChains := e.Env.AllChainSelectors()
cfg := commontypes.MCMSWithTimelockConfig{
Canceller: commonchangeset.SingleGroupMCMS(t),
Expand All @@ -260,13 +259,17 @@ func NewMemoryEnvironmentWithJobsAndContracts(t *testing.T, lggr logger.Logger,
for _, c := range e.Env.AllChainSelectors() {
mcmsCfg[c] = cfg
}
var usdcChains []uint64
if isUSDC {
usdcChains = allChains
}
// Need to deploy prerequisites first so that we can for the CCIP contracts.
cs01 := []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(DeployPrerequisites),
Config: DeployPrerequisiteConfig{
ChainSelectors: allChains,
USDCEnabledChainSelectors: allChains,
USDCEnabledChainSelectors: usdcChains,
},
},
{
Expand All @@ -283,7 +286,7 @@ func NewMemoryEnvironmentWithJobsAndContracts(t *testing.T, lggr logger.Logger,
tokenConfig := NewTestTokenConfig(state.Chains[e.FeedChainSel].USDFeeds)
USDCCCTPConfig := make(map[cciptypes.ChainSelector]pluginconfig.USDCCCTPTokenConfig)
timelocksPerChain := make(map[uint64]*gethwrappers.RBACTimelock)
for _, chain := range allChains {
for _, chain := range usdcChains {
require.NotNil(t, state.Chains[chain].MockUSDCTokenMessenger)
require.NotNil(t, state.Chains[chain].MockUSDCTransmitter)
require.NotNil(t, state.Chains[chain].USDCTokenPool)
Expand All @@ -293,10 +296,17 @@ func NewMemoryEnvironmentWithJobsAndContracts(t *testing.T, lggr logger.Logger,
}
timelocksPerChain[chain] = state.Chains[chain].Timelock
}

server := mockAttestationResponse()
defer server.Close()
endpoint := server.URL
var usdcCfg USDCAttestationConfig
if isUSDC {
server := mockAttestationResponse()
defer server.Close()
endpoint := server.URL
usdcCfg = USDCAttestationConfig{
API: endpoint,
APITimeout: commonconfig.MustNewDuration(time.Second),
APIInterval: commonconfig.MustNewDuration(500 * time.Millisecond),
}
}

// Deploy second set of changesets to deploy and configure the CCIP contracts.
cs02 := []commonchangeset.ChangesetApplication{
Expand All @@ -312,24 +322,42 @@ func NewMemoryEnvironmentWithJobsAndContracts(t *testing.T, lggr logger.Logger,
Config: DeployCCIPContractConfig{
HomeChainSel: e.HomeChainSel,
FeedChainSel: e.FeedChainSel,
ChainsToDeploy: e.Env.AllChainSelectors(),
ChainsToDeploy: allChains,
TokenConfig: tokenConfig,
OCRSecrets: deployment.XXXGenerateTestOCRSecrets(),
USDCConfig: USDCConfig{
EnabledChains: allChains,
USDCAttestationConfig: USDCAttestationConfig{
API: endpoint,
APITimeout: commonconfig.MustNewDuration(time.Second),
APIInterval: commonconfig.MustNewDuration(500 * time.Millisecond),
},
CCTPTokenConfig: USDCCCTPConfig,
EnabledChains: usdcChains,
USDCAttestationConfig: usdcCfg,
CCTPTokenConfig: USDCCCTPConfig,
},
},
},
{
Changeset: commonchangeset.WrapChangeSet(CCIPCapabilityJobspec),
},
}

e.Env, err = commonchangeset.ApplyChangesets(context.Background(), e.Env, timelocksPerChain, cs02)
require.NoError(t, err)

state, err = LoadOnchainState(e.Env)
require.NoError(t, err)
require.NotNil(t, state.Chains[e.HomeChainSel].CapabilityRegistry)
require.NotNil(t, state.Chains[e.HomeChainSel].CCIPHome)
require.NotNil(t, state.Chains[e.HomeChainSel].RMNHome)
for _, chain := range allChains {
require.NotNil(t, state.Chains[chain].LinkToken)
require.NotNil(t, state.Chains[chain].Weth9)
require.NotNil(t, state.Chains[chain].TokenAdminRegistry)
require.NotNil(t, state.Chains[chain].RegistryModule)
require.NotNil(t, state.Chains[chain].Router)
require.NotNil(t, state.Chains[chain].RMNRemote)
require.NotNil(t, state.Chains[chain].TestRouter)
require.NotNil(t, state.Chains[chain].NonceManager)
require.NotNil(t, state.Chains[chain].FeeQuoter)
require.NotNil(t, state.Chains[chain].OffRamp)
require.NotNil(t, state.Chains[chain].OnRamp)
}
return e
}

Expand Down
15 changes: 10 additions & 5 deletions deployment/common/changeset/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ type ChangesetApplication struct {

func WrapChangeSet[C any](fn deployment.ChangeSet[C]) func(e deployment.Environment, config any) (deployment.ChangesetOutput, error) {
return func(e deployment.Environment, config any) (deployment.ChangesetOutput, error) {
c, ok := config.(C)
if !ok {
return deployment.ChangesetOutput{}, fmt.Errorf("invalid config type, expected %T", c)
var zeroC C
if config != nil {
c, ok := config.(C)
if !ok {
return deployment.ChangesetOutput{}, fmt.Errorf("invalid config type, expected %T", c)
}
return fn(e, config.(C))
}
return fn(e, c)

return fn(e, zeroC)
}
}

Expand All @@ -47,7 +52,7 @@ func ApplyChangesets(ctx context.Context, e deployment.Environment, timelocksPer
for nodeID, jobs := range out.JobSpecs {
for _, job := range jobs {
// Note these auto-accept
_, err := e.Offchain.ProposeJob(ctx,
_, err := currentEnv.Offchain.ProposeJob(ctx,
&jobv1.ProposeJobRequest{
NodeId: nodeID,
Spec: job,
Expand Down

0 comments on commit b53d58a

Please sign in to comment.