Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
connorwstein committed Aug 21, 2024
1 parent 6ac05d7 commit 2c93e6a
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 53 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ require (
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/chain-selectors v1.0.21
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240816163757-48726fd8165f
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240820142424-1b2d9ea02c35
github.com/smartcontractkit/chainlink-common v0.2.1-0.20240717132349-ee5af9b79834
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240710121324-3ed288aa9b45
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240718160222-2dc0c8136bfa
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,8 @@ github.com/smartcontractkit/chain-selectors v1.0.21 h1:KCR9SA7PhOexaBzFieHoLv1Wo
github.com/smartcontractkit/chain-selectors v1.0.21/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.4 h1:iyW181JjKHLNMnDleI8umfIfVVlwC7+n5izbLSFgjw8=
github.com/smartcontractkit/chainlink-automation v1.0.4/go.mod h1:u4NbPZKJ5XiayfKHD/v3z3iflQWqvtdhj13jVZXj/cM=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240816163757-48726fd8165f h1:lQZBOjeYFpCdk0mGQUhbrJipd00tu49xK4zSijC/9Co=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240816163757-48726fd8165f/go.mod h1:/ZWraCBaDDgaIN1prixYcbVvIk/6HeED9+8zbWQ+TMo=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240820142424-1b2d9ea02c35 h1:35SN1dx03/J0xac0YKtJH9CyqQEsMqap9aBMpu+TQoM=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240820142424-1b2d9ea02c35/go.mod h1:xoO0vYi0LNn8QK23fvMVNvyIOgaLVTFgi5RprDsxK8M=
github.com/smartcontractkit/chainlink-common v0.2.1-0.20240717132349-ee5af9b79834 h1:pTf4xdcmiWBqWZ6rTy2RMTDBzhHk89VC1pM7jXKQztI=
github.com/smartcontractkit/chainlink-common v0.2.1-0.20240717132349-ee5af9b79834/go.mod h1:fh9eBbrReCmv31bfz52ENCAMa7nTKQbdhb2B3+S2VGo=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240710121324-3ed288aa9b45 h1:NBQLtqk8zsyY4qTJs+NElI3aDFTcAo83JHvqD04EvB0=
Expand Down
10 changes: 5 additions & 5 deletions integration-tests/deployment/ccip/add_lane.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func AddLane(e deployment.Environment, state CCIPOnChainState, from, to uint64)
tx, err := state.Chains[from].Router.ApplyRampUpdates(e.Chains[from].DeployerKey, []router.RouterOnRamp{
{
DestChainSelector: to,
OnRamp: state.Chains[from].EvmOnRampV160.Address(),
OnRamp: state.Chains[from].OnRamp.Address(),
},
}, []router.RouterOffRamp{}, []router.RouterOffRamp{})
if err := deployment.ConfirmIfNoError(e.Chains[from], tx, err); err != nil {
return err
}
tx, err = state.Chains[from].EvmOnRampV160.ApplyDestChainConfigUpdates(e.Chains[from].DeployerKey,
tx, err = state.Chains[from].OnRamp.ApplyDestChainConfigUpdates(e.Chains[from].DeployerKey,
[]onramp.OnRampDestChainConfigArgs{
{
DestChainSelector: to,
Expand Down Expand Up @@ -70,13 +70,13 @@ func AddLane(e deployment.Environment, state CCIPOnChainState, from, to uint64)
return err
}

tx, err = state.Chains[to].EvmOffRampV160.ApplySourceChainConfigUpdates(e.Chains[to].DeployerKey,
tx, err = state.Chains[to].OffRamp.ApplySourceChainConfigUpdates(e.Chains[to].DeployerKey,
[]offramp.OffRampSourceChainConfigArgs{
{
Router: state.Chains[to].Router.Address(),
SourceChainSelector: from,
IsEnabled: true,
OnRamp: common.LeftPadBytes(state.Chains[from].EvmOnRampV160.Address().Bytes(), 32),
OnRamp: common.LeftPadBytes(state.Chains[from].OnRamp.Address().Bytes(), 32),
},
})
if err := deployment.ConfirmIfNoError(e.Chains[to], tx, err); err != nil {
Expand All @@ -85,7 +85,7 @@ func AddLane(e deployment.Environment, state CCIPOnChainState, from, to uint64)
tx, err = state.Chains[to].Router.ApplyRampUpdates(e.Chains[to].DeployerKey, []router.RouterOnRamp{}, []router.RouterOffRamp{}, []router.RouterOffRamp{
{
SourceChainSelector: from,
OffRamp: state.Chains[to].EvmOffRampV160.Address(),
OffRamp: state.Chains[to].OffRamp.Address(),
},
})
return deployment.ConfirmIfNoError(e.Chains[to], tx, err)
Expand Down
36 changes: 36 additions & 0 deletions integration-tests/deployment/ccip/add_lane_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
package ccipdeployment

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/v2/core/logger"
)

// TestAddLane covers the workflow of adding a lane
// between existing supported chains in CCIP.
func TestAddLane(t *testing.T) {
e := NewEnvironmentWithCR(t, logger.TestLogger(t), 3)
// Here we have CR + nodes set up, but no CCIP contracts deployed.
state, err := LoadOnchainState(e.Env, e.Ab)
require.NoError(t, err)
// Set up CCIP contracts and a DON per chain.
ab, err := DeployCCIPContracts(e.Env, DeployCCIPContractConfig{
HomeChainSel: e.HomeChainSel,
CCIPOnChainState: state,
})
require.NoError(t, err)
require.NoError(t, ab.Merge(e.Ab))

// We expect no lanes available on any chain.
state, err = LoadOnchainState(e.Env, e.Ab)
require.NoError(t, err)
for _, chain := range state.Chains {
offRamps, err := chain.Router.GetOffRamps(nil)
require.NoError(t, err)
require.Len(t, offRamps, 0)
}

// Add one lane and send traffic.
//from, to := e.Env.AllChainSelectors()[0], e.Env.AllChainSelectors()[1]
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"

ccipdeployment "github.com/smartcontractkit/chainlink/integration-tests/deployment/ccip"
"github.com/smartcontractkit/chainlink/integration-tests/deployment/memory"

"github.com/smartcontractkit/chainlink/v2/core/logger"
)

func Test0002_InitialDeploy(t *testing.T) {
lggr := logger.TestLogger(t)
ctx := ccipdeployment.Context(t)
tenv := ccipdeployment.NewDeployedTestEnvironment(t, lggr)
tenv := ccipdeployment.NewEnvironmentWithCR(t, lggr, 3)
e := tenv.Env
nodes := tenv.Nodes
chains := e.Chains
Expand All @@ -48,7 +46,7 @@ func Test0002_InitialDeploy(t *testing.T) {
require.NoError(t, err)

// Ensure capreg logs are up to date.
require.NoError(t, ReplayAllLogs(nodes, chains))
require.NoError(t, ccipdeployment.ReplayAllLogs(nodes, chains))

// Apply the jobs.
for nodeID, jobs := range output.JobSpecs {
Expand All @@ -67,7 +65,7 @@ func Test0002_InitialDeploy(t *testing.T) {
time.Sleep(30 * time.Second)

// Ensure job related logs are up to date.
require.NoError(t, ReplayAllLogs(nodes, chains))
require.NoError(t, ccipdeployment.ReplayAllLogs(nodes, chains))

// Send a request from every router
// Add all lanes
Expand Down Expand Up @@ -118,6 +116,7 @@ func Test0002_InitialDeploy(t *testing.T) {
}

// Wait for all commit reports to land.
cStart := time.Now()
var wg sync.WaitGroup
for src, srcChain := range e.Chains {
for dest, dstChain := range e.Chains {
Expand All @@ -129,11 +128,12 @@ func Test0002_InitialDeploy(t *testing.T) {
wg.Add(1)
go func(src, dest uint64) {
defer wg.Done()
waitForCommitWithInterval(t, srcChain, dstChain, state.Chains[dest].EvmOffRampV160, ccipocr3.SeqNumRange{1, 1})
waitForCommitWithInterval(t, srcChain, dstChain, state.Chains[dest].OffRamp, ccipocr3.SeqNumRange{1, 1})
}(src, dest)
}
}
wg.Wait()
cEnd := time.Now()

// Wait for all exec reports to land
for src, srcChain := range e.Chains {
Expand All @@ -146,26 +146,17 @@ func Test0002_InitialDeploy(t *testing.T) {
wg.Add(1)
go func(src, dest deployment.Chain) {
defer wg.Done()
waitForExecWithSeqNr(t, src, dest, state.Chains[dest.Selector].EvmOffRampV160, 1)
waitForExecWithSeqNr(t, src, dest, state.Chains[dest.Selector].OffRamp, 1)
}(srcChain, dstChain)
}
}
wg.Wait()

eEnd := time.Now()
t.Log("Commit time:", cEnd.Sub(cStart))
t.Log("Exec time:", eEnd.Sub(cEnd))
// TODO: Apply the proposal.
}

func ReplayAllLogs(nodes map[string]memory.Node, chains map[uint64]deployment.Chain) error {
for _, node := range nodes {
for sel := range chains {
if err := node.ReplayLogs(map[uint64]uint64{sel: 1}); err != nil {
return err
}
}
}
return nil
}

func waitForCommitWithInterval(
t *testing.T,
src deployment.Chain,
Expand Down
7 changes: 4 additions & 3 deletions integration-tests/deployment/ccip/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,22 @@ func DeployCCIPContracts(e deployment.Environment, c DeployCCIPContractConfig) (
// Enable ramps on price registry/nonce manager
tx, err := chainState.PriceRegistry.ApplyAuthorizedCallerUpdates(chain.DeployerKey, price_registry.AuthorizedCallersAuthorizedCallerArgs{
// TODO: We enable the deployer initially to set prices
AddedCallers: []common.Address{chainState.EvmOffRampV160.Address(), chain.DeployerKey.From},
AddedCallers: []common.Address{chainState.OffRamp.Address(), chain.DeployerKey.From},
})
if err := deployment.ConfirmIfNoError(chain, tx, err); err != nil {
e.Logger.Errorw("Failed to confirm price registry authorized caller update", "err", err)
return ab, err
}

tx, err = chainState.NonceManager.ApplyAuthorizedCallerUpdates(chain.DeployerKey, nonce_manager.AuthorizedCallersAuthorizedCallerArgs{
AddedCallers: []common.Address{chainState.EvmOffRampV160.Address(), chainState.EvmOnRampV160.Address()},
AddedCallers: []common.Address{chainState.OffRamp.Address(), chainState.OnRamp.Address()},
})
if err := deployment.ConfirmIfNoError(chain, tx, err); err != nil {
e.Logger.Errorw("Failed to update nonce manager with ramps", "err", err)
return ab, err
}

// TODO: Do we want to extract this?
// Add chain config for each chain.
_, err = AddChainConfig(e.Logger,
e.Chains[c.HomeChainSel],
Expand All @@ -187,7 +188,7 @@ func DeployCCIPContracts(e deployment.Environment, c DeployCCIPContractConfig) (
cr,
c.Chains[c.HomeChainSel].CapabilityRegistry,
c.Chains[c.HomeChainSel].CCIPConfig,
chainState.EvmOffRampV160,
chainState.OffRamp,
chain,
e.Chains[c.HomeChainSel],
uint8(len(nodes)/3),
Expand Down
36 changes: 27 additions & 9 deletions integration-tests/deployment/ccip/deploy_home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
"fmt"
"sort"
"time"

Expand Down Expand Up @@ -377,7 +378,7 @@ func AddDON(
}

for _, pluginType := range []cctypes.PluginType{cctypes.PluginTypeCCIPCommit, cctypes.PluginTypeCCIPExec} {
_, err = offRamp.LatestConfigDetails(&bind.CallOpts{
ocrConfig, err := offRamp.LatestConfigDetails(&bind.CallOpts{
Context: context.Background(),
}, uint8(pluginType))
if err != nil {
Expand All @@ -386,14 +387,31 @@ func AddDON(
}
// TODO: assertions to be done as part of full state
// resprentation validation CCIP-3047
//require.Equalf(t, offrampOCR3Configs[pluginType].ConfigDigest, ocrConfig.ConfigInfo.ConfigDigest, "%s OCR3 config digest mismatch", pluginType.String())
//require.Equalf(t, offrampOCR3Configs[pluginType].F, ocrConfig.ConfigInfo.F, "%s OCR3 config F mismatch", pluginType.String())
//require.Equalf(t, offrampOCR3Configs[pluginType].IsSignatureVerificationEnabled, ocrConfig.ConfigInfo.IsSignatureVerificationEnabled, "%s OCR3 config signature verification mismatch", pluginType.String())
//if pluginType == cctypes.PluginTypeCCIPCommit {
// // only commit will set signers, exec doesn't need them.
// require.Equalf(t, offrampOCR3Configs[pluginType].Signers, ocrConfig.Signers, "%s OCR3 config signers mismatch", pluginType.String())
//}
//require.Equalf(t, offrampOCR3Configs[pluginType].TransmittersByEVMChainID, ocrConfig.TransmittersByEVMChainID, "%s OCR3 config transmitters mismatch", pluginType.String())
if offrampOCR3Configs[pluginType].ConfigDigest != ocrConfig.ConfigInfo.ConfigDigest {
return fmt.Errorf("%s OCR3 config digest mismatch", pluginType.String())
}
if offrampOCR3Configs[pluginType].F != ocrConfig.ConfigInfo.F {
return fmt.Errorf("%s OCR3 config F mismatch", pluginType.String())
}
if offrampOCR3Configs[pluginType].IsSignatureVerificationEnabled != ocrConfig.ConfigInfo.IsSignatureVerificationEnabled {
return fmt.Errorf("%s OCR3 config signature verification mismatch", pluginType.String())
}
if pluginType == cctypes.PluginTypeCCIPCommit {
// only commit will set signers, exec doesn't need them.
for i, signer := range offrampOCR3Configs[pluginType].Signers {
if !bytes.Equal(signer.Bytes(), ocrConfig.Signers[i].Bytes()) {
return fmt.Errorf("%s OCR3 config signer mismatch", pluginType.String())
}
}
//if offrampOCR3Configs[pluginType].Signers != ocrConfig.Signers {
// return fmt.Errorf("%s OCR3 config signers mismatch", pluginType.String())
//}
}
for i, transmitter := range offrampOCR3Configs[pluginType].Transmitters {
if !bytes.Equal(transmitter.Bytes(), ocrConfig.Transmitters[i].Bytes()) {
return fmt.Errorf("%s OCR3 config transmitter mismatch", pluginType.String())
}
}
}

lggr.Infof("set ocr3 config on the offramp, signers: %+v, transmitters: %+v", signerAddresses, transmitterAddresses)
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/deployment/ccip/propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func GenerateAcceptOwnershipProposal(
return deployment.Proposal{}, err
}

txData, err := state.Chains[sel].EvmOnRampV160.AcceptOwnership(SimTransactOpts())
txData, err := state.Chains[sel].OnRamp.AcceptOwnership(SimTransactOpts())
if err != nil {
return deployment.Proposal{}, err
}
Expand All @@ -49,7 +49,7 @@ func GenerateAcceptOwnershipProposal(
ChainId: big.NewInt(int64(evmID)),
MultiSig: state.Chains[sel].McmsAddr,
Nonce: opCount,
To: state.Chains[sel].EvmOnRampV160.Address(),
To: state.Chains[sel].OnRamp.Address(),
Value: big.NewInt(0),
Data: txData.Data(),
})
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/deployment/ccip/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
)

type CCIPChainState struct {
EvmOnRampV160 *onramp.OnRamp
EvmOffRampV160 *offramp.OffRamp
OnRamp *onramp.OnRamp
OffRamp *offramp.OffRamp
PriceRegistry *price_registry.PriceRegistry
ArmProxy *rmn_proxy_contract.RMNProxyContract
NonceManager *nonce_manager.NonceManager
Expand Down Expand Up @@ -201,13 +201,13 @@ func LoadChainState(chain deployment.Chain, addresses map[string]deployment.Type
if err != nil {
return state, err
}
state.EvmOnRampV160 = onRampC
state.OnRamp = onRampC
case deployment.NewTypeAndVersion(OffRamp, deployment.Version1_6_0_dev).String():
offRamp, err := offramp.NewOffRamp(common.HexToAddress(address), chain.Client)
if err != nil {
return state, err
}
state.EvmOffRampV160 = offRamp
state.OffRamp = offRamp
case deployment.NewTypeAndVersion(ARMProxy, deployment.Version1_0_0).String():
armProxy, err := rmn_proxy_contract.NewRMNProxyContract(common.HexToAddress(address), chain.Client)
if err != nil {
Expand Down
43 changes: 41 additions & 2 deletions integration-tests/deployment/ccip/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package ccipdeployment
import (
"context"
"testing"
"time"

chainsel "github.com/smartcontractkit/chain-selectors"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

jobv1 "github.com/smartcontractkit/chainlink/integration-tests/deployment/jd/job/v1"

"github.com/smartcontractkit/chainlink/integration-tests/deployment"
"github.com/smartcontractkit/chainlink/integration-tests/deployment/memory"

Expand Down Expand Up @@ -40,9 +43,9 @@ type DeployedTestEnvironment struct {

// NewDeployedEnvironment creates a new CCIP environment
// with capreg and nodes set up.
func NewDeployedTestEnvironment(t *testing.T, lggr logger.Logger) DeployedTestEnvironment {
func NewEnvironmentWithCR(t *testing.T, lggr logger.Logger, numChains int) DeployedTestEnvironment {
ctx := Context(t)
chains := memory.NewMemoryChains(t, 3)
chains := memory.NewMemoryChains(t, numChains)
homeChainSel := uint64(0)
homeChainEVM := uint64(0)
// Say first chain is home chain.
Expand Down Expand Up @@ -70,3 +73,39 @@ func NewDeployedTestEnvironment(t *testing.T, lggr logger.Logger) DeployedTestEn
Nodes: nodes,
}
}

func NewEnvironmentWithCRAndJobs(t *testing.T, lggr logger.Logger, numChains int) DeployedTestEnvironment {
ctx := Context(t)
e := NewEnvironmentWithCR(t, lggr, numChains)
jbs, err := NewCCIPJobSpecs(e.Env.NodeIDs, e.Env.Offchain)
require.NoError(t, err)
for nodeID, jobs := range jbs {
for _, job := range jobs {
// Note these auto-accept
_, err := e.Env.Offchain.ProposeJob(ctx,
&jobv1.ProposeJobRequest{
NodeId: nodeID,
Spec: job,
})
require.NoError(t, err)
}
}
// Wait for plugins to register filters?
// TODO: Investigate how to avoid.
time.Sleep(30 * time.Second)

// Ensure job related logs are up to date.
require.NoError(t, ReplayAllLogs(e.Nodes, e.Env.Chains))
return e
}

func ReplayAllLogs(nodes map[string]memory.Node, chains map[uint64]deployment.Chain) error {
for _, node := range nodes {
for sel := range chains {
if err := node.ReplayLogs(map[uint64]uint64{sel: 1}); err != nil {
return err
}
}
}
return nil
}
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/smartcontractkit/ccip-owner-contracts v0.0.0-20240808195812-ae0378684685
github.com/smartcontractkit/chain-selectors v1.0.21
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240816163757-48726fd8165f
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240820142424-1b2d9ea02c35
github.com/smartcontractkit/chainlink-common v0.2.1-0.20240717132349-ee5af9b79834
github.com/smartcontractkit/chainlink-testing-framework v1.33.0
github.com/smartcontractkit/chainlink-testing-framework/grafana v0.0.0-20240405215812-5a72bc9af239
Expand Down
Loading

0 comments on commit 2c93e6a

Please sign in to comment.