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

Simplify new chain config #15478

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 2 additions & 38 deletions deployment/ccip/changeset/accept_ownership_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package changeset

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

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink/deployment"
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
commontypes "github.com/smartcontractkit/chainlink/deployment/common/types"

"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"
Expand All @@ -21,48 +19,14 @@ import (
)

func Test_NewAcceptOwnershipChangeset(t *testing.T) {
e := NewMemoryEnvironmentWithJobs(t, logger.TestLogger(t), 2, 4)
e := NewMemoryEnvironmentWithJobsAndContracts(t, logger.TestLogger(t), 2, 4, &TestConfigs{})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive by test simplification

state, err := LoadOnchainState(e.Env)
require.NoError(t, err)

allChains := maps.Keys(e.Env.Chains)
source := allChains[0]
dest := allChains[1]

newAddresses := deployment.NewMemoryAddressBook()
err = deployPrerequisiteChainContracts(e.Env, newAddresses, allChains, nil)
require.NoError(t, err)
require.NoError(t, e.Env.ExistingAddresses.Merge(newAddresses))

mcmConfig := commontypes.MCMSWithTimelockConfig{
Canceller: commonchangeset.SingleGroupMCMS(t),
Bypasser: commonchangeset.SingleGroupMCMS(t),
Proposer: commonchangeset.SingleGroupMCMS(t),
TimelockExecutors: e.Env.AllDeployerKeys(),
TimelockMinDelay: big.NewInt(0),
}
out, err := commonchangeset.DeployMCMSWithTimelock(e.Env, map[uint64]commontypes.MCMSWithTimelockConfig{
source: mcmConfig,
dest: mcmConfig,
})
require.NoError(t, err)
require.NoError(t, e.Env.ExistingAddresses.Merge(out.AddressBook))
newAddresses = deployment.NewMemoryAddressBook()
tokenConfig := NewTestTokenConfig(state.Chains[e.FeedChainSel].USDFeeds)
ocrParams := make(map[uint64]CCIPOCRParams)
for _, chain := range allChains {
ocrParams[chain] = DefaultOCRParams(e.FeedChainSel, nil)
}
err = deployCCIPContracts(e.Env, newAddresses, NewChainsConfig{
HomeChainSel: e.HomeChainSel,
FeedChainSel: e.FeedChainSel,
ChainsToDeploy: allChains,
TokenConfig: tokenConfig,
OCRSecrets: deployment.XXXGenerateTestOCRSecrets(),
OCRParams: ocrParams,
})
require.NoError(t, err)

// at this point we have the initial deploys done, now we need to transfer ownership
// to the timelock contract
state, err = LoadOnchainState(e.Env)
Expand Down
1 change: 1 addition & 0 deletions deployment/ccip/changeset/active_candidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func SetCandidatePluginChangeset(
ccipOCRParams := DefaultOCRParams(
feedChainSel,
tokenConfig.GetTokenInfo(e.Logger, state.Chains[newChainSel].LinkToken, state.Chains[newChainSel].Weth9),
nil,
)
newDONArgs, err := internal.BuildOCR3ConfigForCCIPHome(
ocrSecrets,
Expand Down
1 change: 1 addition & 0 deletions deployment/ccip/changeset/active_candidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func TestActiveCandidate(t *testing.T) {
ccipOCRParams := DefaultOCRParams(
tenv.FeedChainSel,
tokenConfig.GetTokenInfo(e.Logger, state.Chains[tenv.FeedChainSel].LinkToken, state.Chains[tenv.FeedChainSel].Weth9),
nil,
)
ocr3ConfigMap, err := internal.BuildOCR3ConfigForCCIPHome(
deployment.XXXGenerateTestOCRSecrets(),
Expand Down
3 changes: 3 additions & 0 deletions deployment/ccip/changeset/add_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/big"

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

"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal"
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"
Expand Down Expand Up @@ -119,6 +120,8 @@ func AddDonAndSetCandidateChangeset(
ccipOCRParams := DefaultOCRParams(
feedChainSel,
tokenConfig.GetTokenInfo(e.Logger, state.Chains[newChainSel].LinkToken, state.Chains[newChainSel].Weth9),
// TODO: Need USDC support.
nil,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a ticket for that?

)
newDONArgs, err := internal.BuildOCR3ConfigForCCIPHome(
ocrSecrets,
Expand Down
14 changes: 9 additions & 5 deletions deployment/ccip/changeset/add_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers"

"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal"
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
commontypes "github.com/smartcontractkit/chainlink/deployment/common/types"
Expand Down Expand Up @@ -61,12 +62,15 @@ func TestAddChainInbound(t *testing.T) {
newAddresses = deployment.NewMemoryAddressBook()
tokenConfig := NewTestTokenConfig(state.Chains[e.FeedChainSel].USDFeeds)

chainConfig := make(map[uint64]CCIPOCRParams)
for _, chain := range initialDeploy {
chainConfig[chain] = DefaultOCRParams(e.FeedChainSel, nil, nil)
}
err = deployCCIPContracts(e.Env, newAddresses, NewChainsConfig{
HomeChainSel: e.HomeChainSel,
FeedChainSel: e.FeedChainSel,
ChainsToDeploy: initialDeploy,
TokenConfig: tokenConfig,
OCRSecrets: deployment.XXXGenerateTestOCRSecrets(),
HomeChainSel: e.HomeChainSel,
FeedChainSel: e.FeedChainSel,
ChainConfigByChain: chainConfig,
OCRSecrets: deployment.XXXGenerateTestOCRSecrets(),
})
require.NoError(t, err)

Expand Down
28 changes: 3 additions & 25 deletions deployment/ccip/changeset/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"golang.org/x/sync/errgroup"

cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"

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

"github.com/smartcontractkit/chainlink/deployment"
Expand Down Expand Up @@ -372,16 +370,12 @@ func configureChain(
return fmt.Errorf("rmn home not found")
}

for _, chainSel := range c.ChainsToDeploy {
for chainSel, chainConfig := range c.ChainConfigByChain {
chain, _ := e.Chains[chainSel]
chainState, ok := existingState.Chains[chain.Selector]
if !ok {
return fmt.Errorf("chain state not found for chain %d", chain.Selector)
}
ocrParams, ok := c.OCRParams[chain.Selector]
if !ok {
return fmt.Errorf("OCR params not found for chain %d", chain.Selector)
}
if chainState.OffRamp == nil {
return fmt.Errorf("off ramp not found for chain %d", chain.Selector)
}
Expand All @@ -394,10 +388,6 @@ func configureChain(
if err != nil {
return err
}
if enabled, ok := c.USDCConfig.EnabledChainMap()[chainSel]; ok && enabled {
ocrParams.ExecuteOffChainConfig.TokenDataObservers = c.USDCConfig.ToTokenDataObserverConfig()
}
ocrParams.CommitOffChainConfig.PriceFeedChainSelector = cciptypes.ChainSelector(c.FeedChainSel)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think much better to just have the full configuration as input and not mutate the config inside here

// For each chain, we create a DON on the home chain (2 OCR instances)
if err := addDON(
e.Logger,
Expand All @@ -409,7 +399,7 @@ func configureChain(
chain,
e.Chains[c.HomeChainSel],
nodes.NonBootstraps(),
ocrParams,
chainConfig,
); err != nil {
e.Logger.Errorw("Failed to add DON", "err", err)
return err
Expand All @@ -432,7 +422,7 @@ func deployCCIPContracts(
e deployment.Environment,
ab deployment.AddressBook,
c NewChainsConfig) error {
err := deployChainContractsForChains(e, ab, c.HomeChainSel, c.ChainsToDeploy)
err := deployChainContractsForChains(e, ab, c.HomeChainSel, c.Chains())
if err != nil {
e.Logger.Errorw("Failed to deploy chain contracts", "err", err)
return err
Expand All @@ -442,18 +432,6 @@ func deployCCIPContracts(
e.Logger.Errorw("Failed to merge address book", "err", err)
return err
}
state, err := LoadOnchainState(e)
if err != nil {
e.Logger.Errorw("Failed to load existing onchain state", "err", err)
return err
}

ocrParams := make(map[uint64]CCIPOCRParams)
for _, chain := range c.ChainsToDeploy {
tokenInfo := c.TokenConfig.GetTokenInfo(e.Logger, state.Chains[chain].LinkToken, state.Chains[chain].Weth9)
ocrParams[chain] = DefaultOCRParams(c.FeedChainSel, tokenInfo)
}
c.OCRParams = ocrParams
err = configureChain(e, c)
if err != nil {
e.Logger.Errorw("Failed to add chain", "err", err)
Expand Down
2 changes: 1 addition & 1 deletion deployment/ccip/changeset/deploy_home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func AddChainConfig(
chainSelector uint64,
p2pIDs [][32]byte,
) (ccip_home.CCIPHomeChainConfigArgs, error) {
// First Add ChainConfig that includes all p2pIDs as readers
// First Add CCIPOCRParams that includes all p2pIDs as readers
encodedExtraChainConfig, err := chainconfig.EncodeChainConfig(chainconfig.ChainConfig{
GasPriceDeviationPPB: ccipocr3.NewBigIntFromInt64(1000),
DAGasPriceDeviationPPB: ccipocr3.NewBigIntFromInt64(0),
Expand Down
Loading
Loading