Skip to content

Commit

Permalink
deployment: golangci-lint run --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Jan 3, 2025
1 parent 945c706 commit f88aeb5
Show file tree
Hide file tree
Showing 104 changed files with 332 additions and 320 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ linters:
- errname
- errorlint
- exhaustive
- exportloopref
- fatcontext
- ginkgolinter
- gocritic
Expand Down
1 change: 0 additions & 1 deletion deployment/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ linters:
- errname
- errorlint
- exhaustive
- exportloopref
- fatcontext
- ginkgolinter
- gocritic
Expand Down
10 changes: 5 additions & 5 deletions deployment/address_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
)

var (
ErrInvalidChainSelector = fmt.Errorf("invalid chain selector")
ErrInvalidAddress = fmt.Errorf("invalid address")
ErrChainNotFound = fmt.Errorf("chain not found")
ErrInvalidChainSelector = errors.New("invalid chain selector")
ErrInvalidAddress = errors.New("invalid address")
ErrChainNotFound = errors.New("chain not found")
)

// ContractType is a simple string type for identifying contract types.
Expand Down Expand Up @@ -117,7 +117,7 @@ func (m *AddressBookMap) save(chainSelector uint64, address string, typeAndVersi
// TODO NONEVM-960: Add validation for non-EVM chain addresses

if typeAndVersion.Type == "" {
return fmt.Errorf("type cannot be empty")
return errors.New("type cannot be empty")
}

if _, exists := m.addressesByChain[chainSelector]; !exists {
Expand Down Expand Up @@ -256,7 +256,7 @@ func SearchAddressBook(ab AddressBook, chain uint64, typ ContractType) (string,
}
}

return "", fmt.Errorf("not found")
return "", errors.New("not found")
}

func AddressBookContains(ab AddressBook, chain uint64, addrToFind string) (bool, error) {
Expand Down
45 changes: 23 additions & 22 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,7 +140,7 @@ func (p PromoteCandidatesChangesetConfig) 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
Expand All @@ -153,7 +154,7 @@ func (p PromoteCandidatesChangesetConfig) 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 PromoteCandidatesChangesetConfig) 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 @@ -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 @@ -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 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.NotZero(t, 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.Zero(t, chainConfigAfter.FChain)

// Lets add it back now.
_, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*proposalutils.TimelockExecutionContracts{
Expand Down
9 changes: 4 additions & 5 deletions deployment/ccip/changeset/cs_chain_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func UpdateNonceManagersCS(e deployment.Environment, cfg UpdateNonceManagerConfi
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
}

Expand Down Expand Up @@ -265,7 +265,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")
}
}
}
Expand Down Expand Up @@ -514,7 +514,7 @@ func UpdateFeeQuoterPricesCS(e deployment.Environment, cfg UpdateFeeQuoterPrices
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
}

Expand Down Expand Up @@ -552,7 +552,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("source and destination chain cannot be the same")
return errors.New("source and destination chain cannot be the same")
}
}
}
Expand Down Expand Up @@ -824,7 +824,6 @@ func (cfg UpdateRouterRampsConfig) Validate(e deployment.Environment) error {
return fmt.Errorf("missing offramp for dest %d", destination)
}
}

}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions deployment/ccip/changeset/cs_chain_contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,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)
})
}
}
Expand Down
17 changes: 9 additions & 8 deletions deployment/ccip/changeset/cs_deploy_chain.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package changeset

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

Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -203,7 +204,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 {
Expand Down Expand Up @@ -243,7 +244,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 {
Expand All @@ -264,7 +265,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 {
Expand Down Expand Up @@ -304,7 +305,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 {
Expand Down Expand Up @@ -335,7 +336,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 {
Expand Down
Loading

0 comments on commit f88aeb5

Please sign in to comment.