Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ccip-4681 lint fix for deployment/ccip #15783

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions deployment/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -176,3 +179,4 @@ issues:
- linters:
- govet
text: "declaration of \"err\" shadows"

15 changes: 8 additions & 7 deletions deployment/ccip/changeset/cs_add_lane.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package changeset

import (
"encoding/hex"
"errors"
"fmt"
"math/big"

Expand All @@ -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
}
Expand All @@ -52,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
Expand All @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions deployment/ccip/changeset/cs_add_lane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}

Expand Down
53 changes: 27 additions & 26 deletions deployment/ccip/changeset/cs_ccip_home.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package changeset
import (
"bytes"
"encoding/hex"
"errors"
"fmt"
"math/big"
"os"
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -316,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.
Expand All @@ -340,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
Expand Down Expand Up @@ -420,7 +421,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,
Expand All @@ -443,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
Expand Down Expand Up @@ -476,7 +477,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 {
Expand Down Expand Up @@ -671,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(
Expand Down Expand Up @@ -791,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(
Expand Down Expand Up @@ -831,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 {
Expand Down Expand Up @@ -866,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
Expand Down Expand Up @@ -947,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)
Expand Down Expand Up @@ -1017,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 {
Expand All @@ -1042,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
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions deployment/ccip/changeset/cs_ccip_home_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down
Loading
Loading