diff --git a/.golangci.yml b/.golangci.yml index 92f26ea20900..2a5b771b78d4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -34,7 +34,6 @@ linters: - dogsled - dupl - durationcheck - - errorlint - exhaustive - exhaustruct - forbidigo diff --git a/api/client/beacon/checkpoint_test.go b/api/client/beacon/checkpoint_test.go index 232a9914c269..250608ebf99d 100644 --- a/api/client/beacon/checkpoint_test.go +++ b/api/client/beacon/checkpoint_test.go @@ -9,22 +9,20 @@ import ( "net/http" "testing" + "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/api/client" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" blocktest "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks/testing" - "github.com/prysmaticlabs/prysm/v5/network/forks" - ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/v5/testing/util" - "github.com/prysmaticlabs/prysm/v5/time/slots" - - "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/encoding/ssz/detect" + "github.com/prysmaticlabs/prysm/v5/network/forks" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/runtime/version" - - "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/testing/require" + "github.com/prysmaticlabs/prysm/v5/testing/util" + "github.com/prysmaticlabs/prysm/v5/time/slots" ) type testRT struct { diff --git a/api/client/builder/BUILD.bazel b/api/client/builder/BUILD.bazel index 6248a2051e75..e8dd1ce1a27a 100644 --- a/api/client/builder/BUILD.bazel +++ b/api/client/builder/BUILD.bazel @@ -55,6 +55,7 @@ go_test( "//testing/assert:go_default_library", "//testing/require:go_default_library", "@com_github_ethereum_go_ethereum//common/hexutil:go_default_library", + "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", ], diff --git a/api/client/builder/types_test.go b/api/client/builder/types_test.go index 0bc6b1b57c50..fbcf5a854e7f 100644 --- a/api/client/builder/types_test.go +++ b/api/client/builder/types_test.go @@ -12,6 +12,7 @@ import ( "testing" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/pkg/errors" "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/v5/api/server/structs" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" @@ -1914,7 +1915,8 @@ func TestEmptyResponseBody(t *testing.T) { var b []byte r := &ExecutionPayloadResponse{} err := json.Unmarshal(b, r) - _, ok := err.(*json.SyntaxError) + var syntaxError *json.SyntaxError + ok := errors.As(err, &syntaxError) require.Equal(t, true, ok) }) t.Run("empty object", func(t *testing.T) { diff --git a/api/server/error.go b/api/server/error.go index 809fcae01744..feb09facb8ec 100644 --- a/api/server/error.go +++ b/api/server/error.go @@ -1,6 +1,7 @@ package server import ( + "errors" "fmt" "strings" ) @@ -15,7 +16,8 @@ type DecodeError struct { // NewDecodeError wraps an error (either the initial decoding error or another DecodeError). // The current field that failed decoding must be passed in. func NewDecodeError(err error, field string) *DecodeError { - de, ok := err.(*DecodeError) + var de *DecodeError + ok := errors.As(err, &de) if ok { return &DecodeError{path: append([]string{field}, de.path...), err: de.err} } diff --git a/api/server/structs/conversions.go b/api/server/structs/conversions.go index 4cee5e8964d6..6e1b66ed9852 100644 --- a/api/server/structs/conversions.go +++ b/api/server/structs/conversions.go @@ -8,11 +8,10 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/api/server" - "github.com/prysmaticlabs/prysm/v5/consensus-types/validator" - "github.com/prysmaticlabs/prysm/v5/container/slice" - fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" + "github.com/prysmaticlabs/prysm/v5/consensus-types/validator" + "github.com/prysmaticlabs/prysm/v5/container/slice" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" "github.com/prysmaticlabs/prysm/v5/math" enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" diff --git a/beacon-chain/blockchain/chain_info.go b/beacon-chain/blockchain/chain_info.go index f6a6e5dec924..e3fbac167eb7 100644 --- a/beacon-chain/blockchain/chain_info.go +++ b/beacon-chain/blockchain/chain_info.go @@ -6,8 +6,6 @@ import ( "time" "github.com/pkg/errors" - "go.opencensus.io/trace" - "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers" f "github.com/prysmaticlabs/prysm/v5/beacon-chain/forkchoice" doublylinkedtree "github.com/prysmaticlabs/prysm/v5/beacon-chain/forkchoice/doubly-linked-tree" @@ -20,6 +18,7 @@ import ( "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/time/slots" + "go.opencensus.io/trace" ) // ChainInfoFetcher defines a common interface for methods in blockchain service which diff --git a/beacon-chain/blockchain/execution_engine.go b/beacon-chain/blockchain/execution_engine.go index 3ef06e3f443d..f6e287f4c525 100644 --- a/beacon-chain/blockchain/execution_engine.go +++ b/beacon-chain/blockchain/execution_engine.go @@ -74,8 +74,8 @@ func (s *Service) notifyForkchoiceUpdate(ctx context.Context, arg *fcuConfig) (* } payloadID, lastValidHash, err := s.cfg.ExecutionEngineCaller.ForkchoiceUpdated(ctx, fcs, arg.attributes) if err != nil { - switch err { - case execution.ErrAcceptedSyncingPayloadStatus: + switch { + case errors.Is(err, execution.ErrAcceptedSyncingPayloadStatus): forkchoiceUpdatedOptimisticNodeCount.Inc() log.WithFields(logrus.Fields{ "headSlot": headBlk.Slot(), @@ -83,7 +83,7 @@ func (s *Service) notifyForkchoiceUpdate(ctx context.Context, arg *fcuConfig) (* "finalizedPayloadBlockHash": fmt.Sprintf("%#x", bytesutil.Trunc(finalizedHash[:])), }).Info("Called fork choice updated with optimistic block") return payloadID, nil - case execution.ErrInvalidPayloadStatus: + case errors.Is(err, execution.ErrInvalidPayloadStatus): forkchoiceUpdatedInvalidNodeCount.Inc() headRoot := arg.headRoot if len(lastValidHash) == 0 { @@ -139,7 +139,6 @@ func (s *Service) notifyForkchoiceUpdate(ctx context.Context, arg *fcuConfig) (* "newHeadRoot": fmt.Sprintf("%#x", bytesutil.Trunc(r[:])), }).Warn("Pruned invalid blocks") return pid, invalidBlock{error: ErrInvalidPayload, root: arg.headRoot, invalidAncestorRoots: invalidRoots} - default: log.WithError(err).Error(ErrUndefinedExecutionEngineError) return nil, nil @@ -231,18 +230,18 @@ func (s *Service) notifyNewPayload(ctx context.Context, preStateVersion int, } else { lastValidHash, err = s.cfg.ExecutionEngineCaller.NewPayload(ctx, payload, []common.Hash{}, &common.Hash{} /*empty version hashes and root before Deneb*/) } - switch err { - case nil: + switch { + case err == nil: newPayloadValidNodeCount.Inc() return true, nil - case execution.ErrAcceptedSyncingPayloadStatus: + case errors.Is(err, execution.ErrAcceptedSyncingPayloadStatus): newPayloadOptimisticNodeCount.Inc() log.WithFields(logrus.Fields{ "slot": blk.Block().Slot(), "payloadBlockHash": fmt.Sprintf("%#x", bytesutil.Trunc(payload.BlockHash())), }).Info("Called new payload with optimistic block") return false, nil - case execution.ErrInvalidPayloadStatus: + case errors.Is(err, execution.ErrInvalidPayloadStatus): lvh := bytesutil.ToBytes32(lastValidHash) return false, invalidBlock{ error: ErrInvalidPayload, diff --git a/beacon-chain/blockchain/lightclient.go b/beacon-chain/blockchain/lightclient.go index 1183b1d577d4..4a6890659510 100644 --- a/beacon-chain/blockchain/lightclient.go +++ b/beacon-chain/blockchain/lightclient.go @@ -69,7 +69,7 @@ func NewLightClientOptimisticUpdateFromBeaconState( // assert sum(block.message.body.sync_aggregate.sync_committee_bits) >= MIN_SYNC_COMMITTEE_PARTICIPANTS syncAggregate, err := block.Block().Body().SyncAggregate() if err != nil { - return nil, fmt.Errorf("could not get sync aggregate %v", err) + return nil, fmt.Errorf("could not get sync aggregate %w", err) } if syncAggregate.SyncCommitteeBits.Count() < params.BeaconConfig().MinSyncCommitteeParticipants { @@ -85,18 +85,18 @@ func NewLightClientOptimisticUpdateFromBeaconState( header := state.LatestBlockHeader() stateRoot, err := state.HashTreeRoot(ctx) if err != nil { - return nil, fmt.Errorf("could not get state root %v", err) + return nil, fmt.Errorf("could not get state root %w", err) } header.StateRoot = stateRoot[:] headerRoot, err := header.HashTreeRoot() if err != nil { - return nil, fmt.Errorf("could not get header root %v", err) + return nil, fmt.Errorf("could not get header root %w", err) } blockRoot, err := block.Block().HashTreeRoot() if err != nil { - return nil, fmt.Errorf("could not get block root %v", err) + return nil, fmt.Errorf("could not get block root %w", err) } if headerRoot != blockRoot { @@ -114,14 +114,14 @@ func NewLightClientOptimisticUpdateFromBeaconState( // attested_header.state_root = hash_tree_root(attested_state) attestedStateRoot, err := attestedState.HashTreeRoot(ctx) if err != nil { - return nil, fmt.Errorf("could not get attested state root %v", err) + return nil, fmt.Errorf("could not get attested state root %w", err) } attestedHeader.StateRoot = attestedStateRoot[:] // assert hash_tree_root(attested_header) == block.message.parent_root attestedHeaderRoot, err := attestedHeader.HashTreeRoot() if err != nil { - return nil, fmt.Errorf("could not get attested header root %v", err) + return nil, fmt.Errorf("could not get attested header root %w", err) } if attestedHeaderRoot != block.Block().ParentRoot() { @@ -175,13 +175,13 @@ func NewLightClientFinalityUpdateFromBeaconState( if finalizedBlock.Block().Slot() != 0 { tempFinalizedHeader, err := finalizedBlock.Header() if err != nil { - return nil, fmt.Errorf("could not get finalized header %v", err) + return nil, fmt.Errorf("could not get finalized header %w", err) } finalizedHeader = migration.V1Alpha1SignedHeaderToV1(tempFinalizedHeader).GetMessage() finalizedHeaderRoot, err := finalizedHeader.HashTreeRoot() if err != nil { - return nil, fmt.Errorf("could not get finalized header root %v", err) + return nil, fmt.Errorf("could not get finalized header root %w", err) } if finalizedHeaderRoot != bytesutil.ToBytes32(attestedState.FinalizedCheckpoint().Root) { @@ -204,7 +204,7 @@ func NewLightClientFinalityUpdateFromBeaconState( var bErr error finalityBranch, bErr = attestedState.FinalizedRootProof(ctx) if bErr != nil { - return nil, fmt.Errorf("could not get finalized root proof %v", bErr) + return nil, fmt.Errorf("could not get finalized root proof %w", bErr) } } else { finalizedHeader = ðpbv1.BeaconBlockHeader{ diff --git a/beacon-chain/blockchain/process_block.go b/beacon-chain/blockchain/process_block.go index 1ea9e28a5dc5..fc52ca2b0b9d 100644 --- a/beacon-chain/blockchain/process_block.go +++ b/beacon-chain/blockchain/process_block.go @@ -6,9 +6,6 @@ import ( "time" "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "go.opencensus.io/trace" - "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed" statefeed "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed/state" @@ -32,6 +29,8 @@ import ( "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation" "github.com/prysmaticlabs/prysm/v5/runtime/version" "github.com/prysmaticlabs/prysm/v5/time/slots" + "github.com/sirupsen/logrus" + "go.opencensus.io/trace" ) // A custom slot deadline for processing state slots in our cache. diff --git a/beacon-chain/blockchain/process_block_helpers.go b/beacon-chain/blockchain/process_block_helpers.go index 810be735abf9..5e1e7a3e6ef6 100644 --- a/beacon-chain/blockchain/process_block_helpers.go +++ b/beacon-chain/blockchain/process_block_helpers.go @@ -7,9 +7,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "go.opencensus.io/trace" - "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed" statefeed "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed/state" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/transition" @@ -25,6 +22,8 @@ import ( ethpbv2 "github.com/prysmaticlabs/prysm/v5/proto/eth/v2" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/time/slots" + "github.com/sirupsen/logrus" + "go.opencensus.io/trace" ) // CurrentSlot returns the current slot based on time. diff --git a/beacon-chain/blockchain/service.go b/beacon-chain/blockchain/service.go index 52dea5958bb8..efbc70c7941f 100644 --- a/beacon-chain/blockchain/service.go +++ b/beacon-chain/blockchain/service.go @@ -11,8 +11,6 @@ import ( "time" "github.com/pkg/errors" - "go.opencensus.io/trace" - "github.com/prysmaticlabs/prysm/v5/async/event" "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/kzg" "github.com/prysmaticlabs/prysm/v5/beacon-chain/cache" @@ -44,6 +42,7 @@ import ( ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" prysmTime "github.com/prysmaticlabs/prysm/v5/time" "github.com/prysmaticlabs/prysm/v5/time/slots" + "go.opencensus.io/trace" ) // Service represents a service that handles the internal @@ -506,7 +505,7 @@ func (s *Service) saveGenesisData(ctx context.Context, genesisState state.Beacon } genesisBlk, err := s.cfg.BeaconDB.GenesisBlock(ctx) if err != nil || genesisBlk == nil || genesisBlk.IsNil() { - return fmt.Errorf("could not load genesis block: %v", err) + return fmt.Errorf("could not load genesis block: %w", err) } genesisBlkRoot, err := genesisBlk.Block().HashTreeRoot() if err != nil { diff --git a/beacon-chain/core/helpers/sync_committee.go b/beacon-chain/core/helpers/sync_committee.go index 8c930945828d..c28926f062b3 100644 --- a/beacon-chain/core/helpers/sync_committee.go +++ b/beacon-chain/core/helpers/sync_committee.go @@ -31,7 +31,7 @@ func IsCurrentPeriodSyncCommittee(st state.BeaconState, valIdx primitives.Valida return false, err } indices, err := syncCommitteeCache.CurrentPeriodIndexPosition(root, valIdx) - if err == cache.ErrNonExistingSyncCommitteeKey { + if errors.Is(err, cache.ErrNonExistingSyncCommitteeKey) { val, err := st.ValidatorAtIndex(valIdx) if err != nil { return false, err @@ -68,7 +68,7 @@ func IsNextPeriodSyncCommittee( return false, err } indices, err := syncCommitteeCache.NextPeriodIndexPosition(root, valIdx) - if err == cache.ErrNonExistingSyncCommitteeKey { + if errors.Is(err, cache.ErrNonExistingSyncCommitteeKey) { val, err := st.ValidatorAtIndex(valIdx) if err != nil { return false, err @@ -95,7 +95,7 @@ func CurrentPeriodSyncSubcommitteeIndices( return nil, err } indices, err := syncCommitteeCache.CurrentPeriodIndexPosition(root, valIdx) - if err == cache.ErrNonExistingSyncCommitteeKey { + if errors.Is(err, cache.ErrNonExistingSyncCommitteeKey) { val, err := st.ValidatorAtIndex(valIdx) if err != nil { return nil, err @@ -129,7 +129,7 @@ func NextPeriodSyncSubcommitteeIndices( return nil, err } indices, err := syncCommitteeCache.NextPeriodIndexPosition(root, valIdx) - if err == cache.ErrNonExistingSyncCommitteeKey { + if errors.Is(err, cache.ErrNonExistingSyncCommitteeKey) { val, err := st.ValidatorAtIndex(valIdx) if err != nil { return nil, err diff --git a/beacon-chain/execution/engine_client.go b/beacon-chain/execution/engine_client.go index 7ce50bae0cd9..17a4c74c17d3 100644 --- a/beacon-chain/execution/engine_client.go +++ b/beacon-chain/execution/engine_client.go @@ -647,14 +647,15 @@ func handleRPCError(err error) error { if isTimeout(err) { return ErrHTTPTimeout } - e, ok := err.(gethRPC.Error) + var e gethRPC.Error + ok := errors.As(err, &e) if !ok { if strings.Contains(err.Error(), "401 Unauthorized") { log.Error("HTTP authentication to your execution client is not working. Please ensure " + "you are setting a correct value for the --jwt-secret flag in Prysm, or use an IPC connection if on " + "the same machine. Please see our documentation for more information on authenticating connections " + "here https://docs.prylabs.network/docs/execution-node/authentication") - return fmt.Errorf("could not authenticate connection to execution client: %v", err) + return fmt.Errorf("could not authenticate connection to execution client: %w", err) } return errors.Wrapf(err, "got an unexpected error in JSON-RPC response") } @@ -689,7 +690,8 @@ func handleRPCError(err error) error { case -32000: errServerErrorCount.Inc() // Only -32000 status codes are data errors in the RPC specification. - errWithData, ok := err.(gethRPC.DataError) + var errWithData gethRPC.DataError + ok := errors.As(err, &errWithData) if !ok { return errors.Wrapf(err, "got an unexpected error in JSON-RPC response") } @@ -708,7 +710,8 @@ type httpTimeoutError interface { } func isTimeout(e error) bool { - t, ok := e.(httpTimeoutError) + var t httpTimeoutError + ok := errors.As(e, &t) return ok && t.Timeout() } diff --git a/beacon-chain/node/node.go b/beacon-chain/node/node.go index e965d9956b99..d3f3af2ecfbd 100644 --- a/beacon-chain/node/node.go +++ b/beacon-chain/node/node.go @@ -572,7 +572,7 @@ func (b *BeaconNode) startDB(cliCtx *cli.Context, depositAddress string) error { if b.GenesisInitializer != nil { if err := b.GenesisInitializer.Initialize(b.ctx, d); err != nil { - if err == db.ErrExistingGenesisState { + if errors.Is(err, db.ErrExistingGenesisState) { return errors.Errorf("Genesis state flag specified but a genesis state "+ "exists already. Run again with --%s and/or ensure you are using the "+ "appropriate testnet flag to load the given genesis state.", cmd.ClearDB.Name) diff --git a/beacon-chain/node/prometheus.go b/beacon-chain/node/prometheus.go index 66f0b9dc301b..4431b2bdde8e 100644 --- a/beacon-chain/node/prometheus.go +++ b/beacon-chain/node/prometheus.go @@ -51,7 +51,7 @@ func (bc *bcnodeCollector) Collect(ch chan<- prometheus.Metric) { func (bc *bcnodeCollector) getCurrentDbBytes() (float64, error) { fs, err := os.Stat(bc.dbPath) if err != nil { - return 0, fmt.Errorf("could not collect database file size for prometheus, path=%s, err=%s", bc.dbPath, err) + return 0, fmt.Errorf("could not collect database file size for prometheus, path=%s, err=%w", bc.dbPath, err) } return float64(fs.Size()), nil } diff --git a/beacon-chain/node/registration/log.go b/beacon-chain/node/registration/log.go index 7e3060955643..0e3ed0b8e3cc 100644 --- a/beacon-chain/node/registration/log.go +++ b/beacon-chain/node/registration/log.go @@ -1,5 +1 @@ package registration - -import "github.com/sirupsen/logrus" - -var log = logrus.WithField("prefix", "registration") diff --git a/beacon-chain/node/registration/p2p.go b/beacon-chain/node/registration/p2p.go index 6675f2544641..01929014d788 100644 --- a/beacon-chain/node/registration/p2p.go +++ b/beacon-chain/node/registration/p2p.go @@ -7,6 +7,7 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/cmd" "github.com/prysmaticlabs/prysm/v5/config/params" + log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" "gopkg.in/yaml.v2" ) @@ -50,7 +51,8 @@ func readbootNodes(fileName string) ([]string, error) { listNodes := make([]string, 0) err = yaml.UnmarshalStrict(fileContent, &listNodes) if err != nil { - if _, ok := err.(*yaml.TypeError); !ok { + var typeError *yaml.TypeError + if !errors.As(err, &typeError) { return nil, err } else { log.WithError(err).Error("There were some issues parsing the bootnodes from a yaml file.") diff --git a/beacon-chain/p2p/handshake.go b/beacon-chain/p2p/handshake.go index a6086252152f..97d2af8eed72 100644 --- a/beacon-chain/p2p/handshake.go +++ b/beacon-chain/p2p/handshake.go @@ -138,7 +138,7 @@ func (s *Service) AddConnectionHandler(reqFunc, goodByeFunc func(ctx context.Con } s.peers.SetConnectionState(conn.RemotePeer(), peers.PeerConnecting) - if err := reqFunc(context.TODO(), conn.RemotePeer()); err != nil && err != io.EOF { + if err := reqFunc(context.TODO(), conn.RemotePeer()); err != nil && !errors.Is(err, io.EOF) { log.WithError(err).Trace("Handshake failed") disconnectFromPeer() return diff --git a/beacon-chain/p2p/options.go b/beacon-chain/p2p/options.go index de213848333a..272a1d7d9b28 100644 --- a/beacon-chain/p2p/options.go +++ b/beacon-chain/p2p/options.go @@ -18,7 +18,6 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/config/features" ecdsaprysm "github.com/prysmaticlabs/prysm/v5/crypto/ecdsa" - "github.com/prysmaticlabs/prysm/v5/runtime/version" ) diff --git a/beacon-chain/p2p/pubsub.go b/beacon-chain/p2p/pubsub.go index 0cc0b4f13013..3549841c9034 100644 --- a/beacon-chain/p2p/pubsub.go +++ b/beacon-chain/p2p/pubsub.go @@ -165,14 +165,14 @@ func (s *Service) pubsubOptions() []pubsub.Option { func parsePeersEnr(peers []string) ([]peer.AddrInfo, error) { addrs, err := PeersFromStringAddrs(peers) if err != nil { - return nil, fmt.Errorf("Cannot convert peers raw ENRs into multiaddresses: %v", err) + return nil, fmt.Errorf("Cannot convert peers raw ENRs into multiaddresses: %w", err) } if len(addrs) == 0 { return nil, fmt.Errorf("Converting peers raw ENRs into multiaddresses resulted in an empty list") } directAddrInfos, err := peer.AddrInfosFromP2pAddrs(addrs...) if err != nil { - return nil, fmt.Errorf("Cannot convert peers multiaddresses into AddrInfos: %v", err) + return nil, fmt.Errorf("Cannot convert peers multiaddresses into AddrInfos: %w", err) } return directAddrInfos, nil } diff --git a/beacon-chain/p2p/subnets.go b/beacon-chain/p2p/subnets.go index 78b65cc3ebe5..37ccea8ad998 100644 --- a/beacon-chain/p2p/subnets.go +++ b/beacon-chain/p2p/subnets.go @@ -14,15 +14,14 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/cache" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v5/cmd/beacon-chain/flags" + "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/consensus-types/wrapper" "github.com/prysmaticlabs/prysm/v5/crypto/hash" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" mathutil "github.com/prysmaticlabs/prysm/v5/math" - "go.opencensus.io/trace" - - "github.com/prysmaticlabs/prysm/v5/config/params" pb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" + "go.opencensus.io/trace" ) var attestationSubnetCount = params.BeaconConfig().AttestationSubnetCount diff --git a/beacon-chain/p2p/types/rpc_goodbye_codes.go b/beacon-chain/p2p/types/rpc_goodbye_codes.go index 82870e692837..ab66ada455b2 100644 --- a/beacon-chain/p2p/types/rpc_goodbye_codes.go +++ b/beacon-chain/p2p/types/rpc_goodbye_codes.go @@ -1,6 +1,8 @@ package types import ( + "errors" + "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ) @@ -35,8 +37,8 @@ var GoodbyeCodeMessages = map[RPCGoodbyeCode]string{ // ErrToGoodbyeCode converts given error to RPC goodbye code. func ErrToGoodbyeCode(err error) RPCGoodbyeCode { - switch err { - case ErrWrongForkDigestVersion: + switch { + case errors.Is(err, ErrWrongForkDigestVersion): return GoodbyeCodeWrongNetwork default: return GoodbyeCodeGenericError diff --git a/beacon-chain/rpc/eth/beacon/handlers_pool.go b/beacon-chain/rpc/eth/beacon/handlers_pool.go index eee3a7a70dad..e78a91ca9aed 100644 --- a/beacon-chain/rpc/eth/beacon/handlers_pool.go +++ b/beacon-chain/rpc/eth/beacon/handlers_pool.go @@ -98,7 +98,7 @@ func (s *Server) SubmitAttestations(w http.ResponseWriter, r *http.Request) { var req structs.SubmitAttestationsRequest err := json.NewDecoder(r.Body).Decode(&req.Data) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -216,7 +216,7 @@ func (s *Server) SubmitVoluntaryExit(w http.ResponseWriter, r *http.Request) { var req structs.SignedVoluntaryExit err := json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -274,7 +274,7 @@ func (s *Server) SubmitSyncCommitteeSignatures(w http.ResponseWriter, r *http.Re var req structs.SubmitSyncCommitteeSignaturesRequest err := json.NewDecoder(r.Body).Decode(&req.Data) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -333,7 +333,7 @@ func (s *Server) SubmitBLSToExecutionChanges(w http.ResponseWriter, r *http.Requ var req []*structs.SignedBLSToExecutionChange err = json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -491,7 +491,7 @@ func (s *Server) SubmitAttesterSlashing(w http.ResponseWriter, r *http.Request) var req structs.AttesterSlashing err := json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -565,7 +565,7 @@ func (s *Server) SubmitProposerSlashing(w http.ResponseWriter, r *http.Request) var req structs.ProposerSlashing err := json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: diff --git a/beacon-chain/rpc/eth/beacon/handlers_state.go b/beacon-chain/rpc/eth/beacon/handlers_state.go index bd6659fa9473..6ada905f6dae 100644 --- a/beacon-chain/rpc/eth/beacon/handlers_state.go +++ b/beacon-chain/rpc/eth/beacon/handlers_state.go @@ -2,6 +2,7 @@ package beacon import ( "context" + "errors" "fmt" "net/http" "strconv" @@ -41,12 +42,10 @@ func (s *Server) GetStateRoot(w http.ResponseWriter, r *http.Request) { stateRoot, err := s.Stater.StateRoot(ctx, []byte(stateId)) if err != nil { - if rootNotFoundErr, ok := err.(*lookup.StateRootNotFoundError); ok { + var rootNotFoundErr *lookup.StateRootNotFoundError + if errors.As(err, &rootNotFoundErr) { httputil.HandleError(w, "State root not found: "+rootNotFoundErr.Error(), http.StatusNotFound) return - } else if parseErr, ok := err.(*lookup.StateIdParseError); ok { - httputil.HandleError(w, "Invalid state ID: "+parseErr.Error(), http.StatusBadRequest) - return } httputil.HandleError(w, "Could not get state root: "+err.Error(), http.StatusInternalServerError) return @@ -270,7 +269,7 @@ func currentCommitteeIndicesFromState(st state.BeaconState) ([]string, *ethpbalp committee, err := st.CurrentSyncCommittee() if err != nil { return nil, nil, fmt.Errorf( - "could not get sync committee: %v", err, + "could not get sync committee: %w", err, ) } @@ -281,7 +280,7 @@ func nextCommitteeIndicesFromState(st state.BeaconState) ([]string, *ethpbalpha. committee, err := st.NextSyncCommittee() if err != nil { return nil, nil, fmt.Errorf( - "could not get sync committee: %v", err, + "could not get sync committee: %w", err, ) } @@ -295,7 +294,7 @@ func extractSyncSubcommittees(st state.BeaconState, committee *ethpbalpha.SyncCo pubkeys, err := altair.SyncSubCommitteePubkeys(committee, primitives.CommitteeIndex(i)) if err != nil { return nil, fmt.Errorf( - "failed to get subcommittee pubkeys: %v", err, + "failed to get subcommittee pubkeys: %w", err, ) } subcommittee := make([]string, len(pubkeys)) diff --git a/beacon-chain/rpc/eth/beacon/handlers_test.go b/beacon-chain/rpc/eth/beacon/handlers_test.go index 592122c9ec1c..67b571042268 100644 --- a/beacon-chain/rpc/eth/beacon/handlers_test.go +++ b/beacon-chain/rpc/eth/beacon/handlers_test.go @@ -13,10 +13,6 @@ import ( "time" "github.com/ethereum/go-ethereum/common/hexutil" - mockp2p "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/testing" - logTest "github.com/sirupsen/logrus/hooks/test" - "go.uber.org/mock/gomock" - "github.com/gorilla/mux" "github.com/pkg/errors" "github.com/prysmaticlabs/go-bitfield" @@ -28,6 +24,7 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/db" dbTest "github.com/prysmaticlabs/prysm/v5/beacon-chain/db/testing" doublylinkedtree "github.com/prysmaticlabs/prysm/v5/beacon-chain/forkchoice/doubly-linked-tree" + mockp2p "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/testing" rpctesting "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/shared/testing" "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/lookup" "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/testutil" @@ -46,7 +43,9 @@ import ( "github.com/prysmaticlabs/prysm/v5/testing/require" "github.com/prysmaticlabs/prysm/v5/testing/util" "github.com/prysmaticlabs/prysm/v5/time/slots" + logTest "github.com/sirupsen/logrus/hooks/test" "github.com/stretchr/testify/mock" + "go.uber.org/mock/gomock" ) func fillDBTestBlocks(ctx context.Context, t *testing.T, beaconDB db.Database) (*eth.SignedBeaconBlock, []*eth.BeaconBlockContainer) { diff --git a/beacon-chain/rpc/eth/beacon/handlers_validator.go b/beacon-chain/rpc/eth/beacon/handlers_validator.go index 706e55a59b2e..d14fd6bf87ea 100644 --- a/beacon-chain/rpc/eth/beacon/handlers_validator.go +++ b/beacon-chain/rpc/eth/beacon/handlers_validator.go @@ -10,6 +10,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/gorilla/mux" + "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/api/server/structs" "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/helpers" "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/shared" @@ -56,7 +57,7 @@ func (s *Server) GetValidators(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodPost { err = json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -272,7 +273,7 @@ func (s *Server) GetValidatorBalances(w http.ResponseWriter, r *http.Request) { } else { err = json.NewDecoder(r.Body).Decode(&rawIds) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: diff --git a/beacon-chain/rpc/eth/config/handlers_test.go b/beacon-chain/rpc/eth/config/handlers_test.go index 1863f86cc1f7..080082e35e6f 100644 --- a/beacon-chain/rpc/eth/config/handlers_test.go +++ b/beacon-chain/rpc/eth/config/handlers_test.go @@ -12,7 +12,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/prysmaticlabs/prysm/v5/api/server/structs" - "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" diff --git a/beacon-chain/rpc/eth/helpers/error_handling.go b/beacon-chain/rpc/eth/helpers/error_handling.go index da1b5d49c827..12561e13fa60 100644 --- a/beacon-chain/rpc/eth/helpers/error_handling.go +++ b/beacon-chain/rpc/eth/helpers/error_handling.go @@ -17,10 +17,12 @@ func PrepareStateFetchGRPCError(err error) error { if errors.Is(err, stategen.ErrNoDataForSlot) { return status.Errorf(codes.NotFound, "lacking historical data needed to fulfill request") } - if stateNotFoundErr, ok := err.(*lookup.StateNotFoundError); ok { + var stateNotFoundErr *lookup.StateNotFoundError + if errors.As(err, &stateNotFoundErr) { return status.Errorf(codes.NotFound, "State not found: %v", stateNotFoundErr) } - if parseErr, ok := err.(*lookup.StateIdParseError); ok { + var parseErr *lookup.StateIdParseError + if errors.As(err, &parseErr) { return status.Errorf(codes.InvalidArgument, "Invalid state ID: %v", parseErr) } return status.Errorf(codes.Internal, "Invalid state ID: %v", err) @@ -38,7 +40,8 @@ type SingleIndexedVerificationFailure struct { } func HandleGetBlockError(blk interfaces.ReadOnlySignedBeaconBlock, err error) error { - if invalidBlockIdErr, ok := err.(*lookup.BlockIdParseError); ok { + var invalidBlockIdErr *lookup.BlockIdParseError + if errors.As(err, &invalidBlockIdErr) { return status.Errorf(codes.InvalidArgument, "Invalid block ID: %v", invalidBlockIdErr) } if err != nil { diff --git a/beacon-chain/rpc/eth/helpers/sync_test.go b/beacon-chain/rpc/eth/helpers/sync_test.go index 54832c7e7321..014e61888a5f 100644 --- a/beacon-chain/rpc/eth/helpers/sync_test.go +++ b/beacon-chain/rpc/eth/helpers/sync_test.go @@ -97,7 +97,7 @@ func TestIsOptimistic(t *testing.T) { t.Run("finalized checkpoint is optimistic", func(t *testing.T) { st, err := util.NewBeaconState() require.NoError(t, err) - cs := &chainmock.ChainService{Optimistic: true, FinalizedCheckPoint: ð.Checkpoint{}, OptimisticRoots: map[[32]byte]bool{[32]byte{}: true}} + cs := &chainmock.ChainService{Optimistic: true, FinalizedCheckPoint: ð.Checkpoint{}, OptimisticRoots: map[[32]byte]bool{{}: true}} mf := &testutil.MockStater{BeaconState: st} o, err := IsOptimistic(ctx, []byte("finalized"), cs, mf, cs, nil) require.NoError(t, err) @@ -117,7 +117,7 @@ func TestIsOptimistic(t *testing.T) { t.Run("justified checkpoint is optimistic", func(t *testing.T) { st, err := util.NewBeaconState() require.NoError(t, err) - cs := &chainmock.ChainService{Optimistic: true, CurrentJustifiedCheckPoint: ð.Checkpoint{}, OptimisticRoots: map[[32]byte]bool{[32]byte{}: true}} + cs := &chainmock.ChainService{Optimistic: true, CurrentJustifiedCheckPoint: ð.Checkpoint{}, OptimisticRoots: map[[32]byte]bool{{}: true}} mf := &testutil.MockStater{BeaconState: st} o, err := IsOptimistic(ctx, []byte("justified"), cs, mf, cs, nil) require.NoError(t, err) diff --git a/beacon-chain/rpc/eth/light-client/handlers.go b/beacon-chain/rpc/eth/light-client/handlers.go index 4ba524bbf692..74296f192e85 100644 --- a/beacon-chain/rpc/eth/light-client/handlers.go +++ b/beacon-chain/rpc/eth/light-client/handlers.go @@ -9,10 +9,6 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/gorilla/mux" "github.com/prysmaticlabs/prysm/v5/api/server/structs" - "go.opencensus.io/trace" - - "github.com/wealdtech/go-bytesutil" - "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/shared" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" "github.com/prysmaticlabs/prysm/v5/config/params" @@ -20,6 +16,8 @@ import ( types "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/network/httputil" "github.com/prysmaticlabs/prysm/v5/runtime/version" + "github.com/wealdtech/go-bytesutil" + "go.opencensus.io/trace" ) // GetLightClientBootstrap - implements https://github.com/ethereum/beacon-APIs/blob/263f4ed6c263c967f13279c7a9f5629b51c5fc55/apis/beacon/light_client/bootstrap.yaml @@ -353,24 +351,24 @@ func (s *Server) getLightClientEventBlock(ctx context.Context, minSignaturesRequ // Get the current state state, err := s.HeadFetcher.HeadState(ctx) if err != nil { - return nil, fmt.Errorf("could not get head state %v", err) + return nil, fmt.Errorf("could not get head state %w", err) } // Get the block latestBlockHeader := *state.LatestBlockHeader() stateRoot, err := state.HashTreeRoot(ctx) if err != nil { - return nil, fmt.Errorf("could not get state root %v", err) + return nil, fmt.Errorf("could not get state root %w", err) } latestBlockHeader.StateRoot = stateRoot[:] latestBlockHeaderRoot, err := latestBlockHeader.HashTreeRoot() if err != nil { - return nil, fmt.Errorf("could not get latest block header root %v", err) + return nil, fmt.Errorf("could not get latest block header root %w", err) } block, err := s.Blocker.Block(ctx, latestBlockHeaderRoot[:]) if err != nil { - return nil, fmt.Errorf("could not get latest block %v", err) + return nil, fmt.Errorf("could not get latest block %w", err) } if block == nil { return nil, fmt.Errorf("latest block is nil") @@ -387,7 +385,7 @@ func (s *Server) getLightClientEventBlock(ctx context.Context, minSignaturesRequ parentRoot := block.Block().ParentRoot() block, err = s.Blocker.Block(ctx, parentRoot[:]) if err != nil { - return nil, fmt.Errorf("could not get parent block %v", err) + return nil, fmt.Errorf("could not get parent block %w", err) } if block == nil { return nil, fmt.Errorf("parent block is nil") diff --git a/beacon-chain/rpc/eth/light-client/handlers_test.go b/beacon-chain/rpc/eth/light-client/handlers_test.go index aa65d9b29203..aff9643128cc 100644 --- a/beacon-chain/rpc/eth/light-client/handlers_test.go +++ b/beacon-chain/rpc/eth/light-client/handlers_test.go @@ -12,7 +12,6 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/gorilla/mux" "github.com/prysmaticlabs/prysm/v5/api/server/structs" - mock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/testutil" diff --git a/beacon-chain/rpc/eth/shared/BUILD.bazel b/beacon-chain/rpc/eth/shared/BUILD.bazel index 81baa76dcee5..78c012169402 100644 --- a/beacon-chain/rpc/eth/shared/BUILD.bazel +++ b/beacon-chain/rpc/eth/shared/BUILD.bazel @@ -18,6 +18,7 @@ go_library( "//network/httputil:go_default_library", "@com_github_ethereum_go_ethereum//common/hexutil:go_default_library", "@com_github_gorilla_mux//:go_default_library", + "@com_github_pkg_errors//:go_default_library", ], ) diff --git a/beacon-chain/rpc/eth/shared/errors.go b/beacon-chain/rpc/eth/shared/errors.go index 84cdacea4275..bfcd781822af 100644 --- a/beacon-chain/rpc/eth/shared/errors.go +++ b/beacon-chain/rpc/eth/shared/errors.go @@ -3,6 +3,7 @@ package shared import ( "net/http" + "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/lookup" "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" @@ -12,11 +13,13 @@ import ( // WriteStateFetchError writes an appropriate error based on the supplied argument. // The argument error should be a result of fetching state. func WriteStateFetchError(w http.ResponseWriter, err error) { - if _, ok := err.(*lookup.StateNotFoundError); ok { + var stateNotFoundError *lookup.StateNotFoundError + if errors.As(err, &stateNotFoundError) { httputil.HandleError(w, "State not found", http.StatusNotFound) return } - if parseErr, ok := err.(*lookup.StateIdParseError); ok { + var parseErr *lookup.StateIdParseError + if errors.As(err, &parseErr) { httputil.HandleError(w, "Invalid state ID: "+parseErr.Error(), http.StatusBadRequest) return } @@ -26,7 +29,8 @@ func WriteStateFetchError(w http.ResponseWriter, err error) { // WriteBlockFetchError writes an appropriate error based on the supplied argument. // The argument error should be a result of fetching block. func WriteBlockFetchError(w http.ResponseWriter, blk interfaces.ReadOnlySignedBeaconBlock, err error) bool { - if invalidBlockIdErr, ok := err.(*lookup.BlockIdParseError); ok { + var invalidBlockIdErr *lookup.BlockIdParseError + if errors.As(err, &invalidBlockIdErr) { httputil.HandleError(w, "Invalid block ID: "+invalidBlockIdErr.Error(), http.StatusBadRequest) return false } diff --git a/beacon-chain/rpc/eth/validator/handlers.go b/beacon-chain/rpc/eth/validator/handlers.go index c214697b3eed..f20ab9c5cc4d 100644 --- a/beacon-chain/rpc/eth/validator/handlers.go +++ b/beacon-chain/rpc/eth/validator/handlers.go @@ -121,7 +121,7 @@ func (s *Server) SubmitContributionAndProofs(w http.ResponseWriter, r *http.Requ var req structs.SubmitContributionAndProofsRequest err := json.NewDecoder(r.Body).Decode(&req.Data) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -154,7 +154,7 @@ func (s *Server) SubmitAggregateAndProofs(w http.ResponseWriter, r *http.Request var req structs.SubmitAggregateAndProofsRequest err := json.NewDecoder(r.Body).Decode(&req.Data) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -175,7 +175,8 @@ func (s *Server) SubmitAggregateAndProofs(w http.ResponseWriter, r *http.Request } rpcError := s.CoreService.SubmitSignedAggregateSelectionProof(ctx, consensusItem) if rpcError != nil { - _, ok := rpcError.Err.(*core.AggregateBroadcastFailedError) + var aggregateBroadcastFailedError *core.AggregateBroadcastFailedError + ok := errors.As(rpcError.Err, &aggregateBroadcastFailedError) if ok { broadcastFailed = true } else { @@ -206,7 +207,7 @@ func (s *Server) SubmitSyncCommitteeSubscription(w http.ResponseWriter, r *http. var req structs.SubmitSyncCommitteeSubscriptionsRequest err := json.NewDecoder(r.Body).Decode(&req.Data) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -316,7 +317,7 @@ func (s *Server) SubmitBeaconCommitteeSubscription(w http.ResponseWriter, r *htt var req structs.SubmitBeaconCommitteeSubscriptionsRequest err := json.NewDecoder(r.Body).Decode(&req.Data) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -519,7 +520,7 @@ func (s *Server) RegisterValidator(w http.ResponseWriter, r *http.Request) { var jsonRegistrations []*structs.SignedValidatorRegistration err := json.NewDecoder(r.Body).Decode(&jsonRegistrations) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -552,7 +553,7 @@ func (s *Server) PrepareBeaconProposer(w http.ResponseWriter, r *http.Request) { var jsonFeeRecipients []*structs.FeeRecipient err := json.NewDecoder(r.Body).Decode(&jsonFeeRecipients) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -612,7 +613,7 @@ func (s *Server) GetAttesterDuties(w http.ResponseWriter, r *http.Request) { var indices []string err := json.NewDecoder(r.Body).Decode(&indices) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -892,7 +893,7 @@ func (s *Server) GetSyncCommitteeDuties(w http.ResponseWriter, r *http.Request) var indices []string err := json.NewDecoder(r.Body).Decode(&indices) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -1017,7 +1018,7 @@ func (s *Server) GetLiveness(w http.ResponseWriter, r *http.Request) { var indices []string err := json.NewDecoder(r.Body).Decode(&indices) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: diff --git a/beacon-chain/rpc/lookup/stater_test.go b/beacon-chain/rpc/lookup/stater_test.go index 027212257ea7..009c8c30267f 100644 --- a/beacon-chain/rpc/lookup/stater_test.go +++ b/beacon-chain/rpc/lookup/stater_test.go @@ -7,15 +7,14 @@ import ( "testing" "time" - statenative "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native" - "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/stategen" - "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" - "github.com/ethereum/go-ethereum/common/hexutil" chainMock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing" testDB "github.com/prysmaticlabs/prysm/v5/beacon-chain/db/testing" + statenative "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native" + "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/stategen" mockstategen "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/stategen/mock" "github.com/prysmaticlabs/prysm/v5/config/params" + "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" diff --git a/beacon-chain/rpc/prysm/beacon/validator_count.go b/beacon-chain/rpc/prysm/beacon/validator_count.go index 166a8c5c684d..ba9b6f744f8a 100644 --- a/beacon-chain/rpc/prysm/beacon/validator_count.go +++ b/beacon-chain/rpc/prysm/beacon/validator_count.go @@ -131,15 +131,15 @@ func validatorCountByStatus(validators []*eth.Validator, statuses []validator.St for _, val := range validators { readOnlyVal, err := statenative.NewValidator(val) if err != nil { - return nil, fmt.Errorf("could not convert validator: %v", err) + return nil, fmt.Errorf("could not convert validator: %w", err) } valStatus, err := helpers.ValidatorStatus(readOnlyVal, epoch) if err != nil { - return nil, fmt.Errorf("could not get validator status: %v", err) + return nil, fmt.Errorf("could not get validator status: %w", err) } valSubStatus, err := helpers.ValidatorSubStatus(readOnlyVal, epoch) if err != nil { - return nil, fmt.Errorf("could not get validator sub status: %v", err) + return nil, fmt.Errorf("could not get validator sub status: %w", err) } for _, status := range statuses { diff --git a/beacon-chain/rpc/prysm/beacon/validator_count_test.go b/beacon-chain/rpc/prysm/beacon/validator_count_test.go index 85f79d3be8e0..7d4f9b330186 100644 --- a/beacon-chain/rpc/prysm/beacon/validator_count_test.go +++ b/beacon-chain/rpc/prysm/beacon/validator_count_test.go @@ -12,17 +12,15 @@ import ( "strings" "testing" - "github.com/prysmaticlabs/prysm/v5/api/server/structs" - "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" - - "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/lookup" - "github.com/prysmaticlabs/prysm/v5/network/httputil" - "github.com/gorilla/mux" + "github.com/prysmaticlabs/prysm/v5/api/server/structs" chainMock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing" + "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/lookup" "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/testutil" + "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" + "github.com/prysmaticlabs/prysm/v5/network/httputil" eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/require" "github.com/prysmaticlabs/prysm/v5/testing/util" diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/slashings_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/slashings_test.go index 7c72515f75a8..63bd3a92a158 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/slashings_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/slashings_test.go @@ -4,17 +4,16 @@ import ( "context" "testing" - "github.com/prysmaticlabs/prysm/v5/config/features" - "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" - ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/v5/testing/util" - "google.golang.org/protobuf/proto" - mock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/slashings" mockp2p "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/testing" + "github.com/prysmaticlabs/prysm/v5/config/features" + "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" "github.com/prysmaticlabs/prysm/v5/testing/require" + "github.com/prysmaticlabs/prysm/v5/testing/util" + "google.golang.org/protobuf/proto" ) func TestServer_SubmitProposerSlashing(t *testing.T) { diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go index 611cffa66901..27d1a5f297fd 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go @@ -89,7 +89,7 @@ func (vs *Server) GetBeaconBlock(ctx context.Context, req *ethpb.BlockRequest) ( // Set proposer index. idx, err := helpers.BeaconProposerIndex(ctx, head) if err != nil { - return nil, fmt.Errorf("could not calculate proposer index %v", err) + return nil, fmt.Errorf("could not calculate proposer index %w", err) } sBlk.SetProposerIndex(idx) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/status.go b/beacon-chain/rpc/prysm/v1alpha1/validator/status.go index 643f0a96d183..67bf6da2a60d 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/status.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/status.go @@ -288,12 +288,12 @@ func (vs *Server) validatorStatus( ActivationEpoch: params.BeaconConfig().FarFutureEpoch, } vStatus, idx, err := statusForPubKey(headState, pubKey) - if err != nil && err != errPubkeyDoesNotExist { + if err != nil && !errors.Is(err, errPubkeyDoesNotExist) { tracing.AnnotateError(span, err) return resp, nonExistentIndex } resp.Status = vStatus - if err != errPubkeyDoesNotExist { + if !errors.Is(err, errPubkeyDoesNotExist) { val, err := headState.ValidatorAtIndexReadOnly(idx) if err != nil { tracing.AnnotateError(span, err) diff --git a/beacon-chain/rpc/testutil/mock_stater.go b/beacon-chain/rpc/testutil/mock_stater.go index d478c896ae61..872aab459663 100644 --- a/beacon-chain/rpc/testutil/mock_stater.go +++ b/beacon-chain/rpc/testutil/mock_stater.go @@ -3,10 +3,9 @@ package testutil import ( "context" - "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" - "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" + "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" ) // MockStater is a fake implementation of lookup.Stater. diff --git a/beacon-chain/state/stategen/history_test.go b/beacon-chain/state/stategen/history_test.go index 14c2fe3b649b..fd17abd7631e 100644 --- a/beacon-chain/state/stategen/history_test.go +++ b/beacon-chain/state/stategen/history_test.go @@ -6,12 +6,11 @@ import ( "fmt" "testing" + "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/mock" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" - - "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/testing/require" ) diff --git a/beacon-chain/state/testing/getters_checkpoint.go b/beacon-chain/state/testing/getters_checkpoint.go index a9edf294ea15..c2b8b177ee3f 100644 --- a/beacon-chain/state/testing/getters_checkpoint.go +++ b/beacon-chain/state/testing/getters_checkpoint.go @@ -1,14 +1,14 @@ package testing import ( + "testing" + "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/require" - - "testing" ) func VerifyBeaconStateJustificationBitsNil(t *testing.T, factory getState) { diff --git a/beacon-chain/sync/backfill/status_test.go b/beacon-chain/sync/backfill/status_test.go index c6e455596900..940f47780b7e 100644 --- a/beacon-chain/sync/backfill/status_test.go +++ b/beacon-chain/sync/backfill/status_test.go @@ -5,16 +5,15 @@ import ( "context" "testing" + "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/beacon-chain/das" "github.com/prysmaticlabs/prysm/v5/beacon-chain/db" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" blocktest "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks/testing" "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" - "github.com/prysmaticlabs/prysm/v5/proto/dbval" - - "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" + "github.com/prysmaticlabs/prysm/v5/proto/dbval" "github.com/prysmaticlabs/prysm/v5/testing/require" "github.com/prysmaticlabs/prysm/v5/testing/util" ) diff --git a/beacon-chain/sync/genesis/file.go b/beacon-chain/sync/genesis/file.go index dcfcabe7c843..ef2f1b309936 100644 --- a/beacon-chain/sync/genesis/file.go +++ b/beacon-chain/sync/genesis/file.go @@ -5,11 +5,10 @@ import ( "fmt" "os" - "github.com/prysmaticlabs/prysm/v5/crypto/hash" - "github.com/prysmaticlabs/prysm/v5/io/file" - "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/beacon-chain/db" + "github.com/prysmaticlabs/prysm/v5/crypto/hash" + "github.com/prysmaticlabs/prysm/v5/io/file" ) // Initializer describes a type that is able to obtain the checkpoint sync data (BeaconState and SignedBeaconBlock) diff --git a/beacon-chain/sync/rpc.go b/beacon-chain/sync/rpc.go index fb6e0530c909..7ada5cc609f3 100644 --- a/beacon-chain/sync/rpc.go +++ b/beacon-chain/sync/rpc.go @@ -10,6 +10,7 @@ import ( libp2pcore "github.com/libp2p/go-libp2p/core" "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/protocol" + "github.com/pkg/errors" ssz "github.com/prysmaticlabs/fastssz" "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p" p2ptypes "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/types" @@ -195,7 +196,7 @@ func (s *Service) registerRPC(baseTopic string, handle rpcHandler) { if baseTopic == p2p.RPCMetaDataTopicV1 || baseTopic == p2p.RPCMetaDataTopicV2 { if err := handle(ctx, base, stream); err != nil { messageFailedProcessingCounter.WithLabelValues(topic).Inc() - if err != p2ptypes.ErrWrongForkDigestVersion { + if !errors.Is(err, p2ptypes.ErrWrongForkDigestVersion) { log.WithError(err).Debug("Could not handle p2p RPC") } tracing.AnnotateError(span, err) @@ -220,7 +221,7 @@ func (s *Service) registerRPC(baseTopic string, handle rpcHandler) { } if err := handle(ctx, msg, stream); err != nil { messageFailedProcessingCounter.WithLabelValues(topic).Inc() - if err != p2ptypes.ErrWrongForkDigestVersion { + if !errors.Is(err, p2ptypes.ErrWrongForkDigestVersion) { log.WithError(err).Debug("Could not handle p2p RPC") } tracing.AnnotateError(span, err) @@ -240,7 +241,7 @@ func (s *Service) registerRPC(baseTopic string, handle rpcHandler) { } if err := handle(ctx, nTyp.Elem().Interface(), stream); err != nil { messageFailedProcessingCounter.WithLabelValues(topic).Inc() - if err != p2ptypes.ErrWrongForkDigestVersion { + if !errors.Is(err, p2ptypes.ErrWrongForkDigestVersion) { log.WithError(err).Debug("Could not handle p2p RPC") } tracing.AnnotateError(span, err) diff --git a/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go b/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go index 5138893e97f2..55e838718ab0 100644 --- a/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go +++ b/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go @@ -12,6 +12,7 @@ import ( gethTypes "github.com/ethereum/go-ethereum/core/types" "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/protocol" + "github.com/pkg/errors" chainMock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing" db2 "github.com/prysmaticlabs/prysm/v5/beacon-chain/db" db "github.com/prysmaticlabs/prysm/v5/beacon-chain/db/testing" @@ -857,7 +858,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) { if err != nil && err != io.EOF { t.Fatal(err) } - if code != 0 || err == io.EOF { + if code != 0 || errors.Is(err, io.EOF) { break } blk := util.NewBeaconBlock() diff --git a/beacon-chain/sync/rpc_status.go b/beacon-chain/sync/rpc_status.go index d8f4d60d2b09..e688301d66de 100644 --- a/beacon-chain/sync/rpc_status.go +++ b/beacon-chain/sync/rpc_status.go @@ -211,10 +211,10 @@ func (s *Service) statusRPCHandler(ctx context.Context, msg interface{}, stream }).Debug("Invalid status message from peer") var respCode byte - switch err { - case p2ptypes.ErrGeneric: + switch { + case errors.Is(err, p2ptypes.ErrGeneric): respCode = responseCodeServerError - case p2ptypes.ErrWrongForkDigestVersion: + case errors.Is(err, p2ptypes.ErrWrongForkDigestVersion): // Respond with our status and disconnect with the peer. s.cfg.p2p.Peers().SetChainState(remotePeer, m) if err := s.respondWithStatus(ctx, stream); err != nil { diff --git a/beacon-chain/sync/subscriber.go b/beacon-chain/sync/subscriber.go index ee7691a2b806..3b7f7def672c 100644 --- a/beacon-chain/sync/subscriber.go +++ b/beacon-chain/sync/subscriber.go @@ -230,7 +230,7 @@ func (s *Service) subscribeWithBase(topic string, validator wrappedVal, handle s msg, err := sub.Next(s.ctx) if err != nil { // This should only happen when the context is cancelled or subscription is cancelled. - if err != pubsub.ErrSubscriptionCancelled { // Only log a warning on unexpected errors. + if !errors.Is(err, pubsub.ErrSubscriptionCancelled) { // Only log a warning on unexpected errors. log.WithError(err).Warn("Subscription next failed") } // Cancel subscription in the event of an error, as we are diff --git a/beacon-chain/verification/blob_test.go b/beacon-chain/verification/blob_test.go index 9148c4a6a902..d5df7db2a65d 100644 --- a/beacon-chain/verification/blob_test.go +++ b/beacon-chain/verification/blob_test.go @@ -507,7 +507,8 @@ func TestRequirementSatisfaction(t *testing.T) { _, err := v.VerifiedROBlob() require.ErrorIs(t, err, ErrBlobInvalid) - me, ok := err.(VerificationMultiError) + var me VerificationMultiError + ok := errors.As(err, &me) require.Equal(t, true, ok) fails := me.Failures() // we haven't performed any verification, so all the results should be this type diff --git a/beacon-chain/verification/cache.go b/beacon-chain/verification/cache.go index d1ca89def527..ebfb09bd53fa 100644 --- a/beacon-chain/verification/cache.go +++ b/beacon-chain/verification/cache.go @@ -5,20 +5,19 @@ import ( "fmt" lru "github.com/hashicorp/golang-lru" - lruwrpr "github.com/prysmaticlabs/prysm/v5/cache/lru" - log "github.com/sirupsen/logrus" - "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/signing" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/transition" forkchoicetypes "github.com/prysmaticlabs/prysm/v5/beacon-chain/forkchoice/types" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" + lruwrpr "github.com/prysmaticlabs/prysm/v5/cache/lru" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/crypto/bls" "github.com/prysmaticlabs/prysm/v5/network/forks" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/time/slots" + log "github.com/sirupsen/logrus" ) const ( diff --git a/cmd/prysmctl/p2p/handler.go b/cmd/prysmctl/p2p/handler.go index 085e3c8352a9..c0aa289e0a56 100644 --- a/cmd/prysmctl/p2p/handler.go +++ b/cmd/prysmctl/p2p/handler.go @@ -9,6 +9,7 @@ import ( libp2pcore "github.com/libp2p/go-libp2p/core" corenet "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/protocol" + "github.com/pkg/errors" ssz "github.com/prysmaticlabs/fastssz" "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p" p2ptypes "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/types" @@ -51,7 +52,7 @@ func (c *client) registerRPCHandler(baseTopic string, handle rpcHandler) { // do not decode anything. if baseTopic == p2p.RPCMetaDataTopicV1 || baseTopic == p2p.RPCMetaDataTopicV2 { if err := handle(context.Background(), base, stream); err != nil { - if err != p2ptypes.ErrWrongForkDigestVersion { + if !errors.Is(err, p2ptypes.ErrWrongForkDigestVersion) { log.WithError(err).Debug("Could not handle p2p RPC") } } @@ -73,7 +74,7 @@ func (c *client) registerRPCHandler(baseTopic string, handle rpcHandler) { return } if err := handle(context.Background(), msg, stream); err != nil { - if err != p2ptypes.ErrWrongForkDigestVersion { + if !errors.Is(err, p2ptypes.ErrWrongForkDigestVersion) { log.WithError(err).Debug("Could not handle p2p RPC") } } @@ -89,7 +90,7 @@ func (c *client) registerRPCHandler(baseTopic string, handle rpcHandler) { return } if err := handle(context.Background(), nTyp.Elem().Interface(), stream); err != nil { - if err != p2ptypes.ErrWrongForkDigestVersion { + if !errors.Is(err, p2ptypes.ErrWrongForkDigestVersion) { log.WithError(err).Debug("Could not handle p2p RPC") } } diff --git a/cmd/prysmctl/testnet/generate_genesis.go b/cmd/prysmctl/testnet/generate_genesis.go index 9fcee9a064fe..00357e075e6e 100644 --- a/cmd/prysmctl/testnet/generate_genesis.go +++ b/cmd/prysmctl/testnet/generate_genesis.go @@ -174,11 +174,11 @@ func cliActionGenerateGenesisState(cliCtx *cli.Context) error { ) } if err := setGlobalParams(); err != nil { - return fmt.Errorf("could not set config params: %v", err) + return fmt.Errorf("could not set config params: %w", err) } st, err := generateGenesis(cliCtx.Context) if err != nil { - return fmt.Errorf("could not generate genesis state: %v", err) + return fmt.Errorf("could not generate genesis state: %w", err) } if outputJson != "" { @@ -218,7 +218,7 @@ func setGlobalParams() error { } cfg, err := params.ByName(generateGenesisStateFlags.ConfigName) if err != nil { - return fmt.Errorf("unable to find config using name %s: %v", generateGenesisStateFlags.ConfigName, err) + return fmt.Errorf("unable to find config using name %s: %w", generateGenesisStateFlags.ConfigName, err) } return params.SetActive(cfg.Copy()) } diff --git a/config/features/config.go b/config/features/config.go index 833c562d7587..925d32a89e28 100644 --- a/config/features/config.go +++ b/config/features/config.go @@ -23,11 +23,10 @@ import ( "sync" "time" - "github.com/sirupsen/logrus" - "github.com/urfave/cli/v2" - "github.com/prysmaticlabs/prysm/v5/cmd" "github.com/prysmaticlabs/prysm/v5/config/params" + "github.com/sirupsen/logrus" + "github.com/urfave/cli/v2" ) var log = logrus.WithField("prefix", "flags") diff --git a/config/params/loader.go b/config/params/loader.go index 6a4359064129..e8e2aba491ab 100644 --- a/config/params/loader.go +++ b/config/params/loader.go @@ -53,7 +53,8 @@ func UnmarshalConfig(yamlFile []byte, conf *BeaconChainConfig) (*BeaconChainConf } yamlFile = []byte(strings.Join(lines, "\n")) if err := yaml.UnmarshalStrict(yamlFile, conf); err != nil { - if _, ok := err.(*yaml.TypeError); !ok { + var typeError *yaml.TypeError + if !errors.As(err, &typeError) { return nil, errors.Wrap(err, "Failed to parse chain config yaml file.") } else { log.WithError(err).Error("There were some issues parsing the config from a yaml file") diff --git a/consensus-types/blocks/proto.go b/consensus-types/blocks/proto.go index af75d83e6ee8..4704c08ed4e0 100644 --- a/consensus-types/blocks/proto.go +++ b/consensus-types/blocks/proto.go @@ -977,7 +977,7 @@ func initBlockBodyFromProtoBellatrix(pb *eth.BeaconBlockBodyBellatrix) (*BeaconB p, err := WrappedExecutionPayload(pb.ExecutionPayload) // We allow the payload to be nil - if err != nil && err != consensus_types.ErrNilObjectWrapped { + if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err } b := &BeaconBlockBody{ @@ -1003,7 +1003,7 @@ func initBlindedBlockBodyFromProtoBellatrix(pb *eth.BlindedBeaconBlockBodyBellat ph, err := WrappedExecutionPayloadHeader(pb.ExecutionPayloadHeader) // We allow the payload to be nil - if err != nil && err != consensus_types.ErrNilObjectWrapped { + if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err } b := &BeaconBlockBody{ @@ -1029,7 +1029,7 @@ func initBlockBodyFromProtoCapella(pb *eth.BeaconBlockBodyCapella) (*BeaconBlock p, err := WrappedExecutionPayloadCapella(pb.ExecutionPayload) // We allow the payload to be nil - if err != nil && err != consensus_types.ErrNilObjectWrapped { + if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err } b := &BeaconBlockBody{ @@ -1056,7 +1056,7 @@ func initBlindedBlockBodyFromProtoCapella(pb *eth.BlindedBeaconBlockBodyCapella) ph, err := WrappedExecutionPayloadHeaderCapella(pb.ExecutionPayloadHeader) // We allow the payload to be nil - if err != nil && err != consensus_types.ErrNilObjectWrapped { + if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err } b := &BeaconBlockBody{ @@ -1083,7 +1083,7 @@ func initBlockBodyFromProtoDeneb(pb *eth.BeaconBlockBodyDeneb) (*BeaconBlockBody p, err := WrappedExecutionPayloadDeneb(pb.ExecutionPayload) // We allow the payload to be nil - if err != nil && err != consensus_types.ErrNilObjectWrapped { + if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err } b := &BeaconBlockBody{ @@ -1111,7 +1111,7 @@ func initBlindedBlockBodyFromProtoDeneb(pb *eth.BlindedBeaconBlockBodyDeneb) (*B ph, err := WrappedExecutionPayloadHeaderDeneb(pb.ExecutionPayloadHeader) // We allow the payload to be nil - if err != nil && err != consensus_types.ErrNilObjectWrapped { + if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err } b := &BeaconBlockBody{ @@ -1139,7 +1139,7 @@ func initBlockBodyFromProtoElectra(pb *eth.BeaconBlockBodyElectra) (*BeaconBlock p, err := WrappedExecutionPayloadElectra(pb.ExecutionPayload) // We allow the payload to be nil - if err != nil && err != consensus_types.ErrNilObjectWrapped { + if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err } b := &BeaconBlockBody{ @@ -1167,7 +1167,7 @@ func initBlindedBlockBodyFromProtoElectra(pb *eth.BlindedBeaconBlockBodyElectra) ph, err := WrappedExecutionPayloadHeaderElectra(pb.ExecutionPayloadHeader) // We allow the payload to be nil - if err != nil && err != consensus_types.ErrNilObjectWrapped { + if err != nil && !errors.Is(err, consensus_types.ErrNilObjectWrapped) { return nil, err } b := &BeaconBlockBody{ diff --git a/encoding/ssz/detect/configfork.go b/encoding/ssz/detect/configfork.go index 79099512cc9b..327b68198cd4 100644 --- a/encoding/ssz/detect/configfork.go +++ b/encoding/ssz/detect/configfork.go @@ -3,18 +3,17 @@ package detect import ( "fmt" - state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native" - "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" - "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" - "github.com/prysmaticlabs/prysm/v5/network/forks" - "github.com/pkg/errors" ssz "github.com/prysmaticlabs/fastssz" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" + state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" + "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" + "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" + "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" + "github.com/prysmaticlabs/prysm/v5/network/forks" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/runtime/version" "github.com/prysmaticlabs/prysm/v5/time/slots" diff --git a/encoding/ssz/detect/configfork_test.go b/encoding/ssz/detect/configfork_test.go index 5a5e41a912f2..d417eeeb1fd9 100644 --- a/encoding/ssz/detect/configfork_test.go +++ b/encoding/ssz/detect/configfork_test.go @@ -9,14 +9,13 @@ import ( "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" + "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" + ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/runtime/version" + "github.com/prysmaticlabs/prysm/v5/testing/require" "github.com/prysmaticlabs/prysm/v5/testing/util" "github.com/prysmaticlabs/prysm/v5/time/slots" - - "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" - ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/v5/testing/require" ) func TestSlotFromBlock(t *testing.T) { diff --git a/io/file/fileutil.go b/io/file/fileutil.go index 19b4ff976c6e..f00a55f94f32 100644 --- a/io/file/fileutil.go +++ b/io/file/fileutil.go @@ -198,7 +198,7 @@ func RecursiveFileFind(filename, dir string) (bool, string, error) { // no errors or file found return nil }) - if err != nil && err != errStopWalk { + if err != nil && !errors.Is(err, errStopWalk) { return false, "", err } return found, fpath, nil @@ -231,7 +231,7 @@ func RecursiveDirFind(dirname, dir string) (bool, string, error) { return nil }) - if err != nil && err != errStopWalk { + if err != nil && !errors.Is(err, errStopWalk) { return false, "", errors.Wrapf(err, "error walking directory %s", dir) } diff --git a/monitoring/clientstats/updaters.go b/monitoring/clientstats/updaters.go index a431339d4af1..19bedd6eaf4d 100644 --- a/monitoring/clientstats/updaters.go +++ b/monitoring/clientstats/updaters.go @@ -43,7 +43,7 @@ func (gw *httpPoster) Update(r io.Reader) error { buf := new(bytes.Buffer) _, err = io.Copy(buf, resp.Body) if err != nil { - return fmt.Errorf("error reading response body for non-200 response status code (%d), err=%s", resp.StatusCode, err) + return fmt.Errorf("error reading response body for non-200 response status code (%d), err=%w", resp.StatusCode, err) } return fmt.Errorf("non-200 response status code (%d). response body=%s", resp.StatusCode, buf.String()) } diff --git a/runtime/interop/generate_keys.go b/runtime/interop/generate_keys.go index 915eb19a6fb5..c3990fda9a0c 100644 --- a/runtime/interop/generate_keys.go +++ b/runtime/interop/generate_keys.go @@ -5,12 +5,11 @@ import ( "math/big" "sync" - "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" - "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/async" "github.com/prysmaticlabs/prysm/v5/crypto/bls" "github.com/prysmaticlabs/prysm/v5/crypto/hash" + "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" ) const ( diff --git a/runtime/logging/logrus-prefixed-formatter/formatter_test.go b/runtime/logging/logrus-prefixed-formatter/formatter_test.go index f3a26d474301..615ff5c6a5f9 100644 --- a/runtime/logging/logrus-prefixed-formatter/formatter_test.go +++ b/runtime/logging/logrus-prefixed-formatter/formatter_test.go @@ -5,12 +5,11 @@ import ( "regexp" "testing" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" "github.com/pkg/errors" prefixed "github.com/prysmaticlabs/prysm/v5/runtime/logging/logrus-prefixed-formatter" "github.com/prysmaticlabs/prysm/v5/testing/require" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" "github.com/sirupsen/logrus" ) diff --git a/runtime/logging/logrus-prefixed-formatter/logrus_prefixed_formatter_suite_test.go b/runtime/logging/logrus-prefixed-formatter/logrus_prefixed_formatter_suite_test.go index c95894a70f54..78e9b2fbf756 100644 --- a/runtime/logging/logrus-prefixed-formatter/logrus_prefixed_formatter_suite_test.go +++ b/runtime/logging/logrus-prefixed-formatter/logrus_prefixed_formatter_suite_test.go @@ -1,10 +1,10 @@ package prefixed_test import ( + "testing" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - - "testing" ) type LogOutput struct { diff --git a/runtime/tos/tos.go b/runtime/tos/tos.go index f4727e6673fc..7b9b9f6a4811 100644 --- a/runtime/tos/tos.go +++ b/runtime/tos/tos.go @@ -4,9 +4,8 @@ import ( "path/filepath" "strings" - "github.com/pkg/errors" - "github.com/logrusorgru/aurora" + "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/cmd" "github.com/prysmaticlabs/prysm/v5/io/file" "github.com/prysmaticlabs/prysm/v5/io/prompt" diff --git a/testing/endtoend/components/eth1/depositor_test.go b/testing/endtoend/components/eth1/depositor_test.go index 87e37955737a..7f01282c90c5 100644 --- a/testing/endtoend/components/eth1/depositor_test.go +++ b/testing/endtoend/components/eth1/depositor_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/testing/require" ) diff --git a/testing/endtoend/components/eth1/transactions.go b/testing/endtoend/components/eth1/transactions.go index 15fd02277f31..5426adae257d 100644 --- a/testing/endtoend/components/eth1/transactions.go +++ b/testing/endtoend/components/eth1/transactions.go @@ -380,7 +380,7 @@ func randomBlobData() ([]byte, error) { return nil, err } if n != size { - return nil, fmt.Errorf("could not create random blob data with size %d: %v", size, err) + return nil, fmt.Errorf("could not create random blob data with size %d: %w", size, err) } return data, nil } diff --git a/testing/endtoend/endtoend_test.go b/testing/endtoend/endtoend_test.go index 96200ccb5cc1..8e8f3d51e4f8 100644 --- a/testing/endtoend/endtoend_test.go +++ b/testing/endtoend/endtoend_test.go @@ -16,18 +16,15 @@ import ( "testing" "time" + "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/api/client/beacon" + "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/transition" + "github.com/prysmaticlabs/prysm/v5/config/params" + "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" "github.com/prysmaticlabs/prysm/v5/io/file" "github.com/prysmaticlabs/prysm/v5/network/forks" enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/transition" - "github.com/prysmaticlabs/prysm/v5/config/params" - "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" "github.com/prysmaticlabs/prysm/v5/testing/endtoend/components" @@ -40,6 +37,8 @@ import ( log "github.com/sirupsen/logrus" "golang.org/x/sync/errgroup" "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/emptypb" ) @@ -417,7 +416,7 @@ func (r *testRunner) testDoppelGangerProtection(ctx context.Context) error { } logFile, err := os.Create(path.Join(e2e.TestParams.LogPath, fmt.Sprintf(e2e.ValidatorLogFileName, valIndex))) if err != nil { - return fmt.Errorf("unable to open log file: %v", err) + return fmt.Errorf("unable to open log file: %w", err) } r.t.Run("doppelganger found", func(t *testing.T) { assert.NoError(t, helpers.WaitForTextInFile(logFile, "Duplicate instances exists in the network for validator keys"), "Failed to carry out doppelganger check correctly") diff --git a/testing/endtoend/evaluators/fork.go b/testing/endtoend/evaluators/fork.go index bb04f3146358..54463043585a 100644 --- a/testing/endtoend/evaluators/fork.go +++ b/testing/endtoend/evaluators/fork.go @@ -75,7 +75,7 @@ func altairForkOccurs(_ *types.EvaluationContext, conns ...*grpc.ClientConn) err if err != nil { return err } - if ctx.Err() == context.Canceled { + if errors.Is(ctx.Err(), context.Canceled) { return errors.New("context canceled prematurely") } res, err := stream.Recv() @@ -117,7 +117,7 @@ func bellatrixForkOccurs(_ *types.EvaluationContext, conns ...*grpc.ClientConn) if err != nil { return err } - if ctx.Err() == context.Canceled { + if errors.Is(ctx.Err(), context.Canceled) { return errors.New("context canceled prematurely") } res, err := stream.Recv() @@ -162,7 +162,7 @@ func capellaForkOccurs(_ *types.EvaluationContext, conns ...*grpc.ClientConn) er if err != nil { return err } - if ctx.Err() == context.Canceled { + if errors.Is(ctx.Err(), context.Canceled) { return errors.New("context canceled prematurely") } res, err := stream.Recv() @@ -205,7 +205,7 @@ func denebForkOccurs(_ *types.EvaluationContext, conns ...*grpc.ClientConn) erro if err != nil { return err } - if ctx.Err() == context.Canceled { + if errors.Is(ctx.Err(), context.Canceled) { return errors.New("context canceled prematurely") } res, err := stream.Recv() diff --git a/testing/endtoend/params/params.go b/testing/endtoend/params/params.go index 8ef153c9fd61..dd71b9c53cdd 100644 --- a/testing/endtoend/params/params.go +++ b/testing/endtoend/params/params.go @@ -14,9 +14,8 @@ import ( "testing" "time" - "github.com/ethereum/go-ethereum/core/types" - "github.com/bazelbuild/rules_go/go/tools/bazel" + "github.com/ethereum/go-ethereum/core/types" "github.com/prysmaticlabs/prysm/v5/io/file" ) diff --git a/testing/middleware/builder/builder.go b/testing/middleware/builder/builder.go index 592b96eefff7..a0ed717c0fd3 100644 --- a/testing/middleware/builder/builder.go +++ b/testing/middleware/builder/builder.go @@ -29,7 +29,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" types "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v5/crypto/bls" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" "github.com/prysmaticlabs/prysm/v5/network" @@ -795,7 +794,7 @@ func decodeTransactions(enc [][]byte) ([]*gethTypes.Transaction, error) { for i, encTx := range enc { var tx gethTypes.Transaction if err := tx.UnmarshalBinary(encTx); err != nil { - return nil, fmt.Errorf("invalid transaction %d: %v", i, err) + return nil, fmt.Errorf("invalid transaction %d: %w", i, err) } txs[i] = &tx } diff --git a/testing/spectest/shared/common/forkchoice/runner.go b/testing/spectest/shared/common/forkchoice/runner.go index 3ca092873692..4f4784446f6c 100644 --- a/testing/spectest/shared/common/forkchoice/runner.go +++ b/testing/spectest/shared/common/forkchoice/runner.go @@ -2,6 +2,7 @@ package forkchoice import ( "context" + "errors" "fmt" "os" "path" @@ -415,7 +416,8 @@ func errAssertionForStep(step Step, expect error) func(t *testing.T, err error) return func(t *testing.T, err error) { if err != nil { require.ErrorIs(t, err, verification.ErrBlobInvalid) - me, ok := err.(verification.VerificationMultiError) + var me verification.VerificationMultiError + ok := errors.As(err, &me) require.Equal(t, true, ok) fails := me.Failures() // we haven't performed any verification, so all the results should be this type diff --git a/tools/analyzers/logruswitherror/testdata/src/a/a.go b/tools/analyzers/logruswitherror/testdata/src/a/a.go index 6bbb4b082869..51ab1f662524 100644 --- a/tools/analyzers/logruswitherror/testdata/src/a/a.go +++ b/tools/analyzers/logruswitherror/testdata/src/a/a.go @@ -31,7 +31,7 @@ func LogThis(err error) { log.WithError(err).Error("Something bad happened, but this log statement is OK :)") - _ = fmt.Errorf("this is ok: %v", err) + _ = fmt.Errorf("this is ok: %w", err) } func do() (bool, error) { diff --git a/tools/replay-http/BUILD.bazel b/tools/replay-http/BUILD.bazel index 81c3bef62b91..2e49a793a2b6 100644 --- a/tools/replay-http/BUILD.bazel +++ b/tools/replay-http/BUILD.bazel @@ -6,7 +6,10 @@ go_library( srcs = ["main.go"], importpath = "github.com/prysmaticlabs/prysm/v5/tools/replay-http", visibility = ["//visibility:private"], - deps = ["@com_github_sirupsen_logrus//:go_default_library"], + deps = [ + "@com_github_pkg_errors//:go_default_library", + "@com_github_sirupsen_logrus//:go_default_library", + ], ) go_binary( diff --git a/tools/replay-http/main.go b/tools/replay-http/main.go index 517afad2a4b5..9c1bddcdde37 100644 --- a/tools/replay-http/main.go +++ b/tools/replay-http/main.go @@ -16,6 +16,7 @@ import ( "os" "path" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) @@ -42,7 +43,7 @@ func main() { lr := bufio.NewReader(f) for { line, err := lr.ReadBytes([]byte("\n")[0]) - if err == io.EOF { + if errors.Is(err, io.EOF) { os.Exit(0) } if err != nil { diff --git a/validator/accounts/userprompt/prompt.go b/validator/accounts/userprompt/prompt.go index 2aad4ba01ef6..e7083ab3d739 100644 --- a/validator/accounts/userprompt/prompt.go +++ b/validator/accounts/userprompt/prompt.go @@ -59,12 +59,12 @@ func InputDirectory(cliCtx *cli.Context, promptText string, flag *cli.StringFlag // FormatPromptError for the user. func FormatPromptError(err error) error { - switch err { - case promptui.ErrAbort: + switch { + case errors.Is(err, promptui.ErrAbort): return errors.New("wallet creation aborted, closing") - case promptui.ErrInterrupt: + case errors.Is(err, promptui.ErrInterrupt): return errors.New("keyboard interrupt, closing") - case promptui.ErrEOF: + case errors.Is(err, promptui.ErrEOF): return errors.New("no input received, closing") default: return err diff --git a/validator/client/aggregate_test.go b/validator/client/aggregate_test.go index 7951a744a2f0..fc820b0ed5ef 100644 --- a/validator/client/aggregate_test.go +++ b/validator/client/aggregate_test.go @@ -6,8 +6,6 @@ import ( "fmt" "testing" - "github.com/prysmaticlabs/prysm/v5/validator/client/iface" - "github.com/prysmaticlabs/go-bitfield" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" @@ -19,6 +17,7 @@ import ( "github.com/prysmaticlabs/prysm/v5/testing/util" "github.com/prysmaticlabs/prysm/v5/time" "github.com/prysmaticlabs/prysm/v5/time/slots" + "github.com/prysmaticlabs/prysm/v5/validator/client/iface" logTest "github.com/sirupsen/logrus/hooks/test" "go.uber.org/mock/gomock" ) diff --git a/validator/client/beacon-api/beacon_api_helpers.go b/validator/client/beacon-api/beacon_api_helpers.go index a931e4d96905..ea82f84d6e9e 100644 --- a/validator/client/beacon-api/beacon_api_helpers.go +++ b/validator/client/beacon-api/beacon_api_helpers.go @@ -12,7 +12,6 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/api/server/structs" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" - ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" ) diff --git a/validator/client/beacon-api/beacon_api_validator_client_test.go b/validator/client/beacon-api/beacon_api_validator_client_test.go index 5b7587862ff2..63599d9f2f82 100644 --- a/validator/client/beacon-api/beacon_api_validator_client_test.go +++ b/validator/client/beacon-api/beacon_api_validator_client_test.go @@ -6,17 +6,16 @@ import ( "fmt" "testing" - "github.com/prysmaticlabs/prysm/v5/api/server/structs" - "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" - "go.uber.org/mock/gomock" - "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/prysmaticlabs/prysm/v5/api/server/structs" "github.com/prysmaticlabs/prysm/v5/config/params" + "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" "github.com/prysmaticlabs/prysm/v5/testing/require" "github.com/prysmaticlabs/prysm/v5/validator/client/beacon-api/mock" + "go.uber.org/mock/gomock" ) // Make sure that AttestationData() returns the same thing as the internal attestationData() diff --git a/validator/client/beacon-api/beacon_committee_selections.go b/validator/client/beacon-api/beacon_committee_selections.go index 304b2a7abfe4..44a25ebd8ea9 100644 --- a/validator/client/beacon-api/beacon_committee_selections.go +++ b/validator/client/beacon-api/beacon_committee_selections.go @@ -5,9 +5,8 @@ import ( "context" "encoding/json" - "github.com/prysmaticlabs/prysm/v5/validator/client/iface" - "github.com/pkg/errors" + "github.com/prysmaticlabs/prysm/v5/validator/client/iface" ) type aggregatedSelectionResponse struct { diff --git a/validator/client/beacon-api/beacon_committee_selections_test.go b/validator/client/beacon-api/beacon_committee_selections_test.go index c0f1ff3d1523..647e7eee98d0 100644 --- a/validator/client/beacon-api/beacon_committee_selections_test.go +++ b/validator/client/beacon-api/beacon_committee_selections_test.go @@ -6,12 +6,11 @@ import ( "encoding/json" "testing" - "github.com/prysmaticlabs/prysm/v5/validator/client/iface" - "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/testing/require" "github.com/prysmaticlabs/prysm/v5/validator/client/beacon-api/mock" testhelpers "github.com/prysmaticlabs/prysm/v5/validator/client/beacon-api/test-helpers" + "github.com/prysmaticlabs/prysm/v5/validator/client/iface" "go.uber.org/mock/gomock" ) diff --git a/validator/client/beacon-api/doppelganger.go b/validator/client/beacon-api/doppelganger.go index 3b9c52c4ca80..2fa3887156f6 100644 --- a/validator/client/beacon-api/doppelganger.go +++ b/validator/client/beacon-api/doppelganger.go @@ -6,9 +6,8 @@ import ( "fmt" "strconv" - "github.com/pkg/errors" - "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/runtime/version" diff --git a/validator/client/beacon-api/status.go b/validator/client/beacon-api/status.go index bdec7502fec5..e0055b34a599 100644 --- a/validator/client/beacon-api/status.go +++ b/validator/client/beacon-api/status.go @@ -4,13 +4,12 @@ import ( "context" "strconv" - "github.com/prysmaticlabs/prysm/v5/validator/client/iface" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" + "github.com/prysmaticlabs/prysm/v5/validator/client/iface" ) func (c *beaconApiValidatorClient) validatorStatus(ctx context.Context, in *ethpb.ValidatorStatusRequest) (*ethpb.ValidatorStatusResponse, error) { diff --git a/validator/client/beacon-api/status_test.go b/validator/client/beacon-api/status_test.go index 1803929d4f72..abff246c8f3e 100644 --- a/validator/client/beacon-api/status_test.go +++ b/validator/client/beacon-api/status_test.go @@ -6,16 +6,15 @@ import ( "fmt" "testing" - "github.com/prysmaticlabs/prysm/v5/api/server/structs" - "github.com/prysmaticlabs/prysm/v5/validator/client/iface" - "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/prysmaticlabs/prysm/v5/api/server/structs" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" "github.com/prysmaticlabs/prysm/v5/testing/require" "github.com/prysmaticlabs/prysm/v5/validator/client/beacon-api/mock" + "github.com/prysmaticlabs/prysm/v5/validator/client/iface" "go.uber.org/mock/gomock" ) diff --git a/validator/client/grpc-api/grpc_prysm_beacon_chain_client.go b/validator/client/grpc-api/grpc_prysm_beacon_chain_client.go index 5082107af548..dac34f019dc6 100644 --- a/validator/client/grpc-api/grpc_prysm_beacon_chain_client.go +++ b/validator/client/grpc-api/grpc_prysm_beacon_chain_client.go @@ -6,7 +6,6 @@ import ( "sort" "github.com/golang/protobuf/ptypes/empty" - "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/helpers" statenative "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native" @@ -58,15 +57,15 @@ func validatorCountByStatus(validators []*ethpb.Validator, statuses []validator. for _, val := range validators { readOnlyVal, err := statenative.NewValidator(val) if err != nil { - return nil, fmt.Errorf("could not convert validator: %v", err) + return nil, fmt.Errorf("could not convert validator: %w", err) } valStatus, err := helpers.ValidatorStatus(readOnlyVal, epoch) if err != nil { - return nil, fmt.Errorf("could not get validator status: %v", err) + return nil, fmt.Errorf("could not get validator status: %w", err) } valSubStatus, err := helpers.ValidatorSubStatus(readOnlyVal, epoch) if err != nil { - return nil, fmt.Errorf("could not get validator sub status: %v", err) + return nil, fmt.Errorf("could not get validator sub status: %w", err) } for _, status := range statuses { diff --git a/validator/client/iface/validator_client.go b/validator/client/iface/validator_client.go index f22d64e8cfa9..1fe0e85530ca 100644 --- a/validator/client/iface/validator_client.go +++ b/validator/client/iface/validator_client.go @@ -6,9 +6,8 @@ import ( "strconv" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/pkg/errors" - "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/api/client/event" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" diff --git a/validator/client/key_reload.go b/validator/client/key_reload.go index abb452071423..ab01e89f9306 100644 --- a/validator/client/key_reload.go +++ b/validator/client/key_reload.go @@ -4,11 +4,10 @@ import ( "context" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v5/validator/client/iface" - fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" validator2 "github.com/prysmaticlabs/prysm/v5/consensus-types/validator" eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" + "github.com/prysmaticlabs/prysm/v5/validator/client/iface" "go.opencensus.io/trace" ) diff --git a/validator/client/key_reload_test.go b/validator/client/key_reload_test.go index ae48c159eba4..781317341470 100644 --- a/validator/client/key_reload_test.go +++ b/validator/client/key_reload_test.go @@ -4,15 +4,14 @@ import ( "context" "testing" - validator2 "github.com/prysmaticlabs/prysm/v5/consensus-types/validator" - "github.com/prysmaticlabs/prysm/v5/validator/client/iface" - "github.com/pkg/errors" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" + validator2 "github.com/prysmaticlabs/prysm/v5/consensus-types/validator" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" "github.com/prysmaticlabs/prysm/v5/testing/require" validatormock "github.com/prysmaticlabs/prysm/v5/testing/validator-mock" + "github.com/prysmaticlabs/prysm/v5/validator/client/iface" "github.com/prysmaticlabs/prysm/v5/validator/client/testutil" logTest "github.com/sirupsen/logrus/hooks/test" "go.uber.org/mock/gomock" diff --git a/validator/client/sync_committee.go b/validator/client/sync_committee.go index cefa2bd53f2b..f32b1ce0fede 100644 --- a/validator/client/sync_committee.go +++ b/validator/client/sync_committee.go @@ -6,11 +6,9 @@ import ( "sync/atomic" "time" - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v5/validator/client/iface" - "github.com/ethereum/go-ethereum/common/hexutil" emptypb "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/signing" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" @@ -21,6 +19,7 @@ import ( ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" validatorpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/v5/time/slots" + "github.com/prysmaticlabs/prysm/v5/validator/client/iface" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) diff --git a/validator/client/validator.go b/validator/client/validator.go index 447f8e919fa2..4d8fbc668061 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -265,7 +265,7 @@ func (v *validator) WaitForChainStart(ctx context.Context) error { log.Info("Syncing with beacon node to align on chain genesis info") chainStartRes, err := v.validatorClient.WaitForChainStart(ctx, &emptypb.Empty{}) - if err == io.EOF { + if errors.Is(err, io.EOF) { return client.ErrConnectionIssue } diff --git a/validator/client/wait_for_activation_test.go b/validator/client/wait_for_activation_test.go index 5b6200466fa7..333075fb637d 100644 --- a/validator/client/wait_for_activation_test.go +++ b/validator/client/wait_for_activation_test.go @@ -7,18 +7,17 @@ import ( "testing" "time" - "github.com/prysmaticlabs/prysm/v5/config/params" - validatorType "github.com/prysmaticlabs/prysm/v5/consensus-types/validator" - "github.com/prysmaticlabs/prysm/v5/validator/client/iface" - "github.com/pkg/errors" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" + "github.com/prysmaticlabs/prysm/v5/config/params" + validatorType "github.com/prysmaticlabs/prysm/v5/consensus-types/validator" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" "github.com/prysmaticlabs/prysm/v5/testing/mock" "github.com/prysmaticlabs/prysm/v5/testing/require" validatormock "github.com/prysmaticlabs/prysm/v5/testing/validator-mock" walletMock "github.com/prysmaticlabs/prysm/v5/validator/accounts/testing" + "github.com/prysmaticlabs/prysm/v5/validator/client/iface" "github.com/prysmaticlabs/prysm/v5/validator/keymanager/derived" constant "github.com/prysmaticlabs/prysm/v5/validator/testing" logTest "github.com/sirupsen/logrus/hooks/test" diff --git a/validator/db/common/progress.go b/validator/db/common/progress.go index c9bbf211bbd3..9d622f682456 100644 --- a/validator/db/common/progress.go +++ b/validator/db/common/progress.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/k0kubun/go-ansi" - "github.com/schollz/progressbar/v3" ) diff --git a/validator/db/convert.go b/validator/db/convert.go index 25126e9e9e04..4b9626541838 100644 --- a/validator/db/convert.go +++ b/validator/db/convert.go @@ -125,14 +125,13 @@ func ConvertDatabase(ctx context.Context, sourceDataDir string, targetDataDir st // Get the proposer settings. proposerSettings, err := sourceDatabase.ProposerSettings(ctx) - switch err { - case nil: + switch { + case err == nil: // Save the proposer settings. if err := targetDatabase.SaveProposerSettings(ctx, proposerSettings); err != nil { return errors.Wrap(err, "could not save proposer settings") } - - case kv.ErrNoProposerSettingsFound, filesystem.ErrNoProposerSettingsFound: + case errors.Is(err, kv.ErrNoProposerSettingsFound), errors.Is(err, filesystem.ErrNoProposerSettingsFound): // Nothing to do. default: return errors.Wrap(err, "could not get proposer settings from source database") diff --git a/validator/db/convert_test.go b/validator/db/convert_test.go index 4718891daf92..eb581c109ffd 100644 --- a/validator/db/convert_test.go +++ b/validator/db/convert_test.go @@ -16,7 +16,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/validator/db/common" "github.com/prysmaticlabs/prysm/v5/validator/db/filesystem" "github.com/prysmaticlabs/prysm/v5/validator/db/iface" - "github.com/prysmaticlabs/prysm/v5/validator/db/kv" ) diff --git a/validator/db/filesystem/db.go b/validator/db/filesystem/db.go index edaf9ea61c5e..50d1f27e29c1 100644 --- a/validator/db/filesystem/db.go +++ b/validator/db/filesystem/db.go @@ -11,14 +11,13 @@ import ( "time" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/pkg/errors" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/io/file" validatorpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/v5/validator/db/iface" - "gopkg.in/yaml.v3" - - "github.com/pkg/errors" "github.com/sirupsen/logrus" + "gopkg.in/yaml.v3" ) const ( diff --git a/validator/db/filesystem/db_test.go b/validator/db/filesystem/db_test.go index 5d1b5110ceaa..0a2df5c1f632 100644 --- a/validator/db/filesystem/db_test.go +++ b/validator/db/filesystem/db_test.go @@ -11,7 +11,6 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/proposer" - "github.com/prysmaticlabs/prysm/v5/crypto/bls" "github.com/prysmaticlabs/prysm/v5/io/file" "github.com/prysmaticlabs/prysm/v5/testing/require" diff --git a/validator/db/filesystem/proposer_settings.go b/validator/db/filesystem/proposer_settings.go index b4f443542d7b..db539f8c9b83 100644 --- a/validator/db/filesystem/proposer_settings.go +++ b/validator/db/filesystem/proposer_settings.go @@ -4,7 +4,6 @@ import ( "context" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v5/config/proposer" ) diff --git a/validator/db/filesystem/proposer_settings_test.go b/validator/db/filesystem/proposer_settings_test.go index 6d481775e176..3905210b8b9b 100644 --- a/validator/db/filesystem/proposer_settings_test.go +++ b/validator/db/filesystem/proposer_settings_test.go @@ -61,7 +61,7 @@ func TestStore_ProposerSettings(t *testing.T) { configuration: &Configuration{ ProposerSettings: &validatorpb.ProposerSettingsPayload{ ProposerConfig: map[string]*validatorpb.ProposerOptionPayload{ - pubkeyString: &validatorpb.ProposerOptionPayload{ + pubkeyString: { FeeRecipient: customFeeRecipientString, }, }, @@ -72,7 +72,7 @@ func TestStore_ProposerSettings(t *testing.T) { }, expectedProposerSettings: &proposer.Settings{ ProposeConfig: map[[fieldparams.BLSPubkeyLength]byte]*proposer.Option{ - pubkey: &proposer.Option{ + pubkey: { FeeRecipientConfig: &proposer.FeeRecipientConfig{ FeeRecipient: customFeeRecipient, }, diff --git a/validator/graffiti/BUILD.bazel b/validator/graffiti/BUILD.bazel index dac4a43cf662..5dc68db9c998 100644 --- a/validator/graffiti/BUILD.bazel +++ b/validator/graffiti/BUILD.bazel @@ -11,6 +11,7 @@ go_library( deps = [ "//consensus-types/primitives:go_default_library", "//crypto/hash:go_default_library", + "@com_github_pkg_errors//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@in_gopkg_yaml_v2//:go_default_library", ], diff --git a/validator/graffiti/parse_graffiti.go b/validator/graffiti/parse_graffiti.go index b1199a97e264..358eabd4935e 100644 --- a/validator/graffiti/parse_graffiti.go +++ b/validator/graffiti/parse_graffiti.go @@ -5,6 +5,7 @@ import ( "os" "strings" + "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/crypto/hash" "gopkg.in/yaml.v2" @@ -32,7 +33,8 @@ func ParseGraffitiFile(f string) (*Graffiti, error) { } g := &Graffiti{} if err := yaml.UnmarshalStrict(yamlFile, g); err != nil { - if _, ok := err.(*yaml.TypeError); !ok { + var typeError *yaml.TypeError + if !errors.As(err, &typeError) { return nil, err } else { log.WithError(err).Error("There were some issues parsing graffiti from a yaml file.") diff --git a/validator/helpers/metadata_test.go b/validator/helpers/metadata_test.go index ca010f058198..0df70229c697 100644 --- a/validator/helpers/metadata_test.go +++ b/validator/helpers/metadata_test.go @@ -9,7 +9,6 @@ import ( "github.com/prometheus/client_golang/prometheus" fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/proposer" - "github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" diff --git a/validator/keymanager/remote-web3signer/v1/custom_mappers.go b/validator/keymanager/remote-web3signer/v1/custom_mappers.go index e6440445d688..69581fb5b00a 100644 --- a/validator/keymanager/remote-web3signer/v1/custom_mappers.go +++ b/validator/keymanager/remote-web3signer/v1/custom_mappers.go @@ -121,35 +121,35 @@ func MapBeaconBlockBody(body *ethpb.BeaconBlockBody) (*BeaconBlockBody, error) { for i, slashing := range body.ProposerSlashings { slashing, err := MapProposerSlashing(slashing) if err != nil { - return nil, fmt.Errorf("could not map proposer slashing at index %v: %v", i, err) + return nil, fmt.Errorf("could not map proposer slashing at index %v: %w", i, err) } block.ProposerSlashings[i] = slashing } for i, slashing := range body.AttesterSlashings { slashing, err := MapAttesterSlashing(slashing) if err != nil { - return nil, fmt.Errorf("could not map attester slashing at index %v: %v", i, err) + return nil, fmt.Errorf("could not map attester slashing at index %v: %w", i, err) } block.AttesterSlashings[i] = slashing } for i, attestation := range body.Attestations { attestation, err := MapAttestation(attestation) if err != nil { - return nil, fmt.Errorf("could not map attestation at index %v: %v", i, err) + return nil, fmt.Errorf("could not map attestation at index %v: %w", i, err) } block.Attestations[i] = attestation } for i, Deposit := range body.Deposits { deposit, err := MapDeposit(Deposit) if err != nil { - return nil, fmt.Errorf("could not map deposit at index %v: %v", i, err) + return nil, fmt.Errorf("could not map deposit at index %v: %w", i, err) } block.Deposits[i] = deposit } for i, signedVoluntaryExit := range body.VoluntaryExits { signedVoluntaryExit, err := MapSignedVoluntaryExit(signedVoluntaryExit) if err != nil { - return nil, fmt.Errorf("could not map signed voluntary exit at index %v: %v", i, err) + return nil, fmt.Errorf("could not map signed voluntary exit at index %v: %w", i, err) } block.VoluntaryExits[i] = signedVoluntaryExit } @@ -322,35 +322,35 @@ func MapBeaconBlockBodyAltair(body *ethpb.BeaconBlockBodyAltair) (*BeaconBlockBo for i, slashing := range body.ProposerSlashings { proposer, err := MapProposerSlashing(slashing) if err != nil { - return nil, fmt.Errorf("could not map proposer slashing at index %v: %v", i, err) + return nil, fmt.Errorf("could not map proposer slashing at index %v: %w", i, err) } block.ProposerSlashings[i] = proposer } for i, slashing := range body.AttesterSlashings { attesterSlashing, err := MapAttesterSlashing(slashing) if err != nil { - return nil, fmt.Errorf("could not map attester slashing at index %v: %v", i, err) + return nil, fmt.Errorf("could not map attester slashing at index %v: %w", i, err) } block.AttesterSlashings[i] = attesterSlashing } for i, attestation := range body.Attestations { attestation, err := MapAttestation(attestation) if err != nil { - return nil, fmt.Errorf("could not map attestation at index %v: %v", i, err) + return nil, fmt.Errorf("could not map attestation at index %v: %w", i, err) } block.Attestations[i] = attestation } for i, deposit := range body.Deposits { deposit, err := MapDeposit(deposit) if err != nil { - return nil, fmt.Errorf("could not map deposit at index %v: %v", i, err) + return nil, fmt.Errorf("could not map deposit at index %v: %w", i, err) } block.Deposits[i] = deposit } for i, exit := range body.VoluntaryExits { exit, err := MapSignedVoluntaryExit(exit) if err != nil { - return nil, fmt.Errorf("could not map signed voluntary exit at index %v: %v", i, err) + return nil, fmt.Errorf("could not map signed voluntary exit at index %v: %w", i, err) } block.VoluntaryExits[i] = exit } diff --git a/validator/rpc/handler_wallet.go b/validator/rpc/handler_wallet.go index e3771ac69175..d100d6ce0e3d 100644 --- a/validator/rpc/handler_wallet.go +++ b/validator/rpc/handler_wallet.go @@ -31,7 +31,7 @@ func (s *Server) CreateWallet(w http.ResponseWriter, r *http.Request) { var req CreateWalletRequest err := json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -176,7 +176,7 @@ func (s *Server) RecoverWallet(w http.ResponseWriter, r *http.Request) { var req RecoverWalletRequest err := json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -278,7 +278,7 @@ func (*Server) ValidateKeystores(w http.ResponseWriter, r *http.Request) { var req ValidateKeystoresRequest err := json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: diff --git a/validator/rpc/handlers_accounts.go b/validator/rpc/handlers_accounts.go index 8ad2bbb85a32..724c0353b77c 100644 --- a/validator/rpc/handlers_accounts.go +++ b/validator/rpc/handlers_accounts.go @@ -95,7 +95,7 @@ func (s *Server) ListAccounts(w http.ResponseWriter, r *http.Request) { } start, end, nextPageToken, err := pagination.StartAndEndPage(pageToken, int(ps), len(keys)) if err != nil { - httputil.HandleError(w, fmt.Errorf("Could not paginate results: %v", + httputil.HandleError(w, fmt.Errorf("Could not paginate results: %w", err).Error(), http.StatusInternalServerError) return } @@ -123,7 +123,7 @@ func (s *Server) BackupAccounts(w http.ResponseWriter, r *http.Request) { var req BackupAccountsRequest err := json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -232,7 +232,7 @@ func (s *Server) VoluntaryExit(w http.ResponseWriter, r *http.Request) { var req VoluntaryExitRequest err := json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: diff --git a/validator/rpc/handlers_keymanager.go b/validator/rpc/handlers_keymanager.go index 236945a2489b..d45dc17ce355 100644 --- a/validator/rpc/handlers_keymanager.go +++ b/validator/rpc/handlers_keymanager.go @@ -95,7 +95,7 @@ func (s *Server) ImportKeystores(w http.ResponseWriter, r *http.Request) { var req ImportKeystoresRequest err = json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -190,7 +190,7 @@ func (s *Server) DeleteKeystores(w http.ResponseWriter, r *http.Request) { var req DeleteKeystoresRequest err = json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -287,11 +287,11 @@ func (s *Server) publicKeysInDB(ctx context.Context) (map[[fieldparams.BLSPubkey pubKeysInDB := make(map[[fieldparams.BLSPubkeyLength]byte]bool) attestedPublicKeys, err := s.db.AttestedPublicKeys(ctx) if err != nil { - return nil, fmt.Errorf("could not get attested public keys from DB: %v", err) + return nil, fmt.Errorf("could not get attested public keys from DB: %w", err) } proposedPublicKeys, err := s.db.ProposedPublicKeys(ctx) if err != nil { - return nil, fmt.Errorf("could not get proposed public keys from DB: %v", err) + return nil, fmt.Errorf("could not get proposed public keys from DB: %w", err) } for _, pk := range append(attestedPublicKeys, proposedPublicKeys...) { pubKeysInDB[pk] = true @@ -451,7 +451,7 @@ func (s *Server) ImportRemoteKeys(w http.ResponseWriter, r *http.Request) { var req ImportRemoteKeysRequest err = json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -518,7 +518,7 @@ func (s *Server) DeleteRemoteKeys(w http.ResponseWriter, r *http.Request) { var req DeleteRemoteKeysRequest err = json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -605,7 +605,7 @@ func (s *Server) SetFeeRecipientByPubkey(w http.ResponseWriter, r *http.Request) var req SetFeeRecipientByPubkeyRequest err := json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -756,7 +756,7 @@ func (s *Server) SetGasLimit(w http.ResponseWriter, r *http.Request) { var req SetGasLimitRequest err := json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: @@ -899,7 +899,7 @@ func (s *Server) SetGraffiti(w http.ResponseWriter, r *http.Request) { } err := json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: diff --git a/validator/rpc/handlers_slashing.go b/validator/rpc/handlers_slashing.go index 49a1596bd66e..595047e2f25a 100644 --- a/validator/rpc/handlers_slashing.go +++ b/validator/rpc/handlers_slashing.go @@ -62,7 +62,7 @@ func (s *Server) ImportSlashingProtection(w http.ResponseWriter, r *http.Request var req ImportSlashingProtectionRequest err := json.NewDecoder(r.Body).Decode(&req) switch { - case err == io.EOF: + case errors.Is(err, io.EOF): httputil.HandleError(w, "No data submitted", http.StatusBadRequest) return case err != nil: