From 5f14bf09452442a21bb1cf8e44ea3c3352572961 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Mon, 9 Dec 2024 17:47:49 -0800 Subject: [PATCH 1/8] remove deployCCIPContracts --- .../ccip/changeset/cs_add_chain_test.go | 15 ++++++++- deployment/ccip/changeset/cs_deploy_chain.go | 32 ------------------- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/deployment/ccip/changeset/cs_add_chain_test.go b/deployment/ccip/changeset/cs_add_chain_test.go index c8d872236c2..2873b3bf613 100644 --- a/deployment/ccip/changeset/cs_add_chain_test.go +++ b/deployment/ccip/changeset/cs_add_chain_test.go @@ -80,10 +80,23 @@ func TestAddChainInbound(t *testing.T) { for _, chain := range initialDeploy { chainConfig[chain] = DefaultOCRParams(e.FeedChainSel, nil, nil) } - err = deployCCIPContracts(e.Env, newAddresses, NewChainsConfig{ + newChainCfg := NewChainsConfig{ HomeChainSel: e.HomeChainSel, FeedChainSel: e.FeedChainSel, ChainConfigByChain: chainConfig, + } + e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, nil, []commonchangeset.ChangesetApplication{ + { + Changeset: commonchangeset.WrapChangeSet(DeployChainContracts), + Config: DeployChainContractsConfig{ + ChainSelectors: newChainCfg.Chains(), + HomeChainSelector: newChainCfg.HomeChainSel, + }, + }, + { + Changeset: commonchangeset.WrapChangeSet(ConfigureNewChains), + Config: newChainCfg, + }, }) require.NoError(t, err) diff --git a/deployment/ccip/changeset/cs_deploy_chain.go b/deployment/ccip/changeset/cs_deploy_chain.go index e2762b27578..de6e4b5f466 100644 --- a/deployment/ccip/changeset/cs_deploy_chain.go +++ b/deployment/ccip/changeset/cs_deploy_chain.go @@ -65,38 +65,6 @@ func (c DeployChainContractsConfig) Validate() error { return nil } -// deployCCIPContracts assumes the following contracts are deployed: -// - Capability registry -// - CCIP home -// - RMN home -// - Fee tokens on all chains. -// and present in ExistingAddressBook. -// 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( - e deployment.Environment, - ab deployment.AddressBook, - c NewChainsConfig) error { - err := deployChainContractsForChains(e, ab, c.HomeChainSel, c.Chains()) - if err != nil { - 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) - return err - } - - return nil -} - func deployChainContractsForChains( e deployment.Environment, ab deployment.AddressBook, From 20032b26ccf617724bca5e764589158502f5fbeb Mon Sep 17 00:00:00 2001 From: AnieeG Date: Thu, 19 Dec 2024 10:48:31 -0800 Subject: [PATCH 2/8] fixes --- .../ccip/changeset/cs_ccip_home_test.go | 4 ++-- .../ccip/changeset/cs_chain_contracts.go | 5 ++--- .../ccip/changeset/cs_home_chain_test.go | 4 ++-- deployment/ccip/changeset/test_assertions.go | 19 +++++++++++-------- deployment/ccip/changeset/test_helpers.go | 2 +- .../ccip/view/v1_2/price_registry_test.go | 8 ++++---- deployment/ccip/view/v1_5/offramp_test.go | 7 +++---- deployment/ccip/view/v1_5/onramp_test.go | 7 +++---- deployment/ccip/view/v1_5/rmn_test.go | 6 +++--- deployment/ccip/view/v1_6/rmnhome.go | 1 + 10 files changed, 32 insertions(+), 31 deletions(-) diff --git a/deployment/ccip/changeset/cs_ccip_home_test.go b/deployment/ccip/changeset/cs_ccip_home_test.go index 6b4683ae12c..386be3aa665 100644 --- a/deployment/ccip/changeset/cs_ccip_home_test.go +++ b/deployment/ccip/changeset/cs_ccip_home_test.go @@ -459,7 +459,7 @@ func Test_UpdateChainConfigs(t *testing.T) { ccipHome := state.Chains[tenv.HomeChainSel].CCIPHome otherChainConfig, err := ccipHome.GetChainConfig(nil, otherChain) require.NoError(t, err) - assert.True(t, otherChainConfig.FChain != 0) + assert.NotEqual(t, 0, otherChainConfig.FChain) var mcmsConfig *MCMSConfig if tc.mcmsEnabled { @@ -488,7 +488,7 @@ func Test_UpdateChainConfigs(t *testing.T) { // other chain should be gone chainConfigAfter, err := ccipHome.GetChainConfig(nil, otherChain) require.NoError(t, err) - assert.True(t, chainConfigAfter.FChain == 0) + assert.Equal(t, 0, chainConfigAfter.FChain) // Lets add it back now. _, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*proposalutils.TimelockExecutionContracts{ diff --git a/deployment/ccip/changeset/cs_chain_contracts.go b/deployment/ccip/changeset/cs_chain_contracts.go index e97772793b0..9b5a0c3cdad 100644 --- a/deployment/ccip/changeset/cs_chain_contracts.go +++ b/deployment/ccip/changeset/cs_chain_contracts.go @@ -36,7 +36,7 @@ var ( type UpdateOnRampDestsConfig struct { UpdatesByChain map[uint64]map[uint64]OnRampDestinationUpdate // Disallow mixing MCMS/non-MCMS per chain for simplicity. - // (can still be acheived by calling this function multiple times) + // (can still be achieved by calling this function multiple times) MCMS *MCMSConfig } @@ -170,7 +170,7 @@ func UpdateOnRampsDests(e deployment.Environment, cfg UpdateOnRampDestsConfig) ( type UpdateFeeQuoterDestsConfig struct { UpdatesByChain map[uint64]map[uint64]fee_quoter.FeeQuoterDestChainConfig // Disallow mixing MCMS/non-MCMS per chain for simplicity. - // (can still be acheived by calling this function multiple times) + // (can still be achieved by calling this function multiple times) MCMS *MCMSConfig } @@ -480,7 +480,6 @@ func (cfg UpdateRouterRampsConfig) Validate(e deployment.Environment) error { return fmt.Errorf("missing offramp for dest %d", destination) } } - } return nil } diff --git a/deployment/ccip/changeset/cs_home_chain_test.go b/deployment/ccip/changeset/cs_home_chain_test.go index 8a2d4f87709..e96cd878305 100644 --- a/deployment/ccip/changeset/cs_home_chain_test.go +++ b/deployment/ccip/changeset/cs_home_chain_test.go @@ -52,12 +52,12 @@ func TestDeployHomeChain(t *testing.T) { capRegSnap, ok := snap[chainName].CapabilityRegistry[state.Chains[homeChainSel].CapabilityRegistry.Address().String()] require.True(t, ok) require.NotNil(t, capRegSnap) - require.Equal(t, capRegSnap.Nops, []v1_0.NopView{ + require.Equal(t, []v1_0.NopView{ { Admin: e.Chains[homeChainSel].DeployerKey.From, Name: "NodeOperator", }, - }) + }, capRegSnap.Nops) require.Len(t, capRegSnap.Nodes, len(p2pIds)) } diff --git a/deployment/ccip/changeset/test_assertions.go b/deployment/ccip/changeset/test_assertions.go index bcfb49250d4..311f490e66b 100644 --- a/deployment/ccip/changeset/test_assertions.go +++ b/deployment/ccip/changeset/test_assertions.go @@ -208,15 +208,18 @@ func ConfirmCommitForAllWithExpectedSeqNums( } } - done := make(chan struct{}) + errFound := make(chan error) go func() { - require.NoError(t, wg.Wait()) - close(done) + errFound <- wg.Wait() }() require.Eventually(t, func() bool { select { - case <-done: + case err := <-errFound: + if err != nil { + t.Errorf("Error waiting for all commits: %v", err) + return false + } return true default: return false @@ -360,12 +363,12 @@ func ConfirmCommitWithExpectedSeqNumRange( if mr.SourceChainSelector == src.Selector && uint64(expectedSeqNumRange.Start()) >= mr.MinSeqNr && uint64(expectedSeqNumRange.End()) <= mr.MaxSeqNr { - t.Logf("All sequence numbers commited in a single report [%d, %d]", expectedSeqNumRange.Start(), expectedSeqNumRange.End()) + t.Logf("All sequence numbers committed in a single report [%d, %d]", expectedSeqNumRange.Start(), expectedSeqNumRange.End()) return event, nil } if !enforceSingleCommit && seenMessages.allCommited(src.Selector) { - t.Logf("All sequence numbers already commited from range [%d, %d]", expectedSeqNumRange.Start(), expectedSeqNumRange.End()) + t.Logf("All sequence numbers already committed from range [%d, %d]", expectedSeqNumRange.Start(), expectedSeqNumRange.End()) return event, nil } } @@ -389,12 +392,12 @@ func ConfirmCommitWithExpectedSeqNumRange( if mr.SourceChainSelector == src.Selector && uint64(expectedSeqNumRange.Start()) >= mr.MinSeqNr && uint64(expectedSeqNumRange.End()) <= mr.MaxSeqNr { - t.Logf("All sequence numbers commited in a single report [%d, %d]", expectedSeqNumRange.Start(), expectedSeqNumRange.End()) + t.Logf("All sequence numbers committed in a single report [%d, %d]", expectedSeqNumRange.Start(), expectedSeqNumRange.End()) return report, nil } if !enforceSingleCommit && seenMessages.allCommited(src.Selector) { - t.Logf("All sequence numbers already commited from range [%d, %d]", expectedSeqNumRange.Start(), expectedSeqNumRange.End()) + t.Logf("All sequence numbers already committed from range [%d, %d]", expectedSeqNumRange.Start(), expectedSeqNumRange.End()) return report, nil } } diff --git a/deployment/ccip/changeset/test_helpers.go b/deployment/ccip/changeset/test_helpers.go index 75801d99cff..d6aad8eed1d 100644 --- a/deployment/ccip/changeset/test_helpers.go +++ b/deployment/ccip/changeset/test_helpers.go @@ -504,7 +504,7 @@ func deploySingleFeed( deployFunc func(deployment.Chain) deployment.ContractDeploy[*aggregator_v3_interface.AggregatorV3Interface], symbol TokenSymbol, ) (common.Address, string, error) { - //tokenTV := deployment.NewTypeAndVersion(PriceFeed, deployment.Version1_0_0) + // tokenTV := deployment.NewTypeAndVersion(PriceFeed, deployment.Version1_0_0) mockTokenFeed, err := deployment.DeployContract(lggr, chain, ab, deployFunc) if err != nil { lggr.Errorw("Failed to deploy token feed", "err", err, "symbol", symbol) diff --git a/deployment/ccip/view/v1_2/price_registry_test.go b/deployment/ccip/view/v1_2/price_registry_test.go index cbcdbe253ce..8248f55335b 100644 --- a/deployment/ccip/view/v1_2/price_registry_test.go +++ b/deployment/ccip/view/v1_2/price_registry_test.go @@ -29,10 +29,10 @@ func TestGeneratePriceRegistryView(t *testing.T) { v, err := GeneratePriceRegistryView(c) require.NoError(t, err) assert.Equal(t, v.Owner, chain.DeployerKey.From) - assert.Equal(t, v.TypeAndVersion, "PriceRegistry 1.2.0") - assert.Equal(t, v.FeeTokens, []common.Address{f1, f2}) - assert.Equal(t, v.StalenessThreshold, "10") - assert.Equal(t, v.Updaters, []common.Address{chain.DeployerKey.From}) + assert.Equal(t, "PriceRegistry 1.2.0", v.TypeAndVersion) + assert.Equal(t, []common.Address{f1, f2}, v.FeeTokens) + assert.Equal(t, "10", v.StalenessThreshold) + assert.Equal(t, []common.Address{chain.DeployerKey.From}, v.Updaters) _, err = json.MarshalIndent(v, "", " ") require.NoError(t, err) } diff --git a/deployment/ccip/view/v1_5/offramp_test.go b/deployment/ccip/view/v1_5/offramp_test.go index d6539fe2ba5..073c7c4711c 100644 --- a/deployment/ccip/view/v1_5/offramp_test.go +++ b/deployment/ccip/view/v1_5/offramp_test.go @@ -2,6 +2,7 @@ package v1_5 import ( "encoding/json" + "math/big" "testing" "github.com/ethereum/go-ethereum/common" @@ -10,8 +11,6 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" - "math/big" - "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/environment/memory" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/commit_store" @@ -53,8 +52,8 @@ func TestOffRampView(t *testing.T) { v, err := GenerateOffRampView(c2) require.NoError(t, err) - assert.Equal(t, v.StaticConfig, sc) - assert.Equal(t, v.TypeAndVersion, "EVM2EVMOffRamp 1.5.0") + assert.Equal(t, sc, v.StaticConfig) + assert.Equal(t, "EVM2EVMOffRamp 1.5.0", v.TypeAndVersion) _, err = json.MarshalIndent(v, "", " ") require.NoError(t, err) } diff --git a/deployment/ccip/view/v1_5/onramp_test.go b/deployment/ccip/view/v1_5/onramp_test.go index 4d7ef0225a6..72143bf7deb 100644 --- a/deployment/ccip/view/v1_5/onramp_test.go +++ b/deployment/ccip/view/v1_5/onramp_test.go @@ -62,10 +62,9 @@ func TestOnRampView(t *testing.T) { v, err := GenerateOnRampView(c) require.NoError(t, err) // Check a few fields. - assert.Equal(t, v.StaticConfig.ChainSelector, chain.Selector) - assert.Equal(t, v.DynamicConfig.Router, common.HexToAddress("0x4")) - assert.Equal(t, v.TypeAndVersion, "EVM2EVMOnRamp 1.5.0") + assert.Equal(t, chain.Selector, v.StaticConfig.ChainSelector) + assert.Equal(t, common.HexToAddress("0x4"), v.DynamicConfig.Router) + assert.Equal(t, "EVM2EVMOnRamp 1.5.0", v.TypeAndVersion) _, err = json.MarshalIndent(v, "", " ") require.NoError(t, err) - } diff --git a/deployment/ccip/view/v1_5/rmn_test.go b/deployment/ccip/view/v1_5/rmn_test.go index 3ec7d7a9cc9..4322d45174d 100644 --- a/deployment/ccip/view/v1_5/rmn_test.go +++ b/deployment/ccip/view/v1_5/rmn_test.go @@ -45,9 +45,9 @@ func TestGenerateRMNView(t *testing.T) { v, err := GenerateRMNView(c) require.NoError(t, err) assert.Equal(t, v.Owner, chain.DeployerKey.From) - assert.Equal(t, v.TypeAndVersion, "RMN 1.5.0") - assert.Equal(t, v.ConfigDetails.Version, uint32(1)) - assert.Equal(t, v.ConfigDetails.Config, cfg) + assert.Equal(t, "RMN 1.5.0", v.TypeAndVersion) + assert.Equal(t, uint32(1), v.ConfigDetails.Version) + assert.Equal(t, cfg, v.ConfigDetails.Config) _, err = json.MarshalIndent(v, "", " ") require.NoError(t, err) } diff --git a/deployment/ccip/view/v1_6/rmnhome.go b/deployment/ccip/view/v1_6/rmnhome.go index 82d39074d6f..b05d15bc223 100644 --- a/deployment/ccip/view/v1_6/rmnhome.go +++ b/deployment/ccip/view/v1_6/rmnhome.go @@ -7,6 +7,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/smartcontractkit/chainlink/deployment/common/view/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_home" ) From 2c9f7d78007e859aa71c86f0aa9a31374e62b21b Mon Sep 17 00:00:00 2001 From: AnieeG Date: Thu, 19 Dec 2024 11:06:23 -0800 Subject: [PATCH 3/8] lint updates --- deployment/ccip/changeset/cs_add_lane_test.go | 4 +- deployment/ccip/changeset/cs_ccip_home.go | 2 +- .../ccip/changeset/cs_chain_contracts.go | 9 ++-- .../ccip/changeset/cs_chain_contracts_test.go | 5 ++- deployment/ccip/changeset/cs_deploy_chain.go | 16 +++---- deployment/ccip/changeset/cs_home_chain.go | 18 ++++---- deployment/ccip/changeset/cs_prerequisites.go | 16 +++---- .../ccip/changeset/cs_update_rmn_config.go | 8 ++-- .../changeset/cs_update_rmn_config_test.go | 13 +++--- deployment/ccip/changeset/test_assertions.go | 20 ++++----- deployment/ccip/changeset/test_environment.go | 2 +- deployment/ccip/changeset/test_helpers.go | 44 ++++++++----------- .../ccip/changeset/test_usdc_helpers.go | 4 +- .../smoke/ccip/ccip_batching_test.go | 4 +- .../smoke/ccip/ccip_messaging_test.go | 14 +++--- .../smoke/ccip/ccip_ooo_execution_test.go | 10 ++--- .../smoke/ccip/ccip_token_transfer_test.go | 10 ++--- .../smoke/ccip/ccip_usdc_test.go | 12 ++--- 18 files changed, 103 insertions(+), 108 deletions(-) diff --git a/deployment/ccip/changeset/cs_add_lane_test.go b/deployment/ccip/changeset/cs_add_lane_test.go index 5c324c975ef..2e239632329 100644 --- a/deployment/ccip/changeset/cs_add_lane_test.go +++ b/deployment/ccip/changeset/cs_add_lane_test.go @@ -80,7 +80,7 @@ func TestAddLane(t *testing.T) { chain := state.Chains[sel] offRamps, err := chain.Router.GetOffRamps(nil) require.NoError(t, err) - require.Len(t, offRamps, 0) + require.Empty(t, offRamps) } replayBlocks, err := LatestBlocksByChain(testcontext.Get(t), e.Env.Chains) @@ -114,7 +114,7 @@ func TestAddLane(t *testing.T) { require.Equal(t, common.LeftPadBytes(state.Chains[chain1].OnRamp.Address().Bytes(), 32), srcCfg.OnRamp) require.False(t, srcCfg.IsEnabled) } else { - require.Len(t, offRamps, 0) + require.Empty(t, offRamps) } } diff --git a/deployment/ccip/changeset/cs_ccip_home.go b/deployment/ccip/changeset/cs_ccip_home.go index 6dc47f7259e..cfbbdedd0cb 100644 --- a/deployment/ccip/changeset/cs_ccip_home.go +++ b/deployment/ccip/changeset/cs_ccip_home.go @@ -476,7 +476,7 @@ func AddDonAndSetCandidateChangeset( ChainIdentifier: mcms.ChainIdentifier(cfg.HomeChainSelector), Batch: donOps, }}, - fmt.Sprintf("addDON on new Chain && setCandidate for plugin %s", cfg.PluginType.String()), + "addDON on new Chain && setCandidate for plugin "+cfg.PluginType.String(), cfg.MCMS.MinDelay, ) if err != nil { diff --git a/deployment/ccip/changeset/cs_chain_contracts.go b/deployment/ccip/changeset/cs_chain_contracts.go index 9b5a0c3cdad..c2c9b3ce276 100644 --- a/deployment/ccip/changeset/cs_chain_contracts.go +++ b/deployment/ccip/changeset/cs_chain_contracts.go @@ -14,6 +14,7 @@ import ( "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" commoncs "github.com/smartcontractkit/chainlink/deployment/common/changeset" @@ -103,7 +104,7 @@ func UpdateOnRampsDests(e deployment.Environment, cfg UpdateOnRampDestsConfig) ( proposers := make(map[uint64]*gethwrappers.ManyChainMultiSig) for chainSel, updates := range cfg.UpdatesByChain { txOpts := e.Chains[chainSel].DeployerKey - txOpts.Context = e.GetContext() + txOpts.Context = context.WithValue(e.GetContext(), "chainSel", chainSel) if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() } @@ -228,7 +229,7 @@ func UpdateFeeQuoterDests(e deployment.Environment, cfg UpdateFeeQuoterDestsConf proposers := make(map[uint64]*gethwrappers.ManyChainMultiSig) for chainSel, updates := range cfg.UpdatesByChain { txOpts := e.Chains[chainSel].DeployerKey - txOpts.Context = e.GetContext() + txOpts.Context = context.WithValue(e.GetContext(), "chainSel", chainSel) if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() } @@ -350,7 +351,7 @@ func UpdateOffRampSources(e deployment.Environment, cfg UpdateOffRampSourcesConf proposers := make(map[uint64]*gethwrappers.ManyChainMultiSig) for chainSel, updates := range cfg.UpdatesByChain { txOpts := e.Chains[chainSel].DeployerKey - txOpts.Context = e.GetContext() + txOpts.Context = context.WithValue(e.GetContext(), "chainSel", chainSel) if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() } @@ -689,7 +690,7 @@ func SetOCR3OffRamp(e deployment.Environment, cfg SetOCR3OffRampConfig) (deploym if err != nil { return deployment.ChangesetOutput{}, err } - e.Logger.Infof("Proposing OCR3 config update for", cfg.RemoteChainSels) + e.Logger.Infof("Proposing OCR3 config update for %v", cfg.RemoteChainSels) return deployment.ChangesetOutput{Proposals: []timelock.MCMSWithTimelockProposal{ *p, }}, nil diff --git a/deployment/ccip/changeset/cs_chain_contracts_test.go b/deployment/ccip/changeset/cs_chain_contracts_test.go index ad1b1a9f2b5..3c00d789cd0 100644 --- a/deployment/ccip/changeset/cs_chain_contracts_test.go +++ b/deployment/ccip/changeset/cs_chain_contracts_test.go @@ -9,6 +9,7 @@ import ( "golang.org/x/exp/maps" "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" + commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter" ) @@ -80,11 +81,11 @@ func TestUpdateOnRampsDests(t *testing.T) { sourceCfg, err := state.Chains[source].OnRamp.GetDestChainConfig(&bind.CallOpts{Context: ctx}, dest) require.NoError(t, err) require.Equal(t, state.Chains[source].TestRouter.Address(), sourceCfg.Router) - require.Equal(t, false, sourceCfg.AllowlistEnabled) + require.False(t, sourceCfg.AllowlistEnabled) destCfg, err := state.Chains[dest].OnRamp.GetDestChainConfig(&bind.CallOpts{Context: ctx}, source) require.NoError(t, err) require.Equal(t, state.Chains[dest].Router.Address(), destCfg.Router) - require.Equal(t, true, destCfg.AllowlistEnabled) + require.True(t, destCfg.AllowlistEnabled) }) } } diff --git a/deployment/ccip/changeset/cs_deploy_chain.go b/deployment/ccip/changeset/cs_deploy_chain.go index 065c29755b6..6e2afa4eda8 100644 --- a/deployment/ccip/changeset/cs_deploy_chain.go +++ b/deployment/ccip/changeset/cs_deploy_chain.go @@ -75,7 +75,7 @@ func deployChainContractsForChains( chainsToDeploy []uint64) error { existingState, err := LoadOnchainState(e) if err != nil { - e.Logger.Errorw("Failed to load existing onchain state", "err") + e.Logger.Errorw("Failed to load existing onchain state", "err", err) return err } @@ -148,7 +148,7 @@ func deployChainContracts( // check for existing contracts state, err := LoadOnchainState(e) if err != nil { - e.Logger.Errorw("Failed to load existing onchain state", "err") + e.Logger.Errorw("Failed to load existing onchain state", "err", err) return err } chainState, chainExists := state.Chains[chain.Selector] @@ -189,7 +189,7 @@ func deployChainContracts( false, ) return deployment.ContractDeploy[*maybe_revert_message_receiver.MaybeRevertMessageReceiver]{ - receiverAddr, receiver, tx, deployment.NewTypeAndVersion(CCIPReceiver, deployment.Version1_0_0), err2, + Address: receiverAddr, Contract: receiver, Tx: tx, Tv: deployment.NewTypeAndVersion(CCIPReceiver, deployment.Version1_0_0), Err: err2, } }) if err != nil { @@ -219,7 +219,7 @@ func deployChainContracts( rmnLegacyAddr, ) return deployment.ContractDeploy[*rmn_remote.RMNRemote]{ - rmnRemoteAddr, rmnRemote, tx, deployment.NewTypeAndVersion(RMNRemote, deployment.Version1_6_0_dev), err2, + Address: rmnRemoteAddr, Contract: rmnRemote, Tx: tx, Tv: deployment.NewTypeAndVersion(RMNRemote, deployment.Version1_6_0_dev), Err: err2, } }) if err != nil { @@ -259,7 +259,7 @@ func deployChainContracts( rmnProxyContract.Address(), ) return deployment.ContractDeploy[*router.Router]{ - routerAddr, routerC, tx2, deployment.NewTypeAndVersion(TestRouter, deployment.Version1_2_0), err2, + Address: routerAddr, Contract: routerC, Tx: tx2, Tv: deployment.NewTypeAndVersion(TestRouter, deployment.Version1_2_0), Err: err2, } }) if err != nil { @@ -280,7 +280,7 @@ func deployChainContracts( []common.Address{}, // Need to add onRamp after ) return deployment.ContractDeploy[*nonce_manager.NonceManager]{ - nonceManagerAddr, nonceManager, tx2, deployment.NewTypeAndVersion(NonceManager, deployment.Version1_6_0_dev), err2, + Address: nonceManagerAddr, Contract: nonceManager, Tx: tx2, Tv: deployment.NewTypeAndVersion(NonceManager, deployment.Version1_6_0_dev), Err: err2, } }) if err != nil { @@ -320,7 +320,7 @@ func deployChainContracts( []fee_quoter.FeeQuoterDestChainConfigArgs{}, ) return deployment.ContractDeploy[*fee_quoter.FeeQuoter]{ - prAddr, pr, tx2, deployment.NewTypeAndVersion(FeeQuoter, deployment.Version1_6_0_dev), err2, + Address: prAddr, Contract: pr, Tx: tx2, Tv: deployment.NewTypeAndVersion(FeeQuoter, deployment.Version1_6_0_dev), Err: err2, } }) if err != nil { @@ -351,7 +351,7 @@ func deployChainContracts( []onramp.OnRampDestChainConfigArgs{}, ) return deployment.ContractDeploy[*onramp.OnRamp]{ - onRampAddr, onRamp, tx2, deployment.NewTypeAndVersion(OnRamp, deployment.Version1_6_0_dev), err2, + Address: onRampAddr, Contract: onRamp, Tx: tx2, Tv: deployment.NewTypeAndVersion(OnRamp, deployment.Version1_6_0_dev), Err: err2, } }) if err != nil { diff --git a/deployment/ccip/changeset/cs_home_chain.go b/deployment/ccip/changeset/cs_home_chain.go index 44658d41016..421885772b8 100644 --- a/deployment/ccip/changeset/cs_home_chain.go +++ b/deployment/ccip/changeset/cs_home_chain.go @@ -16,6 +16,7 @@ import ( "golang.org/x/exp/maps" "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" "github.com/smartcontractkit/chainlink/deployment" @@ -36,7 +37,7 @@ func DeployHomeChain(env deployment.Environment, cfg DeployHomeChainConfig) (dep } ab := deployment.NewMemoryAddressBook() // Note we also deploy the cap reg. - _, err = deployHomeChain(env.Logger, env, ab, env.Chains[cfg.HomeChainSel], cfg.RMNStaticConfig, cfg.RMNDynamicConfig, cfg.NodeOperators, cfg.NodeP2PIDsPerNodeOpAdmin) + _, err = deployHomeChainContracts(env.Logger, env, ab, env.Chains[cfg.HomeChainSel], cfg.RMNStaticConfig, cfg.RMNDynamicConfig, cfg.NodeOperators, cfg.NodeP2PIDsPerNodeOpAdmin) if err != nil { env.Logger.Errorw("Failed to deploy cap reg", "err", err, "addresses", env.ExistingAddresses) return deployment.ChangesetOutput{ @@ -122,7 +123,7 @@ func deployCapReg( return capReg, nil } -func deployHomeChain( +func deployHomeChainContracts( lggr logger.Logger, e deployment.Environment, ab deployment.AddressBook, @@ -241,10 +242,10 @@ func deployHomeChain( // Need to fetch nodeoperators ids to be able to add nodes for corresponding node operators p2pIDsByNodeOpId := make(map[uint32][][32]byte) for addedEvent.Next() { - for nopName, p2pId := range nodeP2PIDsPerNodeOpAdmin { + for nopName, p2pID := range nodeP2PIDsPerNodeOpAdmin { if addedEvent.Event.Name == nopName { lggr.Infow("Added node operator", "admin", addedEvent.Event.Admin, "name", addedEvent.Event.Name) - p2pIDsByNodeOpId[addedEvent.Event.NodeOperatorId] = p2pId + p2pIDsByNodeOpId[addedEvent.Event.NodeOperatorId] = p2pID } } } @@ -275,7 +276,7 @@ func addNodes( lggr logger.Logger, capReg *capabilities_registry.CapabilitiesRegistry, chain deployment.Chain, - p2pIDsByNodeOpId map[uint32][][32]byte, + p2pIDsByNodeOpID map[uint32][][32]byte, ) error { var nodeParams []capabilities_registry.CapabilitiesRegistryNodeParams nodes, err := capReg.GetNodes(nil) @@ -291,7 +292,7 @@ func addNodes( HashedCapabilityIds: node.HashedCapabilityIds, } } - for nopID, p2pIDs := range p2pIDsByNodeOpId { + for nopID, p2pIDs := range p2pIDsByNodeOpID { for _, p2pID := range p2pIDs { // if any p2pIDs are empty throw error if bytes.Equal(p2pID[:], make([]byte, 32)) { @@ -347,10 +348,7 @@ func (c RemoveDONsConfig) Validate(homeChain CCIPChainState) error { if homeChain.CCIPHome == nil { return fmt.Errorf("ccip home does not exist") } - if err := internal.DONIdExists(homeChain.CapabilityRegistry, c.DonIDs); err != nil { - return err - } - return nil + return internal.DONIdExists(homeChain.CapabilityRegistry, c.DonIDs) } // RemoveDONs removes DONs from the CapabilitiesRegistry contract. diff --git a/deployment/ccip/changeset/cs_prerequisites.go b/deployment/ccip/changeset/cs_prerequisites.go index 95ef923df83..3bfce4570a2 100644 --- a/deployment/ccip/changeset/cs_prerequisites.go +++ b/deployment/ccip/changeset/cs_prerequisites.go @@ -87,7 +87,7 @@ func WithMulticall3(enabled bool) PrerequisiteOpt { func deployPrerequisiteChainContracts(e deployment.Environment, ab deployment.AddressBook, selectors []uint64, opts ...PrerequisiteOpt) error { state, err := LoadOnchainState(e) if err != nil { - e.Logger.Errorw("Failed to load existing onchain state", "err") + e.Logger.Errorw("Failed to load existing onchain state", "err", err) return err } deployGrp := errgroup.Group{} @@ -154,13 +154,13 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address } rmnProxyContract, err := deployment.DeployContract(lggr, chain, ab, func(chain deployment.Chain) deployment.ContractDeploy[*rmn_proxy_contract.RMNProxyContract] { - rmnProxyAddr, tx2, rmnProxy, err2 := rmn_proxy_contract.DeployRMNProxyContract( + rmnProxyAddr, tx2, rmnProxyC, err2 := rmn_proxy_contract.DeployRMNProxyContract( chain.DeployerKey, chain.Client, rmn.Address, ) return deployment.ContractDeploy[*rmn_proxy_contract.RMNProxyContract]{ - rmnProxyAddr, rmnProxy, tx2, deployment.NewTypeAndVersion(ARMProxy, deployment.Version1_0_0), err2, + Address: rmnProxyAddr, Contract: rmnProxyC, Tx: tx2, Tv: deployment.NewTypeAndVersion(ARMProxy, deployment.Version1_0_0), Err: err2, } }) if err != nil { @@ -176,7 +176,7 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address chain.DeployerKey, chain.Client) return deployment.ContractDeploy[*token_admin_registry.TokenAdminRegistry]{ - tokenAdminRegistryAddr, tokenAdminRegistry, tx2, deployment.NewTypeAndVersion(TokenAdminRegistry, deployment.Version1_5_0), err2, + Address: tokenAdminRegistryAddr, Contract: tokenAdminRegistry, Tx: tx2, Tv: deployment.NewTypeAndVersion(TokenAdminRegistry, deployment.Version1_5_0), Err: err2, } }) if err != nil { @@ -195,7 +195,7 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address chain.Client, tokenAdminReg.Address()) return deployment.ContractDeploy[*registry_module_owner_custom.RegistryModuleOwnerCustom]{ - regModAddr, regMod, tx2, deployment.NewTypeAndVersion(RegistryModule, deployment.Version1_5_0), err2, + Address: regModAddr, Contract: regMod, Tx: tx2, Tv: deployment.NewTypeAndVersion(RegistryModule, deployment.Version1_5_0), Err: err2, } }) if err != nil { @@ -233,7 +233,7 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address chain.Client, ) return deployment.ContractDeploy[*weth9.WETH9]{ - weth9Addr, weth9c, tx2, deployment.NewTypeAndVersion(WETH9, deployment.Version1_0_0), err2, + Address: weth9Addr, Contract: weth9c, Tx: tx2, Tv: deployment.NewTypeAndVersion(WETH9, deployment.Version1_0_0), Err: err2, } }) if err != nil { @@ -255,7 +255,7 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address rmnProxy.Address(), ) return deployment.ContractDeploy[*router.Router]{ - routerAddr, routerC, tx2, deployment.NewTypeAndVersion(Router, deployment.Version1_2_0), err2, + Address: routerAddr, Contract: routerC, Tx: tx2, Tv: deployment.NewTypeAndVersion(Router, deployment.Version1_2_0), Err: err2, } }) if err != nil { @@ -275,7 +275,7 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address chain.Client, ) return deployment.ContractDeploy[*multicall3.Multicall3]{ - multicall3Addr, multicall3Wrapper, tx2, deployment.NewTypeAndVersion(Multicall3, deployment.Version1_0_0), err2, + Address: multicall3Addr, Contract: multicall3Wrapper, Tx: tx2, Tv: deployment.NewTypeAndVersion(Multicall3, deployment.Version1_0_0), Err: err2, } }) if err != nil { diff --git a/deployment/ccip/changeset/cs_update_rmn_config.go b/deployment/ccip/changeset/cs_update_rmn_config.go index 96f8eacb4cc..5b71c162565 100644 --- a/deployment/ccip/changeset/cs_update_rmn_config.go +++ b/deployment/ccip/changeset/cs_update_rmn_config.go @@ -189,15 +189,15 @@ func (c SetRMNHomeCandidateConfig) Validate(state CCIPOnChainState) error { } var ( - peerIds = make(map[[32]byte]struct{}) + peerIDs = make(map[[32]byte]struct{}) offchainPublicKeys = make(map[[32]byte]struct{}) ) for _, node := range c.RMNStaticConfig.Nodes { - if _, exists := peerIds[node.PeerId]; exists { + if _, exists := peerIDs[node.PeerId]; exists { return fmt.Errorf("peerId %x is duplicated", node.PeerId) } - peerIds[node.PeerId] = struct{}{} + peerIDs[node.PeerId] = struct{}{} if _, exists := offchainPublicKeys[node.OffchainPublicKey]; exists { return fmt.Errorf("offchainPublicKey %x is duplicated", node.OffchainPublicKey) @@ -321,7 +321,7 @@ func NewSetRMNHomeCandidateConfigChangeset(e deployment.Environment, config SetR return deployment.ChangesetOutput{ Proposals: []timelock.MCMSWithTimelockProposal{*prop}, - }, nil + }, err } func NewPromoteCandidateConfigChangeset(e deployment.Environment, config PromoteRMNHomeCandidateConfig) (deployment.ChangesetOutput, error) { diff --git a/deployment/ccip/changeset/cs_update_rmn_config_test.go b/deployment/ccip/changeset/cs_update_rmn_config_test.go index 07bf22720c2..080864eb7b3 100644 --- a/deployment/ccip/changeset/cs_update_rmn_config_test.go +++ b/deployment/ccip/changeset/cs_update_rmn_config_test.go @@ -15,19 +15,19 @@ import ( ) var ( - rmn_staging_1 = RMNNopConfig{ + rmnStaging1 = RMNNopConfig{ NodeIndex: 0, PeerId: deployment.MustPeerIDFromString("p2p_12D3KooWRXxZq3pd4a3ZGkKj7Nt1SQQrnB8CuvbPnnV9KVeMeWqg"), OffchainPublicKey: [32]byte(common.FromHex("0xb34944857a42444d1b285d7940d6e06682309e0781e43a69676ee9f85c73c2d1")), EVMOnChainPublicKey: common.HexToAddress("0x5af8ee32316a6427f169a45fdc1b3a91a85ac459e3c1cb91c69e1c51f0c1fc21"), } - rmn_staging_2 = RMNNopConfig{ + rmnStaging2 = RMNNopConfig{ NodeIndex: 1, PeerId: deployment.MustPeerIDFromString("p2p_12D3KooWEmdxYQFsRbD9aFczF32zA3CcUwuSiWCk2CrmACo4v9RL"), OffchainPublicKey: [32]byte(common.FromHex("0x68d9f3f274e3985528a923a9bace3d39c55dd778b187b4120b384cc48c892859")), EVMOnChainPublicKey: common.HexToAddress("0x858589216956f482a0f68b282a7050af4cd48ed2"), } - rmn_staging_3 = RMNNopConfig{ + rmnStaging3 = RMNNopConfig{ NodeIndex: 2, PeerId: deployment.MustPeerIDFromString("p2p_12D3KooWJS42cNXKJvj6DeZnxEX7aGxhEuap6uNFrz554AbUDw6Q"), OffchainPublicKey: [32]byte(common.FromHex("0x5af8ee32316a6427f169a45fdc1b3a91a85ac459e3c1cb91c69e1c51f0c1fc21")), @@ -47,12 +47,12 @@ func TestUpdateRMNConfig(t *testing.T) { { useMCMS: true, name: "with MCMS", - nops: []RMNNopConfig{rmn_staging_1, rmn_staging_2, rmn_staging_3}, + nops: []RMNNopConfig{rmnStaging1, rmnStaging2, rmnStaging3}, }, { useMCMS: false, name: "without MCMS", - nops: []RMNNopConfig{rmn_staging_1, rmn_staging_2, rmn_staging_3}, + nops: []RMNNopConfig{rmnStaging1, rmnStaging2, rmnStaging3}, }, } @@ -90,6 +90,7 @@ func updateRMNConfig(t *testing.T, tc updateRMNConfigTestCase) { }, }, }) + require.NoError(t, err) } rmnHome := state.Chains[e.HomeChainSel].RMNHome @@ -99,7 +100,7 @@ func updateRMNConfig(t *testing.T, tc updateRMNConfigTestCase) { previousActiveDigest, err := rmnHome.GetActiveDigest(nil) require.NoError(t, err) - var mcmsConfig *MCMSConfig = nil + var mcmsConfig *MCMSConfig if tc.useMCMS { mcmsConfig = &MCMSConfig{ diff --git a/deployment/ccip/changeset/test_assertions.go b/deployment/ccip/changeset/test_assertions.go index 311f490e66b..9a53fec5c9b 100644 --- a/deployment/ccip/changeset/test_assertions.go +++ b/deployment/ccip/changeset/test_assertions.go @@ -516,7 +516,7 @@ func ConfirmExecWithSeqNrs( scc, executionState := GetExecutionState(t, source, dest, offRamp, expectedSeqNr) t.Logf("Waiting for ExecutionStateChanged on chain %d (offramp %s) from chain %d with expected sequence number %d, current onchain minSeqNr: %d, execution state: %s", dest.Selector, offRamp.Address().String(), source.Selector, expectedSeqNr, scc.MinSeqNr, executionStateToString(executionState)) - if executionState == EXECUTION_STATE_SUCCESS || executionState == EXECUTION_STATE_FAILURE { + if executionState == ExecutionStateSuccess || executionState == ExecutionStateFailure { t.Logf("Observed %s execution state on chain %d (offramp %s) from chain %d with expected sequence number %d", executionStateToString(executionState), dest.Selector, offRamp.Address().String(), source.Selector, expectedSeqNr) executionStates[expectedSeqNr] = int(executionState) @@ -562,7 +562,7 @@ func ConfirmNoExecConsistentlyWithSeqNr( scc, executionState := GetExecutionState(t, source, dest, offRamp, expectedSeqNr) t.Logf("Waiting for ExecutionStateChanged on chain %d (offramp %s) from chain %d with expected sequence number %d, current onchain minSeqNr: %d, execution state: %s", dest.Selector, offRamp.Address().String(), source.Selector, expectedSeqNr, scc.MinSeqNr, executionStateToString(executionState)) - if executionState == EXECUTION_STATE_UNTOUCHED { + if executionState == ExecutionStateUntouched { return true } t.Logf("Observed %s execution state on chain %d (offramp %s) from chain %d with expected sequence number %d", @@ -620,21 +620,21 @@ func SeqNumberRangeToSlice(seqRanges map[SourceDestPair]ccipocr3.SeqNumRange) ma } const ( - EXECUTION_STATE_UNTOUCHED = 0 - EXECUTION_STATE_INPROGRESS = 1 - EXECUTION_STATE_SUCCESS = 2 - EXECUTION_STATE_FAILURE = 3 + ExecutionStateUntouched = 0 + ExecutionStateInprogress = 1 + ExecutionStateSuccess = 2 + ExecutionStateFailure = 3 ) func executionStateToString(state uint8) string { switch state { - case EXECUTION_STATE_UNTOUCHED: + case ExecutionStateUntouched: return "UNTOUCHED" - case EXECUTION_STATE_INPROGRESS: + case ExecutionStateInprogress: return "IN_PROGRESS" - case EXECUTION_STATE_SUCCESS: + case ExecutionStateSuccess: return "SUCCESS" - case EXECUTION_STATE_FAILURE: + case ExecutionStateFailure: return "FAILURE" default: return "UNKNOWN" diff --git a/deployment/ccip/changeset/test_environment.go b/deployment/ccip/changeset/test_environment.go index 8e590da1703..4610302ed07 100644 --- a/deployment/ccip/changeset/test_environment.go +++ b/deployment/ccip/changeset/test_environment.go @@ -300,7 +300,7 @@ func NewEnvironment(t *testing.T, tc *TestConfigs, tEnv TestEnvironment) Deploye envNodes, err := deployment.NodeInfo(dEnv.Env.NodeIDs, dEnv.Env.Offchain) require.NoError(t, err) dEnv.Env.ExistingAddresses = ab - _, err = deployHomeChain(lggr, dEnv.Env, dEnv.Env.ExistingAddresses, dEnv.Env.Chains[dEnv.HomeChainSel], + _, err = deployHomeChainContracts(lggr, dEnv.Env, dEnv.Env.ExistingAddresses, dEnv.Env.Chains[dEnv.HomeChainSel], NewTestRMNStaticConfig(), NewTestRMNDynamicConfig(), NewTestNodeOperator(dEnv.Env.Chains[dEnv.HomeChainSel].DeployerKey.From), diff --git a/deployment/ccip/changeset/test_helpers.go b/deployment/ccip/changeset/test_helpers.go index d6aad8eed1d..5fd37dd5078 100644 --- a/deployment/ccip/changeset/test_helpers.go +++ b/deployment/ccip/changeset/test_helpers.go @@ -2,6 +2,7 @@ package changeset import ( "context" + "errors" "fmt" "math/big" "net/http" @@ -11,12 +12,12 @@ import ( "testing" "time" + errors2 "github.com/pkg/errors" "golang.org/x/sync/errgroup" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" - "github.com/pkg/errors" "github.com/smartcontractkit/chainlink/v2/core/services/relay" @@ -24,7 +25,6 @@ import ( "github.com/stretchr/testify/require" chainsel "github.com/smartcontractkit/chain-selectors" - "go.uber.org/multierr" "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" @@ -124,7 +124,7 @@ func LatestBlocksByChain(ctx context.Context, chains map[uint64]deployment.Chain for _, chain := range chains { latesthdr, err := chain.Client.HeaderByNumber(ctx, nil) if err != nil { - return nil, errors.Wrapf(err, "failed to get latest header for chain %d", chain.Selector) + return nil, errors2.Wrapf(err, "failed to get latest header for chain %d", chain.Selector) } block := latesthdr.Number.Uint64() latestBlocks[chain.Selector] = block @@ -193,11 +193,11 @@ func CCIPSendRequest( tx, err := r.CcipSend(cfg.Sender, cfg.DestChain, msg) if err != nil { - return nil, 0, errors.Wrap(err, "failed to send CCIP message") + return nil, 0, errors2.Wrap(err, "failed to send CCIP message") } blockNum, err := e.Chains[cfg.SourceChain].Confirm(tx) if err != nil { - return tx, 0, errors.Wrap(err, "failed to confirm CCIP message") + return tx, 0, errors2.Wrap(err, "failed to confirm CCIP message") } return tx, blockNum, nil } @@ -462,7 +462,7 @@ func DeployFeeds( aggregatorCr, err2 := aggregator_v3_interface.NewAggregatorV3Interface(linkFeed, chain.Client) return deployment.ContractDeploy[*aggregator_v3_interface.AggregatorV3Interface]{ - Address: linkFeed, Contract: aggregatorCr, Tv: linkTV, Tx: tx, Err: multierr.Append(err1, err2), + Address: linkFeed, Contract: aggregatorCr, Tv: linkTV, Tx: tx, Err: errors.Join(err1, err2), } } @@ -475,7 +475,7 @@ func DeployFeeds( aggregatorCr, err2 := aggregator_v3_interface.NewAggregatorV3Interface(wethFeed, chain.Client) return deployment.ContractDeploy[*aggregator_v3_interface.AggregatorV3Interface]{ - Address: wethFeed, Contract: aggregatorCr, Tv: linkTV, Tx: tx, Err: multierr.Append(err1, err2), + Address: wethFeed, Contract: aggregatorCr, Tv: linkTV, Tx: tx, Err: errors.Join(err1, err2), } } @@ -638,10 +638,7 @@ func deployTokenPoolsInParallel( if err != nil { return err } - if err := attachTokenToTheRegistry(chains[src], state.Chains[src], srcActor, srcToken.Address(), srcPool.Address()); err != nil { - return err - } - return nil + return attachTokenToTheRegistry(chains[src], state.Chains[src], srcActor, srcToken.Address(), srcPool.Address()) }) deployGrp.Go(func() error { var err error @@ -649,10 +646,7 @@ func deployTokenPoolsInParallel( if err != nil { return err } - if err := attachTokenToTheRegistry(chains[dst], state.Chains[dst], dstActor, dstToken.Address(), dstPool.Address()); err != nil { - return err - } - return nil + return attachTokenToTheRegistry(chains[dst], state.Chains[dst], dstActor, dstToken.Address(), dstPool.Address()) }) if err := deployGrp.Wait(); err != nil { return nil, nil, nil, nil, err @@ -685,7 +679,7 @@ func setUSDCTokenPoolCounterPart( var fixedAddr [32]byte copy(fixedAddr[:], allowedCaller[:32]) - domain, _ := reader.AllAvailableDomains()[destChainSelector] + domain := reader.AllAvailableDomains()[destChainSelector] domains := []usdc_token_pool.USDCTokenPoolDomainUpdate{ { @@ -839,7 +833,7 @@ func deployTransferTokenOneEnd( big.NewInt(0).Mul(big.NewInt(1e9), big.NewInt(1e18)), ) return deployment.ContractDeploy[*burn_mint_erc677.BurnMintERC677]{ - tokenAddress, token, tx, deployment.NewTypeAndVersion(BurnMintToken, deployment.Version1_0_0), err2, + Address: tokenAddress, Contract: token, Tx: tx, Tv: deployment.NewTypeAndVersion(BurnMintToken, deployment.Version1_0_0), Err: err2, } }) if err != nil { @@ -868,7 +862,7 @@ func deployTransferTokenOneEnd( common.HexToAddress(routerAddress), ) return deployment.ContractDeploy[*burn_mint_token_pool.BurnMintTokenPool]{ - tokenPoolAddress, tokenPoolContract, tx, deployment.NewTypeAndVersion(BurnMintTokenPool, deployment.Version1_5_1), err2, + Address: tokenPoolAddress, Contract: tokenPoolContract, Tx: tx, Tv: deployment.NewTypeAndVersion(BurnMintTokenPool, deployment.Version1_5_1), Err: err2, } }) if err != nil { @@ -1003,29 +997,29 @@ func TransferMultiple( t.Run(tt.Name, func(t *testing.T) { expectedTokenBalances.add(tt.DestChain, tt.Receiver, tt.ExpectedTokenBalances) - pairId := SourceDestPair{ + pairID := SourceDestPair{ SourceChainSelector: tt.SourceChain, DestChainSelector: tt.DestChain, } msg, blocks := Transfer( ctx, t, env, state, tt.SourceChain, tt.DestChain, tt.Tokens, tt.Receiver, tt.Data, tt.ExtraArgs) - if _, ok := expectedExecutionStates[pairId]; !ok { - expectedExecutionStates[pairId] = make(map[uint64]int) + if _, ok := expectedExecutionStates[pairID]; !ok { + expectedExecutionStates[pairID] = make(map[uint64]int) } - expectedExecutionStates[pairId][msg.SequenceNumber] = tt.ExpectedStatus + expectedExecutionStates[pairID][msg.SequenceNumber] = tt.ExpectedStatus if _, ok := startBlocks[tt.DestChain]; !ok { startBlocks[tt.DestChain] = blocks[tt.DestChain] } - seqNr, ok := expectedSeqNums[pairId] + seqNr, ok := expectedSeqNums[pairID] if ok { - expectedSeqNums[pairId] = cciptypes.NewSeqNumRange( + expectedSeqNums[pairID] = cciptypes.NewSeqNumRange( seqNr.Start(), cciptypes.SeqNum(msg.SequenceNumber), ) } else { - expectedSeqNums[pairId] = cciptypes.NewSeqNumRange( + expectedSeqNums[pairID] = cciptypes.NewSeqNumRange( cciptypes.SeqNum(msg.SequenceNumber), cciptypes.SeqNum(msg.SequenceNumber), ) } diff --git a/deployment/ccip/changeset/test_usdc_helpers.go b/deployment/ccip/changeset/test_usdc_helpers.go index 55f1bd25a36..c9dd87b866e 100644 --- a/deployment/ccip/changeset/test_usdc_helpers.go +++ b/deployment/ccip/changeset/test_usdc_helpers.go @@ -115,8 +115,8 @@ func UpdateFeeQuoterForUSDC( DestChainSelector: dstChain, TokenTransferFeeConfigs: []fee_quoter.FeeQuoterTokenTransferFeeConfigSingleTokenArgs{ { - usdcToken.Address(), - fee_quoter.FeeQuoterTokenTransferFeeConfig{ + Token: usdcToken.Address(), + TokenTransferFeeConfig: fee_quoter.FeeQuoterTokenTransferFeeConfig{ MinFeeUSDCents: 50, MaxFeeUSDCents: 50_000, DeciBps: 0, diff --git a/integration-tests/smoke/ccip/ccip_batching_test.go b/integration-tests/smoke/ccip/ccip_batching_test.go index 58f4e922ac5..e8cd5f95676 100644 --- a/integration-tests/smoke/ccip/ccip_batching_test.go +++ b/integration-tests/smoke/ccip/ccip_batching_test.go @@ -259,7 +259,7 @@ func Test_CCIPBatching_MultiSource(t *testing.T) { // assert that all states are successful for _, states := range execStates { for _, state := range states { - require.Equal(t, changeset.EXECUTION_STATE_SUCCESS, state) + require.Equal(t, changeset.ExecutionStateSuccess, state) } } } @@ -318,7 +318,7 @@ func Test_CCIPBatching_SingleSource(t *testing.T) { require.NoError(t, err) // assert that all states are successful for _, state := range states { - require.Equal(t, changeset.EXECUTION_STATE_SUCCESS, state) + require.Equal(t, changeset.ExecutionStateSuccess, state) } } diff --git a/integration-tests/smoke/ccip/ccip_messaging_test.go b/integration-tests/smoke/ccip/ccip_messaging_test.go index 13f14fcda16..c8f35e4d468 100644 --- a/integration-tests/smoke/ccip/ccip_messaging_test.go +++ b/integration-tests/smoke/ccip/ccip_messaging_test.go @@ -88,8 +88,8 @@ func Test_CCIPMessaging(t *testing.T) { }, common.HexToAddress("0xdead"), []byte("hello eoa"), - nil, // default extraArgs - changeset.EXECUTION_STATE_SUCCESS, // success because offRamp won't call an EOA + nil, // default extraArgs + changeset.ExecutionStateSuccess, // success because offRamp won't call an EOA ) }) @@ -102,8 +102,8 @@ func Test_CCIPMessaging(t *testing.T) { }, state.Chains[destChain].FeeQuoter.Address(), []byte("hello FeeQuoter"), - nil, // default extraArgs - changeset.EXECUTION_STATE_SUCCESS, // success because offRamp won't call a contract not implementing CCIPReceiver + nil, // default extraArgs + changeset.ExecutionStateSuccess, // success because offRamp won't call a contract not implementing CCIPReceiver ) }) @@ -119,7 +119,7 @@ func Test_CCIPMessaging(t *testing.T) { state.Chains[destChain].Receiver.Address(), []byte("hello CCIPReceiver"), nil, // default extraArgs - changeset.EXECUTION_STATE_SUCCESS, + changeset.ExecutionStateSuccess, func(t *testing.T) { iter, err := state.Chains[destChain].Receiver.FilterMessageReceived(&bind.FilterOpts{ Context: ctx, @@ -144,7 +144,7 @@ func Test_CCIPMessaging(t *testing.T) { state.Chains[destChain].Receiver.Address(), []byte("hello CCIPReceiver with low exec gas"), changeset.MakeEVMExtraArgsV2(1, false), // 1 gas is too low. - changeset.EXECUTION_STATE_FAILURE, // state would be failed onchain due to low gas + changeset.ExecutionStateFailure, // state would be failed onchain due to low gas ) manuallyExecute(ctx, t, latestHead.Number.Uint64(), state, destChain, out, sourceChain, e, sender) @@ -229,7 +229,7 @@ func manuallyExecute( newExecutionState, err := state.Chains[destChain].OffRamp.GetExecutionState(&bind.CallOpts{Context: ctx}, sourceChain, out.msgSentEvent.SequenceNumber) require.NoError(t, err) - require.Equal(t, uint8(changeset.EXECUTION_STATE_SUCCESS), newExecutionState) + require.Equal(t, uint8(changeset.ExecutionStateSuccess), newExecutionState) } func getMerkleRoot( diff --git a/integration-tests/smoke/ccip/ccip_ooo_execution_test.go b/integration-tests/smoke/ccip/ccip_ooo_execution_test.go index 19c36c6e021..23c8f2cf3e1 100644 --- a/integration-tests/smoke/ccip/ccip_ooo_execution_test.go +++ b/integration-tests/smoke/ccip/ccip_ooo_execution_test.go @@ -128,7 +128,7 @@ func Test_OutOfOrderExecution(t *testing.T) { nil, changeset.MakeEVMExtraArgsV2(0, true), ) - expectedStatuses[firstMessage.SequenceNumber] = changeset.EXECUTION_STATE_SUCCESS + expectedStatuses[firstMessage.SequenceNumber] = changeset.ExecutionStateSuccess t.Logf("Out of order messages sent from chain %d to chain %d with sequence number %d", sourceChain, destChain, firstMessage.SequenceNumber, ) @@ -183,7 +183,7 @@ func Test_OutOfOrderExecution(t *testing.T) { []byte("this message has enough gas to execute"), changeset.MakeEVMExtraArgsV2(300_000, true), ) - expectedStatuses[fourthMessage.SequenceNumber] = changeset.EXECUTION_STATE_SUCCESS + expectedStatuses[fourthMessage.SequenceNumber] = changeset.ExecutionStateSuccess t.Logf("Out of order programmable token transfer from chain %d to chain %d with sequence number %d", sourceChain, destChain, fourthMessage.SequenceNumber, ) @@ -202,7 +202,7 @@ func Test_OutOfOrderExecution(t *testing.T) { ExtraArgs: changeset.MakeEVMExtraArgsV2(0, false), })) require.NoError(t, err) - expectedStatuses[fifthMessage.SequenceNumber] = changeset.EXECUTION_STATE_SUCCESS + expectedStatuses[fifthMessage.SequenceNumber] = changeset.ExecutionStateSuccess t.Logf("Ordered message send by %v from chain %d to chain %d with sequence number %d", anotherSender.From, sourceChain, destChain, fifthMessage.SequenceNumber, ) @@ -240,11 +240,11 @@ func Test_OutOfOrderExecution(t *testing.T) { secondMsgState, err := state.Chains[destChain].OffRamp.GetExecutionState(&bind.CallOpts{Context: ctx}, sourceChain, secondMsg.SequenceNumber) require.NoError(t, err) - require.Equal(t, uint8(changeset.EXECUTION_STATE_UNTOUCHED), secondMsgState) + require.Equal(t, uint8(changeset.ExecutionStateUntouched), secondMsgState) thirdMsgState, err := state.Chains[destChain].OffRamp.GetExecutionState(&bind.CallOpts{Context: ctx}, sourceChain, thirdMessage.SequenceNumber) require.NoError(t, err) - require.Equal(t, uint8(changeset.EXECUTION_STATE_UNTOUCHED), thirdMsgState) + require.Equal(t, uint8(changeset.ExecutionStateUntouched), thirdMsgState) changeset.WaitForTheTokenBalance(ctx, t, destToken.Address(), firstReceiver, e.Chains[destChain], oneE18) changeset.WaitForTheTokenBalance(ctx, t, destUSDC.Address(), secondReceiver, e.Chains[destChain], big.NewInt(0)) diff --git a/integration-tests/smoke/ccip/ccip_token_transfer_test.go b/integration-tests/smoke/ccip/ccip_token_transfer_test.go index 2088960639e..662b17eebab 100644 --- a/integration-tests/smoke/ccip/ccip_token_transfer_test.go +++ b/integration-tests/smoke/ccip/ccip_token_transfer_test.go @@ -102,7 +102,7 @@ func TestTokenTransfer(t *testing.T) { ExpectedTokenBalances: map[common.Address]*big.Int{ destToken.Address(): oneE18, }, - ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.ExecutionStateSuccess, }, { Name: "Send token to contract", @@ -118,7 +118,7 @@ func TestTokenTransfer(t *testing.T) { ExpectedTokenBalances: map[common.Address]*big.Int{ destToken.Address(): oneE18, }, - ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.ExecutionStateSuccess, }, { Name: "Send N tokens to contract", @@ -144,7 +144,7 @@ func TestTokenTransfer(t *testing.T) { selfServeSrcToken.Address(): new(big.Int).Add(oneE18, oneE18), srcToken.Address(): oneE18, }, - ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.ExecutionStateSuccess, }, { Name: "Sending token transfer with custom gasLimits to the EOA is successful", @@ -166,7 +166,7 @@ func TestTokenTransfer(t *testing.T) { selfServeSrcToken.Address(): oneE18, srcToken.Address(): new(big.Int).Add(oneE18, oneE18), }, - ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.ExecutionStateSuccess, }, { Name: "Sending PTT with too low gas limit leads to the revert when receiver is a contract", @@ -189,7 +189,7 @@ func TestTokenTransfer(t *testing.T) { selfServeSrcToken.Address(): big.NewInt(0), srcToken.Address(): big.NewInt(0), }, - ExpectedStatus: changeset.EXECUTION_STATE_FAILURE, + ExpectedStatus: changeset.ExecutionStateFailure, }, } diff --git a/integration-tests/smoke/ccip/ccip_usdc_test.go b/integration-tests/smoke/ccip/ccip_usdc_test.go index 174ab941387..3e5592e13d8 100644 --- a/integration-tests/smoke/ccip/ccip_usdc_test.go +++ b/integration-tests/smoke/ccip/ccip_usdc_test.go @@ -110,7 +110,7 @@ func TestUSDCTokenTransfer(t *testing.T) { ExpectedTokenBalances: map[common.Address]*big.Int{ aChainUSDC.Address(): tinyOneCoin, }, - ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.ExecutionStateSuccess, }, { Name: "multiple USDC tokens within the same message", @@ -131,7 +131,7 @@ func TestUSDCTokenTransfer(t *testing.T) { // 2 coins because of the same Receiver aChainUSDC.Address(): new(big.Int).Add(tinyOneCoin, tinyOneCoin), }, - ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.ExecutionStateSuccess, }, { Name: "USDC token together with another token transferred to EOA", @@ -152,7 +152,7 @@ func TestUSDCTokenTransfer(t *testing.T) { cChainUSDC.Address(): tinyOneCoin, cChainToken.Address(): new(big.Int).Mul(tinyOneCoin, big.NewInt(10)), }, - ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.ExecutionStateSuccess, }, { Name: "USDC programmable token transfer to valid contract receiver", @@ -169,7 +169,7 @@ func TestUSDCTokenTransfer(t *testing.T) { ExpectedTokenBalances: map[common.Address]*big.Int{ cChainUSDC.Address(): tinyOneCoin, }, - ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.ExecutionStateSuccess, }, { Name: "USDC programmable token transfer with too little gas", @@ -187,7 +187,7 @@ func TestUSDCTokenTransfer(t *testing.T) { bChainUSDC.Address(): new(big.Int).SetUint64(0), }, ExtraArgs: changeset.MakeEVMExtraArgsV2(1, false), - ExpectedStatus: changeset.EXECUTION_STATE_FAILURE, + ExpectedStatus: changeset.ExecutionStateFailure, }, { Name: "USDC token transfer from a different source chain", @@ -204,7 +204,7 @@ func TestUSDCTokenTransfer(t *testing.T) { ExpectedTokenBalances: map[common.Address]*big.Int{ cChainUSDC.Address(): tinyOneCoin, }, - ExpectedStatus: changeset.EXECUTION_STATE_SUCCESS, + ExpectedStatus: changeset.ExecutionStateSuccess, }, } From 765b113b88052b65855132fa97006f5a697fe2c0 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Thu, 19 Dec 2024 11:32:55 -0800 Subject: [PATCH 4/8] lint updates --- deployment/ccip/changeset/cs_add_lane.go | 11 ++++++----- deployment/ccip/changeset/cs_chain_contracts.go | 5 ++++- deployment/ccip/changeset/cs_deploy_chain.go | 4 ++-- deployment/ccip/changeset/cs_deploy_chain_test.go | 4 ++-- deployment/ccip/changeset/cs_home_chain.go | 10 +++++----- deployment/ccip/changeset/cs_home_chain_test.go | 6 +++--- .../ccip/changeset/internal/deploy_home_chain.go | 2 +- deployment/ccip/changeset/state.go | 10 +++++----- deployment/ccip/changeset/test_environment.go | 2 +- deployment/ccip/changeset/test_helpers.go | 2 -- deployment/ccip/changeset/v1_5/cs_jobspec.go | 8 ++++---- deployment/ccip/changeset/v1_5/e2e_test.go | 2 +- deployment/ccip/changeset/v1_5/test_helpers.go | 6 +++--- deployment/ccip/view/v1_6/ccip_home_test.go | 2 +- deployment/ccip/view/v1_6/rmnhome.go | 12 ++++++------ 15 files changed, 44 insertions(+), 42 deletions(-) diff --git a/deployment/ccip/changeset/cs_add_lane.go b/deployment/ccip/changeset/cs_add_lane.go index 0bd03b56559..c3424f97e9c 100644 --- a/deployment/ccip/changeset/cs_add_lane.go +++ b/deployment/ccip/changeset/cs_add_lane.go @@ -2,6 +2,7 @@ package changeset import ( "encoding/hex" + "errors" "fmt" "math/big" @@ -26,13 +27,13 @@ type InitialPrices struct { func (p InitialPrices) Validate() error { if p.LinkPrice == nil { - return fmt.Errorf("missing link price") + return errors.New("missing link price") } if p.WethPrice == nil { - return fmt.Errorf("missing weth price") + return errors.New("missing weth price") } if p.GasPrice == nil { - return fmt.Errorf("missing gas price") + return errors.New("missing gas price") } return nil } @@ -75,7 +76,7 @@ func AddLanes(e deployment.Environment, cfg AddLanesConfig) (deployment.Changese return deployment.ChangesetOutput{}, fmt.Errorf("invalid AddLanesConfig: %w", err) } newAddresses := deployment.NewMemoryAddressBook() - err := addLanes(e, cfg) + err := addAllLanes(e, cfg) if err != nil { e.Logger.Errorw("Failed to add lanes", "err", err) return deployment.ChangesetOutput{}, err @@ -93,7 +94,7 @@ var DefaultInitialPrices = InitialPrices{ GasPrice: ToPackedFee(big.NewInt(8e14), big.NewInt(0)), } -func addLanes(e deployment.Environment, cfg AddLanesConfig) error { +func addAllLanes(e deployment.Environment, cfg AddLanesConfig) error { state, err := LoadOnchainState(e) if err != nil { return fmt.Errorf("failed to load onchain state: %w", err) diff --git a/deployment/ccip/changeset/cs_chain_contracts.go b/deployment/ccip/changeset/cs_chain_contracts.go index c2c9b3ce276..e1045fafd48 100644 --- a/deployment/ccip/changeset/cs_chain_contracts.go +++ b/deployment/ccip/changeset/cs_chain_contracts.go @@ -505,7 +505,7 @@ func UpdateRouterRamps(e deployment.Environment, cfg UpdateRouterRampsConfig) (d proposers := make(map[uint64]*gethwrappers.ManyChainMultiSig) for chainSel, update := range cfg.UpdatesByChain { txOpts := e.Chains[chainSel].DeployerKey - txOpts.Context = e.GetContext() + txOpts.Context = context.WithValue(e.GetContext(), "chainSel", chainSel) if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() } @@ -637,6 +637,9 @@ func SetOCR3OffRamp(e deployment.Environment, cfg SetOCR3OffRampConfig) (deploym state.Chains[cfg.HomeChainSel].CapabilityRegistry, state.Chains[cfg.HomeChainSel].CCIPHome, remote) + if err != nil { + return deployment.ChangesetOutput{}, err + } args, err := internal.BuildSetOCR3ConfigArgs(donID, state.Chains[cfg.HomeChainSel].CCIPHome, remote) if err != nil { return deployment.ChangesetOutput{}, err diff --git a/deployment/ccip/changeset/cs_deploy_chain.go b/deployment/ccip/changeset/cs_deploy_chain.go index 3093c65e251..381d6adb665 100644 --- a/deployment/ccip/changeset/cs_deploy_chain.go +++ b/deployment/ccip/changeset/cs_deploy_chain.go @@ -123,7 +123,7 @@ func deployChainContractsForChains( } deployGrp.Go( func() error { - err := deployChainContracts(e, chain, ab, rmnHome) + err := deployChain(e, chain, ab, rmnHome) if err != nil { e.Logger.Errorw("Failed to deploy chain contracts", "chain", chainSel, "err", err) return fmt.Errorf("failed to deploy chain contracts for chain %d: %w", chainSel, err) @@ -138,7 +138,7 @@ func deployChainContractsForChains( return nil } -func deployChainContracts( +func deployChain( e deployment.Environment, chain deployment.Chain, ab deployment.AddressBook, diff --git a/deployment/ccip/changeset/cs_deploy_chain_test.go b/deployment/ccip/changeset/cs_deploy_chain_test.go index a72b1b1568b..333f01877b3 100644 --- a/deployment/ccip/changeset/cs_deploy_chain_test.go +++ b/deployment/ccip/changeset/cs_deploy_chain_test.go @@ -28,7 +28,7 @@ func TestDeployChainContractsChangeset(t *testing.T) { homeChainSel := selectors[0] nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) require.NoError(t, err) - p2pIds := nodes.NonBootstraps().PeerIDs() + p2pIDs := nodes.NonBootstraps().PeerIDs() cfg := make(map[uint64]commontypes.MCMSWithTimelockConfig) for _, chain := range e.AllChainSelectors() { cfg[chain] = proposalutils.SingleGroupTimelockConfig(t) @@ -48,7 +48,7 @@ func TestDeployChainContractsChangeset(t *testing.T) { RMNDynamicConfig: NewTestRMNDynamicConfig(), NodeOperators: NewTestNodeOperator(e.Chains[homeChainSel].DeployerKey.From), NodeP2PIDsPerNodeOpAdmin: map[string][][32]byte{ - "NodeOperator": p2pIds, + "NodeOperator": p2pIDs, }, }, }, diff --git a/deployment/ccip/changeset/cs_home_chain.go b/deployment/ccip/changeset/cs_home_chain.go index 421885772b8..e1b1e55cbf4 100644 --- a/deployment/ccip/changeset/cs_home_chain.go +++ b/deployment/ccip/changeset/cs_home_chain.go @@ -240,21 +240,21 @@ func deployHomeChainContracts( return capReg, err } // Need to fetch nodeoperators ids to be able to add nodes for corresponding node operators - p2pIDsByNodeOpId := make(map[uint32][][32]byte) + p2pIDsByNodeOpID := make(map[uint32][][32]byte) for addedEvent.Next() { for nopName, p2pID := range nodeP2PIDsPerNodeOpAdmin { if addedEvent.Event.Name == nopName { lggr.Infow("Added node operator", "admin", addedEvent.Event.Admin, "name", addedEvent.Event.Name) - p2pIDsByNodeOpId[addedEvent.Event.NodeOperatorId] = p2pID + p2pIDsByNodeOpID[addedEvent.Event.NodeOperatorId] = p2pID } } } - if len(p2pIDsByNodeOpId) != len(nodeP2PIDsPerNodeOpAdmin) { - lggr.Errorw("Failed to add all node operators", "added", maps.Keys(p2pIDsByNodeOpId), "expected", maps.Keys(nodeP2PIDsPerNodeOpAdmin), "chain", chain.String()) + if len(p2pIDsByNodeOpID) != len(nodeP2PIDsPerNodeOpAdmin) { + lggr.Errorw("Failed to add all node operators", "added", maps.Keys(p2pIDsByNodeOpID), "expected", maps.Keys(nodeP2PIDsPerNodeOpAdmin), "chain", chain.String()) return capReg, errors.New("failed to add all node operators") } // Adds initial set of nodes to CR, who all have the CCIP capability - if err := addNodes(lggr, capReg.Contract, chain, p2pIDsByNodeOpId); err != nil { + if err := addNodes(lggr, capReg.Contract, chain, p2pIDsByNodeOpID); err != nil { return capReg, err } return capReg, nil diff --git a/deployment/ccip/changeset/cs_home_chain_test.go b/deployment/ccip/changeset/cs_home_chain_test.go index e96cd878305..a0acfb95619 100644 --- a/deployment/ccip/changeset/cs_home_chain_test.go +++ b/deployment/ccip/changeset/cs_home_chain_test.go @@ -26,14 +26,14 @@ func TestDeployHomeChain(t *testing.T) { homeChainSel := e.AllChainSelectors()[0] nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) require.NoError(t, err) - p2pIds := nodes.NonBootstraps().PeerIDs() + p2pIDs := nodes.NonBootstraps().PeerIDs() homeChainCfg := DeployHomeChainConfig{ HomeChainSel: homeChainSel, RMNStaticConfig: NewTestRMNStaticConfig(), RMNDynamicConfig: NewTestRMNDynamicConfig(), NodeOperators: NewTestNodeOperator(e.Chains[homeChainSel].DeployerKey.From), NodeP2PIDsPerNodeOpAdmin: map[string][][32]byte{ - "NodeOperator": p2pIds, + "NodeOperator": p2pIDs, }, } output, err := DeployHomeChain(e, homeChainCfg) @@ -58,7 +58,7 @@ func TestDeployHomeChain(t *testing.T) { Name: "NodeOperator", }, }, capRegSnap.Nops) - require.Len(t, capRegSnap.Nodes, len(p2pIds)) + require.Len(t, capRegSnap.Nodes, len(p2pIDs)) } func TestRemoveDonsValidate(t *testing.T) { diff --git a/deployment/ccip/changeset/internal/deploy_home_chain.go b/deployment/ccip/changeset/internal/deploy_home_chain.go index ad87acf1239..716f6eb93b2 100644 --- a/deployment/ccip/changeset/internal/deploy_home_chain.go +++ b/deployment/ccip/changeset/internal/deploy_home_chain.go @@ -75,7 +75,7 @@ func MustABIEncode(abiString string, args ...interface{}) []byte { // getNodeOperatorIDMap returns a map of node operator names to their IDs // If maxNops is greater than the number of node operators, it will return all node operators -// Unused now but could be useful in the future. +// nolint:ll Unused now but could be useful in the future. func getNodeOperatorIDMap(capReg *capabilities_registry.CapabilitiesRegistry, maxNops uint32) (map[string]uint32, error) { nopIdByName := make(map[string]uint32) operators, err := capReg.GetNodeOperators(nil) diff --git a/deployment/ccip/changeset/state.go b/deployment/ccip/changeset/state.go index b96279d8956..42aa5cbe15e 100644 --- a/deployment/ccip/changeset/state.go +++ b/deployment/ccip/changeset/state.go @@ -2,6 +2,7 @@ package changeset import ( "fmt" + "strconv" "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" @@ -366,7 +367,7 @@ func (s CCIPOnChainState) View(chains []uint64) (map[string]view.ChainView, erro } name := chainInfo.ChainName if chainInfo.ChainName == "" { - name = fmt.Sprintf("%d", chainSelector) + name = strconv.FormatUint(chainSelector, 10) } m[name] = chainView } @@ -380,12 +381,11 @@ func LoadOnchainState(e deployment.Environment) (CCIPOnChainState, error) { for chainSelector, chain := range e.Chains { addresses, err := e.ExistingAddresses.AddressesForChain(chainSelector) if err != nil { - // Chain not found in address book, initialize empty - if errors.Is(err, deployment.ErrChainNotFound) { - addresses = make(map[string]deployment.TypeAndVersion) - } else { + if !errors.Is(err, deployment.ErrChainNotFound) { return state, err } + // Chain not found in address book, initialize empty + addresses = make(map[string]deployment.TypeAndVersion) } chainState, err := LoadChainState(chain, addresses) if err != nil { diff --git a/deployment/ccip/changeset/test_environment.go b/deployment/ccip/changeset/test_environment.go index 001d95a2d77..b62bf334b52 100644 --- a/deployment/ccip/changeset/test_environment.go +++ b/deployment/ccip/changeset/test_environment.go @@ -112,7 +112,7 @@ func WithLegacyDeployment() TestOps { } } -func WithChainIds(chainIDs []uint64) TestOps { +func WithChainIDs(chainIDs []uint64) TestOps { return func(testCfg *TestConfigs) { testCfg.ChainIDs = chainIDs } diff --git a/deployment/ccip/changeset/test_helpers.go b/deployment/ccip/changeset/test_helpers.go index 5fd37dd5078..6ce97bdbbf3 100644 --- a/deployment/ccip/changeset/test_helpers.go +++ b/deployment/ccip/changeset/test_helpers.go @@ -417,11 +417,9 @@ func ToPackedFee(execFee, daFee *big.Int) *big.Int { const ( // MockLinkAggregatorDescription This is the description of the MockV3Aggregator.sol contract - //nolint:lll // https://github.com/smartcontractkit/chainlink/blob/a348b98e90527520049c580000a86fb8ceff7fa7/contracts/src/v0.8/tests/MockV3Aggregator.sol#L76-L76 MockLinkAggregatorDescription = "v0.8/tests/MockV3Aggregator.sol" // MockWETHAggregatorDescription WETH use description from MockETHUSDAggregator.sol - //nolint:lll // https://github.com/smartcontractkit/chainlink/blob/a348b98e90527520049c580000a86fb8ceff7fa7/contracts/src/v0.8/automation/testhelpers/MockETHUSDAggregator.sol#L19-L19 MockWETHAggregatorDescription = "MockETHUSDAggregator" ) diff --git a/deployment/ccip/changeset/v1_5/cs_jobspec.go b/deployment/ccip/changeset/v1_5/cs_jobspec.go index bdb36d531f8..74cb971a0b1 100644 --- a/deployment/ccip/changeset/v1_5/cs_jobspec.go +++ b/deployment/ccip/changeset/v1_5/cs_jobspec.go @@ -28,7 +28,7 @@ type JobSpecInput struct { DestEVMChainID uint64 DestinationStartBlock uint64 TokenPricesUSDPipeline string - PriceGetterConfigJson string + PriceGetterConfigJSON string USDCAttestationAPI string USDCCfg *config.USDCConfig } @@ -40,8 +40,8 @@ func (j JobSpecInput) Validate() error { if err := deployment.IsValidChainSelector(j.DestinationChainSelector); err != nil { return fmt.Errorf("DestinationChainSelector is invalid: %w", err) } - if j.TokenPricesUSDPipeline == "" && j.PriceGetterConfigJson == "" { - return fmt.Errorf("TokenPricesUSDPipeline or PriceGetterConfigJson is required") + if j.TokenPricesUSDPipeline == "" && j.PriceGetterConfigJSON == "" { + return fmt.Errorf("TokenPricesUSDPipeline or PriceGetterConfigJSON is required") } if j.USDCCfg != nil { if err := j.USDCCfg.ValidateUSDCConfig(); err != nil { @@ -95,7 +95,7 @@ func jobSpecsForLane( DestChainName: destChain.Name(), DestEvmChainId: cfg.DestEVMChainID, TokenPricesUSDPipeline: cfg.TokenPricesUSDPipeline, - PriceGetterConfig: cfg.PriceGetterConfigJson, + PriceGetterConfig: cfg.PriceGetterConfigJSON, DestStartBlock: cfg.DestinationStartBlock, USDCAttestationAPI: cfg.USDCAttestationAPI, USDCConfig: cfg.USDCCfg, diff --git a/deployment/ccip/changeset/v1_5/e2e_test.go b/deployment/ccip/changeset/v1_5/e2e_test.go index 11bb566c641..2faebecea28 100644 --- a/deployment/ccip/changeset/v1_5/e2e_test.go +++ b/deployment/ccip/changeset/v1_5/e2e_test.go @@ -19,7 +19,7 @@ func TestE2ELegacy(t *testing.T) { t, changeset.WithLegacyDeployment(), changeset.WithChains(3), - changeset.WithChainIds([]uint64{chainselectors.GETH_TESTNET.EvmChainID})) + changeset.WithChainIDs([]uint64{chainselectors.GETH_TESTNET.EvmChainID})) state, err := changeset.LoadOnchainState(e.Env) require.NoError(t, err) allChains := e.Env.AllChainSelectorsExcluding([]uint64{chainselectors.GETH_TESTNET.Selector}) diff --git a/deployment/ccip/changeset/v1_5/test_helpers.go b/deployment/ccip/changeset/v1_5/test_helpers.go index e1a03539a77..ce1b01d36d1 100644 --- a/deployment/ccip/changeset/v1_5/test_helpers.go +++ b/deployment/ccip/changeset/v1_5/test_helpers.go @@ -85,14 +85,14 @@ func LaneConfigsForChains(t *testing.T, env deployment.Environment, state change tokenPrice, _, _ := CreatePricesPipeline(t, state, src, dest) block, err := env.Chains[dest].Client.HeaderByNumber(context.Background(), nil) require.NoError(t, err) - destEVMChainIdStr, err := chain_selectors.GetChainIDFromSelector(dest) + destEVMChainIDStr, err := chain_selectors.GetChainIDFromSelector(dest) require.NoError(t, err) - destEVMChainId, err := strconv.ParseUint(destEVMChainIdStr, 10, 64) + destEVMChainID, err := strconv.ParseUint(destEVMChainIDStr, 10, 64) require.NoError(t, err) jobSpecs = append(jobSpecs, JobSpecInput{ SourceChainSelector: src, DestinationChainSelector: dest, - DestEVMChainID: destEVMChainId, + DestEVMChainID: destEVMChainID, TokenPricesUSDPipeline: tokenPrice, DestinationStartBlock: block.Number.Uint64(), }) diff --git a/deployment/ccip/view/v1_6/ccip_home_test.go b/deployment/ccip/view/v1_6/ccip_home_test.go index 26f6f50aed5..04937b9a120 100644 --- a/deployment/ccip/view/v1_6/ccip_home_test.go +++ b/deployment/ccip/view/v1_6/ccip_home_test.go @@ -33,7 +33,7 @@ func TestCCIPHomeView(t *testing.T) { v, err := GenerateCCIPHomeView(cr, ch) require.NoError(t, err) - assert.Equal(t, v.TypeAndVersion, "CCIPHome 1.6.0-dev") + assert.Equal(t, "CCIPHome 1.6.0-dev", v.TypeAndVersion) _, err = json.MarshalIndent(v, "", " ") require.NoError(t, err) diff --git a/deployment/ccip/view/v1_6/rmnhome.go b/deployment/ccip/view/v1_6/rmnhome.go index b05d15bc223..678cb204f4f 100644 --- a/deployment/ccip/view/v1_6/rmnhome.go +++ b/deployment/ccip/view/v1_6/rmnhome.go @@ -83,7 +83,7 @@ type RMNHomeSourceChain struct { } type RMNHomeNode struct { - PeerId [32]byte `json:"peerId"` + PeerID [32]byte `json:"peerId"` OffchainPublicKey [32]byte `json:"offchainPublicKey"` } @@ -94,7 +94,7 @@ func (n RMNHomeNode) MarshalJSON() ([]byte, error) { OffchainPublicKey string `json:"offchainPublicKey"` *Alias }{ - PeerId: hex.EncodeToString(n.PeerId[:]), + PeerId: hex.EncodeToString(n.PeerID[:]), OffchainPublicKey: hex.EncodeToString(n.OffchainPublicKey[:]), Alias: (*Alias)(&n), }) @@ -103,7 +103,7 @@ func (n RMNHomeNode) MarshalJSON() ([]byte, error) { func (n *RMNHomeNode) UnmarshalJSON(data []byte) error { type Alias RMNHomeNode aux := &struct { - PeerId string `json:"peerId"` + PeerID string `json:"peerId"` OffchainPublicKey string `json:"offchainPublicKey"` *Alias }{ @@ -113,11 +113,11 @@ func (n *RMNHomeNode) UnmarshalJSON(data []byte) error { return err } - peerIdBytes, err := decodeHexString(aux.PeerId, 32) + peerIDBytes, err := decodeHexString(aux.PeerID, 32) if err != nil { return err } - copy(n.PeerId[:], peerIdBytes) + copy(n.PeerID[:], peerIDBytes) offchainPublicKeyBytes, err := decodeHexString(aux.OffchainPublicKey, 32) if err != nil { @@ -134,7 +134,7 @@ func mapNodes(nodes []rmn_home.RMNHomeNode) []RMNHomeNode { result := make([]RMNHomeNode, len(nodes)) for i, node := range nodes { result[i] = RMNHomeNode{ - PeerId: node.PeerId, + PeerID: node.PeerId, OffchainPublicKey: node.OffchainPublicKey, } } From ad33c21992504b969163cfafdb0d394632eeb827 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Thu, 19 Dec 2024 11:50:07 -0800 Subject: [PATCH 5/8] updates --- deployment/ccip/changeset/cs_chain_contracts.go | 12 ++++++++---- deployment/ccip/changeset/cs_update_rmn_config.go | 4 ++-- .../ccip/changeset/cs_update_rmn_config_test.go | 6 +++--- .../ccip/changeset/internal/deploy_home_chain.go | 9 +++++---- deployment/ccip/changeset/v1_5/test_helpers.go | 8 ++++---- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/deployment/ccip/changeset/cs_chain_contracts.go b/deployment/ccip/changeset/cs_chain_contracts.go index e1045fafd48..b7fa621534c 100644 --- a/deployment/ccip/changeset/cs_chain_contracts.go +++ b/deployment/ccip/changeset/cs_chain_contracts.go @@ -102,9 +102,10 @@ func UpdateOnRampsDests(e deployment.Environment, cfg UpdateOnRampDestsConfig) ( var batches []timelock.BatchChainOperation timelocks := make(map[uint64]common.Address) proposers := make(map[uint64]*gethwrappers.ManyChainMultiSig) + ctx := e.GetContext() for chainSel, updates := range cfg.UpdatesByChain { txOpts := e.Chains[chainSel].DeployerKey - txOpts.Context = context.WithValue(e.GetContext(), "chainSel", chainSel) + txOpts.Context = ctx if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() } @@ -227,9 +228,10 @@ func UpdateFeeQuoterDests(e deployment.Environment, cfg UpdateFeeQuoterDestsConf var batches []timelock.BatchChainOperation timelocks := make(map[uint64]common.Address) proposers := make(map[uint64]*gethwrappers.ManyChainMultiSig) + ctx := e.GetContext() for chainSel, updates := range cfg.UpdatesByChain { txOpts := e.Chains[chainSel].DeployerKey - txOpts.Context = context.WithValue(e.GetContext(), "chainSel", chainSel) + txOpts.Context = ctx if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() } @@ -349,9 +351,10 @@ func UpdateOffRampSources(e deployment.Environment, cfg UpdateOffRampSourcesConf var batches []timelock.BatchChainOperation timelocks := make(map[uint64]common.Address) proposers := make(map[uint64]*gethwrappers.ManyChainMultiSig) + ctx := e.GetContext() for chainSel, updates := range cfg.UpdatesByChain { txOpts := e.Chains[chainSel].DeployerKey - txOpts.Context = context.WithValue(e.GetContext(), "chainSel", chainSel) + txOpts.Context = ctx if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() } @@ -503,9 +506,10 @@ func UpdateRouterRamps(e deployment.Environment, cfg UpdateRouterRampsConfig) (d var batches []timelock.BatchChainOperation timelocks := make(map[uint64]common.Address) proposers := make(map[uint64]*gethwrappers.ManyChainMultiSig) + ctx := e.GetContext() for chainSel, update := range cfg.UpdatesByChain { txOpts := e.Chains[chainSel].DeployerKey - txOpts.Context = context.WithValue(e.GetContext(), "chainSel", chainSel) + txOpts.Context = ctx if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() } diff --git a/deployment/ccip/changeset/cs_update_rmn_config.go b/deployment/ccip/changeset/cs_update_rmn_config.go index 5b71c162565..a58aeff38dc 100644 --- a/deployment/ccip/changeset/cs_update_rmn_config.go +++ b/deployment/ccip/changeset/cs_update_rmn_config.go @@ -126,12 +126,12 @@ type RMNNopConfig struct { NodeIndex uint64 OffchainPublicKey [32]byte EVMOnChainPublicKey common.Address - PeerId p2pkey.PeerID + PeerID p2pkey.PeerID } func (c RMNNopConfig) ToRMNHomeNode() rmn_home.RMNHomeNode { return rmn_home.RMNHomeNode{ - PeerId: c.PeerId, + PeerId: c.PeerID, OffchainPublicKey: c.OffchainPublicKey, } } diff --git a/deployment/ccip/changeset/cs_update_rmn_config_test.go b/deployment/ccip/changeset/cs_update_rmn_config_test.go index 74674e25bec..760ff25ce6a 100644 --- a/deployment/ccip/changeset/cs_update_rmn_config_test.go +++ b/deployment/ccip/changeset/cs_update_rmn_config_test.go @@ -17,19 +17,19 @@ import ( var ( rmnStaging1 = RMNNopConfig{ NodeIndex: 0, - PeerId: deployment.MustPeerIDFromString("p2p_12D3KooWRXxZq3pd4a3ZGkKj7Nt1SQQrnB8CuvbPnnV9KVeMeWqg"), + PeerID: deployment.MustPeerIDFromString("p2p_12D3KooWRXxZq3pd4a3ZGkKj7Nt1SQQrnB8CuvbPnnV9KVeMeWqg"), OffchainPublicKey: [32]byte(common.FromHex("0xb34944857a42444d1b285d7940d6e06682309e0781e43a69676ee9f85c73c2d1")), EVMOnChainPublicKey: common.HexToAddress("0x5af8ee32316a6427f169a45fdc1b3a91a85ac459e3c1cb91c69e1c51f0c1fc21"), } rmnStaging2 = RMNNopConfig{ NodeIndex: 1, - PeerId: deployment.MustPeerIDFromString("p2p_12D3KooWEmdxYQFsRbD9aFczF32zA3CcUwuSiWCk2CrmACo4v9RL"), + PeerID: deployment.MustPeerIDFromString("p2p_12D3KooWEmdxYQFsRbD9aFczF32zA3CcUwuSiWCk2CrmACo4v9RL"), OffchainPublicKey: [32]byte(common.FromHex("0x68d9f3f274e3985528a923a9bace3d39c55dd778b187b4120b384cc48c892859")), EVMOnChainPublicKey: common.HexToAddress("0x858589216956f482a0f68b282a7050af4cd48ed2"), } rmnStaging3 = RMNNopConfig{ NodeIndex: 2, - PeerId: deployment.MustPeerIDFromString("p2p_12D3KooWJS42cNXKJvj6DeZnxEX7aGxhEuap6uNFrz554AbUDw6Q"), + PeerID: deployment.MustPeerIDFromString("p2p_12D3KooWJS42cNXKJvj6DeZnxEX7aGxhEuap6uNFrz554AbUDw6Q"), OffchainPublicKey: [32]byte(common.FromHex("0x5af8ee32316a6427f169a45fdc1b3a91a85ac459e3c1cb91c69e1c51f0c1fc21")), EVMOnChainPublicKey: common.HexToAddress("0x7c5e94162c6fabbdeb3bfe83ae532846e337bfae"), } diff --git a/deployment/ccip/changeset/internal/deploy_home_chain.go b/deployment/ccip/changeset/internal/deploy_home_chain.go index 716f6eb93b2..3afb2b9cbf2 100644 --- a/deployment/ccip/changeset/internal/deploy_home_chain.go +++ b/deployment/ccip/changeset/internal/deploy_home_chain.go @@ -75,9 +75,10 @@ func MustABIEncode(abiString string, args ...interface{}) []byte { // getNodeOperatorIDMap returns a map of node operator names to their IDs // If maxNops is greater than the number of node operators, it will return all node operators -// nolint:ll Unused now but could be useful in the future. +// +//nolint:ll,unused Unused // now but could be useful in the future. func getNodeOperatorIDMap(capReg *capabilities_registry.CapabilitiesRegistry, maxNops uint32) (map[string]uint32, error) { - nopIdByName := make(map[string]uint32) + nopIDByName := make(map[string]uint32) operators, err := capReg.GetNodeOperators(nil) if err != nil { return nil, err @@ -90,9 +91,9 @@ func getNodeOperatorIDMap(capReg *capabilities_registry.CapabilitiesRegistry, ma if err != nil { return nil, err } - nopIdByName[operator.Name] = i + nopIDByName[operator.Name] = i } - return nopIdByName, nil + return nopIDByName, nil } func LatestCCIPDON(registry *capabilities_registry.CapabilitiesRegistry) (*capabilities_registry.CapabilitiesRegistryDONInfo, error) { diff --git a/deployment/ccip/changeset/v1_5/test_helpers.go b/deployment/ccip/changeset/v1_5/test_helpers.go index ce1b01d36d1..71ac75282a4 100644 --- a/deployment/ccip/changeset/v1_5/test_helpers.go +++ b/deployment/ccip/changeset/v1_5/test_helpers.go @@ -64,10 +64,10 @@ func LaneConfigsForChains(t *testing.T, env deployment.Environment, state change []ExecuteOCR2ConfigParams, []JobSpecInput, ) { - var addLanesCfg []DeployLaneConfig - var commitOCR2Configs []CommitOCR2ConfigParams - var execOCR2Configs []ExecuteOCR2ConfigParams - var jobSpecs []JobSpecInput + addLanesCfg := make([]DeployLaneConfig, 0, len(pairs)) + commitOCR2Configs := make([]CommitOCR2ConfigParams, 0, len(pairs)) + execOCR2Configs := make([]ExecuteOCR2ConfigParams, 0, len(pairs)) + jobSpecs := make([]JobSpecInput, 0, len(pairs)) for _, pair := range pairs { dest := pair.DestChainSelector src := pair.SourceChainSelector From 19b39d55feb34f0ab51237378ab77f8461fd3e85 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Thu, 19 Dec 2024 12:30:13 -0800 Subject: [PATCH 6/8] lint updates --- deployment/.golangci.yml | 4 ++++ deployment/ccip/changeset/cs_ccip_home.go | 2 +- deployment/ccip/changeset/cs_deploy_chain_test.go | 2 +- deployment/ccip/changeset/cs_prerequisites.go | 6 ++---- deployment/ccip/changeset/cs_update_rmn_config.go | 7 ++++--- .../ccip/changeset/cs_update_rmn_config_test.go | 2 +- .../ccip/changeset/internal/deploy_home_chain.go | 2 +- deployment/ccip/changeset/test_environment.go | 11 ++++++----- deployment/ccip/changeset/test_helpers.go | 5 ++--- deployment/ccip/changeset/v1_5/cs_ocr2_config.go | 8 ++++---- deployment/ccip/view/v1_0/rmn_proxy_contract.go | 3 ++- deployment/ccip/view/v1_2/price_registry.go | 3 ++- deployment/ccip/view/v1_5/commit_store.go | 3 ++- deployment/ccip/view/v1_5/offramp.go | 3 ++- deployment/ccip/view/v1_6/ccip_home.go | 3 ++- deployment/ccip/view/v1_6/rmnhome.go | 4 ++-- deployment/common/types/types.go | 7 +++++++ 17 files changed, 45 insertions(+), 30 deletions(-) diff --git a/deployment/.golangci.yml b/deployment/.golangci.yml index ff1303e26ce..24d2f9233d3 100644 --- a/deployment/.golangci.yml +++ b/deployment/.golangci.yml @@ -167,6 +167,9 @@ linters-settings: require-explanation: true issues: exclude-rules: + - text: "^var-naming: don't use an underscore in package name" + linters: + - revive - path: memory/(.+)\.go linters: - revive @@ -176,3 +179,4 @@ issues: - linters: - govet text: "declaration of \"err\" shadows" + diff --git a/deployment/ccip/changeset/cs_ccip_home.go b/deployment/ccip/changeset/cs_ccip_home.go index cfbbdedd0cb..a31c3638c4e 100644 --- a/deployment/ccip/changeset/cs_ccip_home.go +++ b/deployment/ccip/changeset/cs_ccip_home.go @@ -420,7 +420,7 @@ func AddDonAndSetCandidateChangeset( if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() } - var donOps []mcms.Operation + donOps := make([]mcms.Operation, 0) for chainSelector, params := range cfg.OCRConfigPerRemoteChainSelector { newDONArgs, err := internal.BuildOCR3ConfigForCCIPHome( e.OCRSecrets, diff --git a/deployment/ccip/changeset/cs_deploy_chain_test.go b/deployment/ccip/changeset/cs_deploy_chain_test.go index 333f01877b3..8378950121c 100644 --- a/deployment/ccip/changeset/cs_deploy_chain_test.go +++ b/deployment/ccip/changeset/cs_deploy_chain_test.go @@ -33,7 +33,7 @@ func TestDeployChainContractsChangeset(t *testing.T) { for _, chain := range e.AllChainSelectors() { cfg[chain] = proposalutils.SingleGroupTimelockConfig(t) } - var prereqCfg []DeployPrerequisiteConfigPerChain + prereqCfg := make([]DeployPrerequisiteConfigPerChain, 0) for _, chain := range e.AllChainSelectors() { prereqCfg = append(prereqCfg, DeployPrerequisiteConfigPerChain{ ChainSelector: chain, diff --git a/deployment/ccip/changeset/cs_prerequisites.go b/deployment/ccip/changeset/cs_prerequisites.go index 57489cd4649..9dd7c6b79d4 100644 --- a/deployment/ccip/changeset/cs_prerequisites.go +++ b/deployment/ccip/changeset/cs_prerequisites.go @@ -367,10 +367,8 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address e.Logger.Errorw("Failed to deploy ccip multicall", "chain", chain.String(), "err", err) return err } - } else { - if mc3 != nil { - e.Logger.Info("ccip multicall already deployed", "chain", chain.String(), "addr", mc3.Address) - } + } else if mc3 != nil { + e.Logger.Info("ccip multicall already deployed", "chain", chain.String(), "addr", mc3.Address) } if deployOpts.USDCEnabled { token, pool, messenger, transmitter, err1 := DeployUSDC(e.Logger, chain, ab, rmnProxy.Address(), r.Address()) diff --git a/deployment/ccip/changeset/cs_update_rmn_config.go b/deployment/ccip/changeset/cs_update_rmn_config.go index a58aeff38dc..b738aebb5df 100644 --- a/deployment/ccip/changeset/cs_update_rmn_config.go +++ b/deployment/ccip/changeset/cs_update_rmn_config.go @@ -14,6 +14,7 @@ import ( "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" + "github.com/smartcontractkit/chainlink/deployment/common/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_home" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_remote" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" @@ -145,9 +146,9 @@ func (c RMNNopConfig) ToRMNRemoteSigner() rmn_remote.RMNRemoteSigner { func (c RMNNopConfig) SetBit(bitmap *big.Int, value bool) { if value { - bitmap.SetBit(bitmap, int(c.NodeIndex), 1) + bitmap.SetBit(bitmap, types.MustGetInt(c.NodeIndex), 1) } else { - bitmap.SetBit(bitmap, int(c.NodeIndex), 0) + bitmap.SetBit(bitmap, types.MustGetInt(c.NodeIndex), 0) } } @@ -472,7 +473,7 @@ func (c SetRMNRemoteConfig) Validate() error { } } - if len(config.Signers) < 2*int(config.F)+1 { + if len(config.Signers) < 2*types.MustGetInt(config.F)+1 { return fmt.Errorf("signers count (%d) must be greater than or equal to %d", len(config.Signers), 2*config.F+1) } } diff --git a/deployment/ccip/changeset/cs_update_rmn_config_test.go b/deployment/ccip/changeset/cs_update_rmn_config_test.go index 760ff25ce6a..0b2c989944a 100644 --- a/deployment/ccip/changeset/cs_update_rmn_config_test.go +++ b/deployment/ccip/changeset/cs_update_rmn_config_test.go @@ -225,7 +225,7 @@ func TestSetRMNRemoteOnRMNProxy(t *testing.T) { allChains := e.Env.AllChainSelectors() mcmsCfg := make(map[uint64]commontypes.MCMSWithTimelockConfig) var err error - var prereqCfgs []DeployPrerequisiteConfigPerChain + prereqCfgs := make([]DeployPrerequisiteConfigPerChain, 0, len(e.Env.AllChainSelectors())) for _, c := range e.Env.AllChainSelectors() { mcmsCfg[c] = proposalutils.SingleGroupTimelockConfig(t) prereqCfgs = append(prereqCfgs, DeployPrerequisiteConfigPerChain{ diff --git a/deployment/ccip/changeset/internal/deploy_home_chain.go b/deployment/ccip/changeset/internal/deploy_home_chain.go index 3afb2b9cbf2..e35d6283790 100644 --- a/deployment/ccip/changeset/internal/deploy_home_chain.go +++ b/deployment/ccip/changeset/internal/deploy_home_chain.go @@ -76,7 +76,7 @@ func MustABIEncode(abiString string, args ...interface{}) []byte { // getNodeOperatorIDMap returns a map of node operator names to their IDs // If maxNops is greater than the number of node operators, it will return all node operators // -//nolint:ll,unused Unused // now but could be useful in the future. +//nolint:ll,unused // could be useful in the future. func getNodeOperatorIDMap(capReg *capabilities_registry.CapabilitiesRegistry, maxNops uint32) (map[string]uint32, error) { nopIDByName := make(map[string]uint32) operators, err := capReg.GetNodeOperators(nil) diff --git a/deployment/ccip/changeset/test_environment.go b/deployment/ccip/changeset/test_environment.go index b62bf334b52..7307d10ab3a 100644 --- a/deployment/ccip/changeset/test_environment.go +++ b/deployment/ccip/changeset/test_environment.go @@ -77,11 +77,12 @@ func (tc *TestConfigs) Validate() error { func (tc *TestConfigs) MustSetEnvTypeOrDefault(t *testing.T) { envType := os.Getenv(ENVTESTTYPE) - if envType == "" || envType == string(Memory) { + switch envType { + case string(Memory): tc.Type = Memory - } else if envType == string(Docker) { + case string(Docker): tc.Type = Docker - } else { + default: t.Fatalf("env var CCIP_V16_TEST_ENV must be either %s or %s, defaults to %s if unset, got: %s", Memory, Docker, Memory, envType) } } @@ -330,7 +331,7 @@ func NewLegacyEnvironment(t *testing.T, tc *TestConfigs, tEnv TestEnvironment) D for _, c := range e.Env.AllChainSelectors() { mcmsCfg[c] = proposalutils.SingleGroupTimelockConfig(t) } - var prereqCfg []DeployPrerequisiteConfigPerChain + prereqCfg := make([]DeployPrerequisiteConfigPerChain, 0) for _, chain := range allChains { var opts []PrerequisiteOpt if tc != nil { @@ -408,7 +409,7 @@ func NewEnvironmentWithJobsAndContracts(t *testing.T, tc *TestConfigs, tEnv Test mcmsCfg[c] = proposalutils.SingleGroupTimelockConfig(t) } - var prereqCfg []DeployPrerequisiteConfigPerChain + prereqCfg := make([]DeployPrerequisiteConfigPerChain, 0) for _, chain := range allChains { var opts []PrerequisiteOpt if tc != nil { diff --git a/deployment/ccip/changeset/test_helpers.go b/deployment/ccip/changeset/test_helpers.go index 6ce97bdbbf3..7141f54b45b 100644 --- a/deployment/ccip/changeset/test_helpers.go +++ b/deployment/ccip/changeset/test_helpers.go @@ -66,8 +66,7 @@ var ( func Context(tb testing.TB) context.Context { ctx := context.Background() var cancel func() - switch t := tb.(type) { - case *testing.T: + if t := tb.(*testing.T); t != nil { if d, ok := t.Deadline(); ok { ctx, cancel = context.WithDeadline(ctx, d) } @@ -134,7 +133,7 @@ func LatestBlocksByChain(ctx context.Context, chains map[uint64]deployment.Chain func allocateCCIPChainSelectors(chains map[uint64]deployment.Chain) (homeChainSel uint64, feeChainSel uint64) { // Lower chainSel is home chain. - var chainSels []uint64 + chainSels := make([]uint64, 0) // Say first chain is home chain. for chainSel := range chains { chainSels = append(chainSels, chainSel) diff --git a/deployment/ccip/changeset/v1_5/cs_ocr2_config.go b/deployment/ccip/changeset/v1_5/cs_ocr2_config.go index 497bcb53ad8..aa95126a9a6 100644 --- a/deployment/ccip/changeset/v1_5/cs_ocr2_config.go +++ b/deployment/ccip/changeset/v1_5/cs_ocr2_config.go @@ -259,8 +259,8 @@ func deriveOCR2Config( } nodes := nodeInfo.NonBootstraps() // Get OCR3 Config from helper - var schedule []int - var oracles []confighelper.OracleIdentityExtra + schedule := make([]int, 0, len(nodes)) + oracles := make([]confighelper.OracleIdentityExtra, 0, len(nodes)) for _, node := range nodes { schedule = append(schedule, 1) cfg, exists := node.OCRConfigForChainSelector(chainSel) @@ -300,14 +300,14 @@ func deriveOCR2Config( if err != nil { return FinalOCR2Config{}, fmt.Errorf("failed to derive OCR2 config: %w", err) } - var signersAddresses []common.Address + signersAddresses := make([]common.Address, 0, len(signers)) for _, signer := range signers { if len(signer) != 20 { return FinalOCR2Config{}, fmt.Errorf("address is not 20 bytes %s", signer) } signersAddresses = append(signersAddresses, common.BytesToAddress(signer)) } - var transmittersAddresses []common.Address + transmittersAddresses := make([]common.Address, 0, len(transmitters)) for _, transmitter := range transmitters { bytes, err := hexutil.Decode(string(transmitter)) if err != nil { diff --git a/deployment/ccip/view/v1_0/rmn_proxy_contract.go b/deployment/ccip/view/v1_0/rmn_proxy_contract.go index 6c628281399..b407b8f73d3 100644 --- a/deployment/ccip/view/v1_0/rmn_proxy_contract.go +++ b/deployment/ccip/view/v1_0/rmn_proxy_contract.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/ethereum/go-ethereum/common" + "github.com/pkg/errors" "github.com/smartcontractkit/chainlink/deployment/common/view/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_proxy_contract" @@ -16,7 +17,7 @@ type RMNProxyView struct { func GenerateRMNProxyView(r *rmn_proxy_contract.RMNProxyContract) (RMNProxyView, error) { if r == nil { - return RMNProxyView{}, fmt.Errorf("cannot generate view for nil RMNProxy") + return RMNProxyView{}, errors.New("cannot generate view for nil RMNProxy") } meta, err := types.NewContractMetaData(r, r.Address()) if err != nil { diff --git a/deployment/ccip/view/v1_2/price_registry.go b/deployment/ccip/view/v1_2/price_registry.go index ee0f1067b6c..269c48fccaf 100644 --- a/deployment/ccip/view/v1_2/price_registry.go +++ b/deployment/ccip/view/v1_2/price_registry.go @@ -1,6 +1,7 @@ package v1_2 import ( + "errors" "fmt" "github.com/ethereum/go-ethereum/common" @@ -18,7 +19,7 @@ type PriceRegistryView struct { func GeneratePriceRegistryView(pr *price_registry_1_2_0.PriceRegistry) (PriceRegistryView, error) { if pr == nil { - return PriceRegistryView{}, fmt.Errorf("cannot generate view for nil PriceRegistry") + return PriceRegistryView{}, errors.New("cannot generate view for nil PriceRegistry") } meta, err := types.NewContractMetaData(pr, pr.Address()) if err != nil { diff --git a/deployment/ccip/view/v1_5/commit_store.go b/deployment/ccip/view/v1_5/commit_store.go index ffea3b61f5f..9da3a4cfc38 100644 --- a/deployment/ccip/view/v1_5/commit_store.go +++ b/deployment/ccip/view/v1_5/commit_store.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/ethereum/go-ethereum/common" + "github.com/pkg/errors" "github.com/smartcontractkit/chainlink/deployment/common/view/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/commit_store" @@ -24,7 +25,7 @@ type CommitStoreView struct { func GenerateCommitStoreView(c *commit_store.CommitStore) (CommitStoreView, error) { if c == nil { - return CommitStoreView{}, fmt.Errorf("cannot generate view for nil CommitStore") + return CommitStoreView{}, errors.New("cannot generate view for nil CommitStore") } meta, err := types.NewContractMetaData(c, c.Address()) if err != nil { diff --git a/deployment/ccip/view/v1_5/offramp.go b/deployment/ccip/view/v1_5/offramp.go index 95e40d9da27..95d92c445e4 100644 --- a/deployment/ccip/view/v1_5/offramp.go +++ b/deployment/ccip/view/v1_5/offramp.go @@ -1,6 +1,7 @@ package v1_5 import ( + "errors" "fmt" "github.com/smartcontractkit/chainlink/deployment/common/view/types" @@ -15,7 +16,7 @@ type OffRampView struct { func GenerateOffRampView(r *evm_2_evm_offramp.EVM2EVMOffRamp) (OffRampView, error) { if r == nil { - return OffRampView{}, fmt.Errorf("cannot generate view for nil OffRamp") + return OffRampView{}, errors.New("cannot generate view for nil OffRamp") } meta, err := types.NewContractMetaData(r, r.Address()) if err != nil { diff --git a/deployment/ccip/view/v1_6/ccip_home.go b/deployment/ccip/view/v1_6/ccip_home.go index ac1e23179c4..4d74bdfc79e 100644 --- a/deployment/ccip/view/v1_6/ccip_home.go +++ b/deployment/ccip/view/v1_6/ccip_home.go @@ -1,6 +1,7 @@ package v1_6 import ( + "errors" "fmt" "math/big" @@ -33,7 +34,7 @@ type CCIPHomeView struct { func GenerateCCIPHomeView(cr *capabilities_registry.CapabilitiesRegistry, ch *ccip_home.CCIPHome) (CCIPHomeView, error) { if ch == nil { - return CCIPHomeView{}, fmt.Errorf("cannot generate view for nil CCIPHome") + return CCIPHomeView{}, errors.New("cannot generate view for nil CCIPHome") } meta, err := types.NewContractMetaData(ch, ch.Address()) if err != nil { diff --git a/deployment/ccip/view/v1_6/rmnhome.go b/deployment/ccip/view/v1_6/rmnhome.go index 678cb204f4f..3aaac8c8a4a 100644 --- a/deployment/ccip/view/v1_6/rmnhome.go +++ b/deployment/ccip/view/v1_6/rmnhome.go @@ -90,11 +90,11 @@ type RMNHomeNode struct { func (n RMNHomeNode) MarshalJSON() ([]byte, error) { type Alias RMNHomeNode return json.Marshal(&struct { - PeerId string `json:"peerId"` + PeerID string `json:"peerId"` OffchainPublicKey string `json:"offchainPublicKey"` *Alias }{ - PeerId: hex.EncodeToString(n.PeerID[:]), + PeerID: hex.EncodeToString(n.PeerID[:]), OffchainPublicKey: hex.EncodeToString(n.OffchainPublicKey[:]), Alias: (*Alias)(&n), }) diff --git a/deployment/common/types/types.go b/deployment/common/types/types.go index 0f04421af43..69c6326213b 100644 --- a/deployment/common/types/types.go +++ b/deployment/common/types/types.go @@ -89,3 +89,10 @@ func (params OCRParameters) Validate() error { } return nil } + +func MustGetInt(num uint64) int { + if num > uint64(int(^uint(0)>>1)) { + panic(fmt.Sprintf("Number %d is too large to convert to int", num)) + } + return int(num) +} From 15a89f3b779a2e6b64ec1e557a79b20850f4ef1a Mon Sep 17 00:00:00 2001 From: AnieeG Date: Thu, 19 Dec 2024 12:50:48 -0800 Subject: [PATCH 7/8] changes --- deployment/ccip/changeset/cs_add_lane.go | 4 ++-- deployment/ccip/changeset/cs_ccip_home.go | 17 +++++++++-------- .../changeset/internal/deploy_home_chain.go | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/deployment/ccip/changeset/cs_add_lane.go b/deployment/ccip/changeset/cs_add_lane.go index c3424f97e9c..da831f632a2 100644 --- a/deployment/ccip/changeset/cs_add_lane.go +++ b/deployment/ccip/changeset/cs_add_lane.go @@ -53,14 +53,14 @@ type AddLanesConfig struct { func (c AddLanesConfig) Validate() error { for _, pair := range c.LaneConfigs { if pair.SourceSelector == pair.DestSelector { - return fmt.Errorf("cannot add lane to the same chain") + return errors.New("cannot add lane to the same chain") } if err := pair.InitialPricesBySource.Validate(); err != nil { return fmt.Errorf("error in validating initial prices for chain %d : %w", pair.SourceSelector, err) } // TODO: add more FeeQuoterDestChainConfigArgs validation if pair.FeeQuoterDestChain == (fee_quoter.FeeQuoterDestChainConfig{}) { - return fmt.Errorf("missing fee quoter dest chain config") + return errors.New("missing fee quoter dest chain config") } } return nil diff --git a/deployment/ccip/changeset/cs_ccip_home.go b/deployment/ccip/changeset/cs_ccip_home.go index a31c3638c4e..1d6eaaa9292 100644 --- a/deployment/ccip/changeset/cs_ccip_home.go +++ b/deployment/ccip/changeset/cs_ccip_home.go @@ -3,6 +3,7 @@ package changeset import ( "bytes" "encoding/hex" + "errors" "fmt" "math/big" "os" @@ -139,10 +140,10 @@ func (p PromoteAllCandidatesChangesetConfig) Validate(e deployment.Environment) if p.PluginType != types.PluginTypeCCIPCommit && p.PluginType != types.PluginTypeCCIPExec { - return nil, fmt.Errorf("PluginType must be set to either CCIPCommit or CCIPExec") + return nil, errors.New("PluginType must be set to either CCIPCommit or CCIPExec") } - var donIDs []uint32 + donIDs := make([]uint32, 0) for _, chainSelector := range p.RemoteChainSelectors { if err := deployment.IsValidChainSelector(chainSelector); err != nil { return nil, fmt.Errorf("don chain selector invalid: %w", err) @@ -153,7 +154,7 @@ func (p PromoteAllCandidatesChangesetConfig) Validate(e deployment.Environment) } if chainState.OffRamp == nil { // should not be possible, but a defensive check. - return nil, fmt.Errorf("OffRamp contract does not exist") + return nil, errors.New("OffRamp contract does not exist") } donID, err := internal.DonIDForChain( @@ -182,13 +183,13 @@ func (p PromoteAllCandidatesChangesetConfig) Validate(e deployment.Environment) donIDs = append(donIDs, donID) } if len(e.NodeIDs) == 0 { - return nil, fmt.Errorf("NodeIDs must be set") + return nil, errors.New("NodeIDs must be set") } if state.Chains[p.HomeChainSelector].CCIPHome == nil { - return nil, fmt.Errorf("CCIPHome contract does not exist") + return nil, errors.New("CCIPHome contract does not exist") } if state.Chains[p.HomeChainSelector].CapabilityRegistry == nil { - return nil, fmt.Errorf("CapabilityRegistry contract does not exist") + return nil, errors.New("CapabilityRegistry contract does not exist") } return donIDs, nil @@ -224,7 +225,7 @@ func PromoteAllCandidatesChangeset( homeChain := e.Chains[cfg.HomeChainSelector] - var ops []mcms.Operation + ops := make([]mcms.Operation, 0) for _, donID := range donIDs { promoteCandidateOps, err := promoteAllCandidatesForChainOps( txOpts, @@ -1064,7 +1065,7 @@ func UpdateChainConfig(e deployment.Environment, cfg UpdateChainConfigConfig) (d if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() } - var adds []ccip_home.CCIPHomeChainConfigArgs + adds := make([]ccip_home.CCIPHomeChainConfigArgs, 0) for chain, ccfg := range cfg.RemoteChainAdds { encodedChainConfig, err := chainconfig.EncodeChainConfig(chainconfig.ChainConfig{ GasPriceDeviationPPB: ccfg.EncodableChainConfig.GasPriceDeviationPPB, diff --git a/deployment/ccip/changeset/internal/deploy_home_chain.go b/deployment/ccip/changeset/internal/deploy_home_chain.go index e35d6283790..c86137379c6 100644 --- a/deployment/ccip/changeset/internal/deploy_home_chain.go +++ b/deployment/ccip/changeset/internal/deploy_home_chain.go @@ -160,7 +160,7 @@ func BuildSetOCR3ConfigArgs( ccipHome *ccip_home.CCIPHome, destSelector uint64, ) ([]offramp.MultiOCR3BaseOCRConfigArgs, error) { - var offrampOCR3Configs []offramp.MultiOCR3BaseOCRConfigArgs + offrampOCR3Configs := make([]offramp.MultiOCR3BaseOCRConfigArgs, 0) for _, pluginType := range []types.PluginType{types.PluginTypeCCIPCommit, types.PluginTypeCCIPExec} { ocrConfig, err2 := ccipHome.GetAllConfigs(&bind.CallOpts{ Context: context.Background(), @@ -209,8 +209,8 @@ func BuildOCR3ConfigForCCIPHome( ) (map[types.PluginType]ccip_home.CCIPHomeOCR3Config, error) { p2pIDs := nodes.PeerIDs() // Get OCR3 Config from helper - var schedule []int - var oracles []confighelper.OracleIdentityExtra + schedule := make([]int, 0) + oracles := make([]confighelper.OracleIdentityExtra, 0) for _, node := range nodes { schedule = append(schedule, 1) cfg, exists := node.OCRConfigForChainSelector(dest.Selector) From 971ae72476d406d4e401e5e2bb1001103503ebf4 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Thu, 19 Dec 2024 13:26:41 -0800 Subject: [PATCH 8/8] update ccip lint --- deployment/ccip/changeset/cs_ccip_home.go | 32 +++++++++---------- .../ccip/changeset/cs_chain_contracts.go | 13 ++------ deployment/ccip/changeset/cs_deploy_chain.go | 7 ++-- deployment/ccip/changeset/cs_home_chain.go | 18 +++++------ .../ccip/changeset/cs_update_rmn_config.go | 7 ++-- .../changeset/internal/deploy_home_chain.go | 8 ++++- deployment/ccip/changeset/test_assertions.go | 3 +- deployment/ccip/changeset/test_environment.go | 18 +++++++---- deployment/ccip/changeset/test_helpers.go | 2 +- deployment/ccip/changeset/v1_5/cs_jobspec.go | 5 +-- .../ccip/changeset/v1_5/test_helpers.go | 6 ++-- deployment/ccip/view/v1_5/onramp.go | 3 +- deployment/ccip/view/v1_5/rmn.go | 3 +- .../ccip/view/v1_5/tokenadminregistry.go | 3 +- deployment/ccip/view/v1_6/ccip_home.go | 2 +- 15 files changed, 72 insertions(+), 58 deletions(-) diff --git a/deployment/ccip/changeset/cs_ccip_home.go b/deployment/ccip/changeset/cs_ccip_home.go index 1d6eaaa9292..b5853045d46 100644 --- a/deployment/ccip/changeset/cs_ccip_home.go +++ b/deployment/ccip/changeset/cs_ccip_home.go @@ -317,7 +317,7 @@ func (s SetCandidateConfigBase) Validate(e deployment.Environment, state CCIPOnC } if s.PluginType != types.PluginTypeCCIPCommit && s.PluginType != types.PluginTypeCCIPExec { - return fmt.Errorf("PluginType must be set to either CCIPCommit or CCIPExec") + return errors.New("PluginType must be set to either CCIPCommit or CCIPExec") } // no donID check since this config is used for both adding a new DON and updating an existing one. @@ -341,17 +341,17 @@ func (s SetCandidateConfigBase) Validate(e deployment.Environment, state CCIPOnC // TODO: validate gas config in the chain config in cciphome for this RemoteChainSelectors. } if len(e.NodeIDs) == 0 { - return fmt.Errorf("nodeIDs must be set") + return errors.New("nodeIDs must be set") } if state.Chains[s.HomeChainSelector].CCIPHome == nil { - return fmt.Errorf("CCIPHome contract does not exist") + return errors.New("CCIPHome contract does not exist") } if state.Chains[s.HomeChainSelector].CapabilityRegistry == nil { - return fmt.Errorf("CapabilityRegistry contract does not exist") + return errors.New("CapabilityRegistry contract does not exist") } if e.OCRSecrets.IsEmpty() { - return fmt.Errorf("OCR secrets must be set") + return errors.New("OCR secrets must be set") } return nil @@ -444,7 +444,7 @@ func AddDonAndSetCandidateChangeset( pluginOCR3Config, ok := newDONArgs[cfg.PluginType] if !ok { - return deployment.ChangesetOutput{}, fmt.Errorf("missing commit plugin in ocr3Configs") + return deployment.ChangesetOutput{}, errors.New("missing commit plugin in ocr3Configs") } expectedDonID := latestDon.Id + 1 @@ -672,7 +672,7 @@ func setCandidateOnExistingDon( mcmsEnabled bool, ) ([]mcms.Operation, error) { if donID == 0 { - return nil, fmt.Errorf("donID is zero") + return nil, errors.New("donID is zero") } encodedSetCandidateCall, err := internal.CCIPHomeABI.Pack( @@ -792,7 +792,7 @@ func promoteAllCandidatesForChainOps( mcmsEnabled bool, ) (mcms.Operation, error) { if donID == 0 { - return mcms.Operation{}, fmt.Errorf("donID is zero") + return mcms.Operation{}, errors.New("donID is zero") } updatePluginOp, err := promoteCandidateOp( @@ -832,13 +832,13 @@ func (r RevokeCandidateChangesetConfig) Validate(e deployment.Environment, state return 0, fmt.Errorf("don chain selector invalid: %w", err) } if len(e.NodeIDs) == 0 { - return 0, fmt.Errorf("NodeIDs must be set") + return 0, errors.New("NodeIDs must be set") } if state.Chains[r.HomeChainSelector].CCIPHome == nil { - return 0, fmt.Errorf("CCIPHome contract does not exist") + return 0, errors.New("CCIPHome contract does not exist") } if state.Chains[r.HomeChainSelector].CapabilityRegistry == nil { - return 0, fmt.Errorf("CapabilityRegistry contract does not exist") + return 0, errors.New("CapabilityRegistry contract does not exist") } homeChainState, exists := state.Chains[r.HomeChainSelector] if !exists { @@ -867,7 +867,7 @@ func (r RevokeCandidateChangesetConfig) Validate(e deployment.Environment, state return 0, fmt.Errorf("fetching candidate digest from cciphome: %w", err) } if candidateDigest == [32]byte{} { - return 0, fmt.Errorf("candidate config digest is zero, can't revoke it") + return 0, errors.New("candidate config digest is zero, can't revoke it") } return donID, nil @@ -948,7 +948,7 @@ func revokeCandidateOps( mcmsEnabled bool, ) ([]mcms.Operation, error) { if donID == 0 { - return nil, fmt.Errorf("donID is zero") + return nil, errors.New("donID is zero") } candidateDigest, err := ccipHome.GetCandidateDigest(nil, donID, pluginType) @@ -1018,7 +1018,7 @@ func (c UpdateChainConfigConfig) Validate(e deployment.Environment) error { return fmt.Errorf("home chain selector invalid: %w", err) } if len(c.RemoteChainRemoves) == 0 && len(c.RemoteChainAdds) == 0 { - return fmt.Errorf("no chain adds or removes") + return errors.New("no chain adds or removes") } homeChainState, exists := state.Chains[c.HomeChainSelector] if !exists { @@ -1043,10 +1043,10 @@ func (c UpdateChainConfigConfig) Validate(e deployment.Environment) error { return fmt.Errorf("chain to add %d is not supported", add) } if ccfg.FChain == 0 { - return fmt.Errorf("FChain must be set") + return errors.New("FChain must be set") } if len(ccfg.Readers) == 0 { - return fmt.Errorf("Readers must be set") + return errors.New("Readers must be set") } } return nil diff --git a/deployment/ccip/changeset/cs_chain_contracts.go b/deployment/ccip/changeset/cs_chain_contracts.go index b7fa621534c..42f1171001f 100644 --- a/deployment/ccip/changeset/cs_chain_contracts.go +++ b/deployment/ccip/changeset/cs_chain_contracts.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/hex" + "errors" "fmt" "math/big" @@ -81,7 +82,7 @@ func (cfg UpdateOnRampDestsConfig) Validate(e deployment.Environment) error { return fmt.Errorf("failed to get onramp static config %s: %w", chainState.OnRamp.Address(), err) } if destination == sc.ChainSelector { - return fmt.Errorf("cannot update onramp destination to the same chain") + return errors.New("cannot update onramp destination to the same chain") } } } @@ -102,10 +103,8 @@ func UpdateOnRampsDests(e deployment.Environment, cfg UpdateOnRampDestsConfig) ( var batches []timelock.BatchChainOperation timelocks := make(map[uint64]common.Address) proposers := make(map[uint64]*gethwrappers.ManyChainMultiSig) - ctx := e.GetContext() for chainSel, updates := range cfg.UpdatesByChain { txOpts := e.Chains[chainSel].DeployerKey - txOpts.Context = ctx if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() } @@ -210,7 +209,7 @@ func (cfg UpdateFeeQuoterDestsConfig) Validate(e deployment.Environment) error { return fmt.Errorf("failed to get onramp static config %s: %w", chainState.OnRamp.Address(), err) } if destination == sc.ChainSelector { - return fmt.Errorf("cannot update onramp destination to the same chain") + return errors.New("cannot update onramp destination to the same chain") } } } @@ -228,10 +227,8 @@ func UpdateFeeQuoterDests(e deployment.Environment, cfg UpdateFeeQuoterDestsConf var batches []timelock.BatchChainOperation timelocks := make(map[uint64]common.Address) proposers := make(map[uint64]*gethwrappers.ManyChainMultiSig) - ctx := e.GetContext() for chainSel, updates := range cfg.UpdatesByChain { txOpts := e.Chains[chainSel].DeployerKey - txOpts.Context = ctx if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() } @@ -351,10 +348,8 @@ func UpdateOffRampSources(e deployment.Environment, cfg UpdateOffRampSourcesConf var batches []timelock.BatchChainOperation timelocks := make(map[uint64]common.Address) proposers := make(map[uint64]*gethwrappers.ManyChainMultiSig) - ctx := e.GetContext() for chainSel, updates := range cfg.UpdatesByChain { txOpts := e.Chains[chainSel].DeployerKey - txOpts.Context = ctx if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() } @@ -506,10 +501,8 @@ func UpdateRouterRamps(e deployment.Environment, cfg UpdateRouterRampsConfig) (d var batches []timelock.BatchChainOperation timelocks := make(map[uint64]common.Address) proposers := make(map[uint64]*gethwrappers.ManyChainMultiSig) - ctx := e.GetContext() for chainSel, update := range cfg.UpdatesByChain { txOpts := e.Chains[chainSel].DeployerKey - txOpts.Context = ctx if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() } diff --git a/deployment/ccip/changeset/cs_deploy_chain.go b/deployment/ccip/changeset/cs_deploy_chain.go index 381d6adb665..9ca27817b63 100644 --- a/deployment/ccip/changeset/cs_deploy_chain.go +++ b/deployment/ccip/changeset/cs_deploy_chain.go @@ -1,6 +1,7 @@ package changeset import ( + "errors" "fmt" "math/big" @@ -81,7 +82,7 @@ func deployChainContractsForChains( capReg := existingState.Chains[homeChainSel].CapabilityRegistry if capReg == nil { e.Logger.Errorw("Failed to get capability registry") - return fmt.Errorf("capability registry not found") + return errors.New("capability registry not found") } cr, err := capReg.GetHashedCapabilityId( &bind.CallOpts{}, internal.CapabilityLabelledName, internal.CapabilityVersion) @@ -105,12 +106,12 @@ func deployChainContractsForChains( return err } if ccipHome.Address() != existingState.Chains[homeChainSel].CCIPHome.Address() { - return fmt.Errorf("ccip home address mismatch") + return errors.New("ccip home address mismatch") } rmnHome := existingState.Chains[homeChainSel].RMNHome if rmnHome == nil { e.Logger.Errorw("Failed to get rmn home", "err", err) - return fmt.Errorf("rmn home not found") + return errors.New("rmn home not found") } deployGrp := errgroup.Group{} for _, chainSel := range chainsToDeploy { diff --git a/deployment/ccip/changeset/cs_home_chain.go b/deployment/ccip/changeset/cs_home_chain.go index e1b1e55cbf4..4f195716448 100644 --- a/deployment/ccip/changeset/cs_home_chain.go +++ b/deployment/ccip/changeset/cs_home_chain.go @@ -62,23 +62,23 @@ type DeployHomeChainConfig struct { func (c DeployHomeChainConfig) Validate() error { if c.HomeChainSel == 0 { - return fmt.Errorf("home chain selector must be set") + return errors.New("home chain selector must be set") } if c.RMNDynamicConfig.OffchainConfig == nil { - return fmt.Errorf("offchain config for RMNHomeDynamicConfig must be set") + return errors.New("offchain config for RMNHomeDynamicConfig must be set") } if c.RMNStaticConfig.OffchainConfig == nil { - return fmt.Errorf("offchain config for RMNHomeStaticConfig must be set") + return errors.New("offchain config for RMNHomeStaticConfig must be set") } if len(c.NodeOperators) == 0 { - return fmt.Errorf("node operators must be set") + return errors.New("node operators must be set") } for _, nop := range c.NodeOperators { if nop.Admin == (common.Address{}) { - return fmt.Errorf("node operator admin address must be set") + return errors.New("node operator admin address must be set") } if nop.Name == "" { - return fmt.Errorf("node operator name must be set") + return errors.New("node operator name must be set") } if len(c.NodeP2PIDsPerNodeOpAdmin[nop.Name]) == 0 { return fmt.Errorf("node operator %s must have node p2p ids provided", nop.Name) @@ -339,14 +339,14 @@ func (c RemoveDONsConfig) Validate(homeChain CCIPChainState) error { return fmt.Errorf("home chain selector must be set %w", err) } if len(c.DonIDs) == 0 { - return fmt.Errorf("don ids must be set") + return errors.New("don ids must be set") } // Cap reg must exist if homeChain.CapabilityRegistry == nil { - return fmt.Errorf("cap reg does not exist") + return errors.New("cap reg does not exist") } if homeChain.CCIPHome == nil { - return fmt.Errorf("ccip home does not exist") + return errors.New("ccip home does not exist") } return internal.DONIdExists(homeChain.CapabilityRegistry, c.DonIDs) } diff --git a/deployment/ccip/changeset/cs_update_rmn_config.go b/deployment/ccip/changeset/cs_update_rmn_config.go index b738aebb5df..d8dc9e45876 100644 --- a/deployment/ccip/changeset/cs_update_rmn_config.go +++ b/deployment/ccip/changeset/cs_update_rmn_config.go @@ -1,6 +1,7 @@ package changeset import ( + "errors" "fmt" "math/big" "reflect" @@ -179,14 +180,14 @@ func (c SetRMNHomeCandidateConfig) Validate(state CCIPOnChainState) error { } if len(c.RMNDynamicConfig.OffchainConfig) != 0 { - return fmt.Errorf("RMNDynamicConfig.OffchainConfig must be empty") + return errors.New("RMNDynamicConfig.OffchainConfig must be empty") } if len(c.RMNStaticConfig.OffchainConfig) != 0 { - return fmt.Errorf("RMNStaticConfig.OffchainConfig must be empty") + return errors.New("RMNStaticConfig.OffchainConfig must be empty") } if len(c.RMNStaticConfig.Nodes) > 256 { - return fmt.Errorf("RMNStaticConfig.Nodes must be less than 256") + return errors.New("RMNStaticConfig.Nodes must be less than 256") } var ( diff --git a/deployment/ccip/changeset/internal/deploy_home_chain.go b/deployment/ccip/changeset/internal/deploy_home_chain.go index c86137379c6..2c05e144542 100644 --- a/deployment/ccip/changeset/internal/deploy_home_chain.go +++ b/deployment/ccip/changeset/internal/deploy_home_chain.go @@ -2,7 +2,9 @@ package internal import ( "context" + "errors" "fmt" + "math" "time" "github.com/ethereum/go-ethereum/accounts/abi" @@ -76,7 +78,7 @@ func MustABIEncode(abiString string, args ...interface{}) []byte { // getNodeOperatorIDMap returns a map of node operator names to their IDs // If maxNops is greater than the number of node operators, it will return all node operators // -//nolint:ll,unused // could be useful in the future. +//nolint:unused // could be useful in the future. func getNodeOperatorIDMap(capReg *capabilities_registry.CapabilitiesRegistry, maxNops uint32) (map[string]uint32, error) { nopIDByName := make(map[string]uint32) operators, err := capReg.GetNodeOperators(nil) @@ -84,6 +86,10 @@ func getNodeOperatorIDMap(capReg *capabilities_registry.CapabilitiesRegistry, ma return nil, err } if len(operators) < int(maxNops) { + if len(operators) >= math.MaxUint32 { + return nil, errors.New("len(operators) exceeds max uint32 value") + } + //nolint:gosec // already checked that len(operators) < math.MaxUint32 maxNops = uint32(len(operators)) } for i := uint32(1); i <= maxNops; i++ { diff --git a/deployment/ccip/changeset/test_assertions.go b/deployment/ccip/changeset/test_assertions.go index 9a53fec5c9b..0e445f93a9b 100644 --- a/deployment/ccip/changeset/test_assertions.go +++ b/deployment/ccip/changeset/test_assertions.go @@ -2,6 +2,7 @@ package changeset import ( "context" + "errors" "fmt" "math/big" "sync" @@ -485,7 +486,7 @@ func ConfirmExecWithSeqNrs( expectedSeqNrs []uint64, ) (executionStates map[uint64]int, err error) { if len(expectedSeqNrs) == 0 { - return nil, fmt.Errorf("no expected sequence numbers provided") + return nil, errors.New("no expected sequence numbers provided") } timer := time.NewTimer(8 * time.Minute) diff --git a/deployment/ccip/changeset/test_environment.go b/deployment/ccip/changeset/test_environment.go index 7307d10ab3a..db7b3e340ca 100644 --- a/deployment/ccip/changeset/test_environment.go +++ b/deployment/ccip/changeset/test_environment.go @@ -2,7 +2,8 @@ package changeset import ( "context" - "fmt" + "errors" + "math" "math/big" "os" "testing" @@ -61,16 +62,16 @@ type TestConfigs struct { func (tc *TestConfigs) Validate() error { if tc.Chains < 2 { - return fmt.Errorf("chains must be at least 2") + return errors.New("chains must be at least 2") } if tc.Nodes < 4 { - return fmt.Errorf("nodes must be at least 4") + return errors.New("nodes must be at least 4") } if tc.Bootstraps < 1 { - return fmt.Errorf("bootstraps must be at least 1") + return errors.New("bootstraps must be at least 1") } if tc.Type == Memory && tc.RMNEnabled { - return fmt.Errorf("cannot run RMN tests in memory mode") + return errors.New("cannot run RMN tests in memory mode") } return nil } @@ -505,9 +506,14 @@ func NewEnvironmentWithJobsAndContracts(t *testing.T, tc *TestConfigs, tEnv Test ocrParams = tc.OCRConfigOverride(ocrParams) } ocrConfigs[chain] = ocrParams + fChain := len(nodeInfo.NonBootstraps().PeerIDs()) / 3 + if fChain > math.MaxUint8 { + t.Fatal("fChain too large") + } chainConfigs[chain] = ChainConfig{ Readers: nodeInfo.NonBootstraps().PeerIDs(), - FChain: uint8(len(nodeInfo.NonBootstraps().PeerIDs()) / 3), + //nolint:gosec // already handled above + FChain: uint8(fChain), EncodableChainConfig: chainconfig.ChainConfig{ GasPriceDeviationPPB: cciptypes.BigInt{Int: big.NewInt(internal.GasPriceDeviationPPB)}, DAGasPriceDeviationPPB: cciptypes.BigInt{Int: big.NewInt(internal.DAGasPriceDeviationPPB)}, diff --git a/deployment/ccip/changeset/test_helpers.go b/deployment/ccip/changeset/test_helpers.go index 7141f54b45b..692c6667081 100644 --- a/deployment/ccip/changeset/test_helpers.go +++ b/deployment/ccip/changeset/test_helpers.go @@ -649,7 +649,7 @@ func deployTokenPoolsInParallel( return nil, nil, nil, nil, err } if srcToken == nil || srcPool == nil || dstToken == nil || dstPool == nil { - return nil, nil, nil, nil, fmt.Errorf("failed to deploy token and pool") + return nil, nil, nil, nil, errors.New("failed to deploy token and pool") } return srcToken, srcPool, dstToken, dstPool, nil } diff --git a/deployment/ccip/changeset/v1_5/cs_jobspec.go b/deployment/ccip/changeset/v1_5/cs_jobspec.go index 74cb971a0b1..537396b96c8 100644 --- a/deployment/ccip/changeset/v1_5/cs_jobspec.go +++ b/deployment/ccip/changeset/v1_5/cs_jobspec.go @@ -1,6 +1,7 @@ package v1_5 import ( + "errors" "fmt" "github.com/smartcontractkit/chainlink/deployment" @@ -41,14 +42,14 @@ func (j JobSpecInput) Validate() error { return fmt.Errorf("DestinationChainSelector is invalid: %w", err) } if j.TokenPricesUSDPipeline == "" && j.PriceGetterConfigJSON == "" { - return fmt.Errorf("TokenPricesUSDPipeline or PriceGetterConfigJSON is required") + return errors.New("TokenPricesUSDPipeline or PriceGetterConfigJSON is required") } if j.USDCCfg != nil { if err := j.USDCCfg.ValidateUSDCConfig(); err != nil { return fmt.Errorf("USDCCfg is invalid: %w", err) } if j.USDCAttestationAPI == "" { - return fmt.Errorf("USDCAttestationAPI is required") + return errors.New("USDCAttestationAPI is required") } } return nil diff --git a/deployment/ccip/changeset/v1_5/test_helpers.go b/deployment/ccip/changeset/v1_5/test_helpers.go index 71ac75282a4..653ce55f9d7 100644 --- a/deployment/ccip/changeset/v1_5/test_helpers.go +++ b/deployment/ccip/changeset/v1_5/test_helpers.go @@ -217,13 +217,15 @@ func CreatePricesPipeline(t *testing.T, state changeset.CCIPOnChainState, source destLink := state.Chains[dest].LinkToken linkUSD := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { _, err := w.Write([]byte(`{"UsdPerLink": "8000000000000000000"}`)) - require.NoError(t, err) + // can't use require.NoError here for linting + panic(err) })) t.Cleanup(linkUSD.Close) ethUSD := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { _, err := w.Write([]byte(`{"UsdPerETH": "1700000000000000000000"}`)) - require.NoError(t, err) + // can't use require.NoError here for linting + panic(err) })) t.Cleanup(ethUSD.Close) diff --git a/deployment/ccip/view/v1_5/onramp.go b/deployment/ccip/view/v1_5/onramp.go index d679f6c14c0..c211c493cbc 100644 --- a/deployment/ccip/view/v1_5/onramp.go +++ b/deployment/ccip/view/v1_5/onramp.go @@ -1,6 +1,7 @@ package v1_5 import ( + "errors" "fmt" "github.com/smartcontractkit/chainlink/deployment/common/view/types" @@ -15,7 +16,7 @@ type OnRampView struct { func GenerateOnRampView(r *evm_2_evm_onramp.EVM2EVMOnRamp) (OnRampView, error) { if r == nil { - return OnRampView{}, fmt.Errorf("cannot generate view for nil OnRamp") + return OnRampView{}, errors.New("cannot generate view for nil OnRamp") } meta, err := types.NewContractMetaData(r, r.Address()) if err != nil { diff --git a/deployment/ccip/view/v1_5/rmn.go b/deployment/ccip/view/v1_5/rmn.go index cef55460446..19535cf508e 100644 --- a/deployment/ccip/view/v1_5/rmn.go +++ b/deployment/ccip/view/v1_5/rmn.go @@ -1,6 +1,7 @@ package v1_5 import ( + "errors" "fmt" "github.com/smartcontractkit/chainlink/deployment/common/view/types" @@ -14,7 +15,7 @@ type RMNView struct { func GenerateRMNView(r *rmn_contract.RMNContract) (RMNView, error) { if r == nil { - return RMNView{}, fmt.Errorf("cannot generate view for nil RMN") + return RMNView{}, errors.New("cannot generate view for nil RMN") } meta, err := types.NewContractMetaData(r, r.Address()) if err != nil { diff --git a/deployment/ccip/view/v1_5/tokenadminregistry.go b/deployment/ccip/view/v1_5/tokenadminregistry.go index 2fd36615bcd..e4a88996247 100644 --- a/deployment/ccip/view/v1_5/tokenadminregistry.go +++ b/deployment/ccip/view/v1_5/tokenadminregistry.go @@ -1,6 +1,7 @@ package v1_5 import ( + "errors" "fmt" "github.com/ethereum/go-ethereum/common" @@ -20,7 +21,7 @@ type TokenAdminRegistryView struct { func GenerateTokenAdminRegistryView(taContract *token_admin_registry.TokenAdminRegistry) (TokenAdminRegistryView, error) { if taContract == nil { - return TokenAdminRegistryView{}, fmt.Errorf("token admin registry contract is nil") + return TokenAdminRegistryView{}, errors.New("token admin registry contract is nil") } tokens, err := getAllConfiguredTokensPaginated(taContract) if err != nil { diff --git a/deployment/ccip/view/v1_6/ccip_home.go b/deployment/ccip/view/v1_6/ccip_home.go index 4d74bdfc79e..1cc403b7525 100644 --- a/deployment/ccip/view/v1_6/ccip_home.go +++ b/deployment/ccip/view/v1_6/ccip_home.go @@ -61,7 +61,7 @@ func GenerateCCIPHomeView(cr *capabilities_registry.CapabilitiesRegistry, ch *cc return CCIPHomeView{}, fmt.Errorf("failed to get DONs for CCIPHome %s: %w", ch.Address(), err) } // Get every don's configuration. - var dvs []DonView + dvs := make([]DonView, 0) for _, d := range dons { commitConfigs, err := ch.GetAllConfigs(nil, d.Id, CommitPluginType) if err != nil {