diff --git a/beacon-chain/core/helpers/slot_epoch.go b/beacon-chain/core/helpers/slot_epoch.go index ed5874d32c..654f06027c 100644 --- a/beacon-chain/core/helpers/slot_epoch.go +++ b/beacon-chain/core/helpers/slot_epoch.go @@ -139,11 +139,11 @@ func VerifySlotTime(genesisTime, slot uint64, timeTolerance time.Duration) error func SlotToTime(genesisTimeSec, slot uint64) (time.Time, error) { timeSinceGenesis, err := mathutil.Mul64(slot, params.BeaconConfig().SecondsPerSlot) if err != nil { - return time.Unix(0, 0), fmt.Errorf("slot (%d) is in the far distant future: %v", slot, err) + return time.Unix(0, 0), fmt.Errorf("slot (%d) is in the far distant future: %w", slot, err) } sTime, err := mathutil.Add64(genesisTimeSec, timeSinceGenesis) if err != nil { - return time.Unix(0, 0), fmt.Errorf("slot (%d) is in the far distant future: %v", slot, err) + return time.Unix(0, 0), fmt.Errorf("slot (%d) is in the far distant future: %w", slot, err) } return time.Unix(int64(sTime), 0), nil } diff --git a/beacon-chain/core/state/transition.go b/beacon-chain/core/state/transition.go index 687050efa4..87c636c6d7 100644 --- a/beacon-chain/core/state/transition.go +++ b/beacon-chain/core/state/transition.go @@ -294,7 +294,7 @@ func ProcessSlots(ctx context.Context, state *stateTrie.BeaconState, slot uint64 highestSlot = cachedState.Slot() state = cachedState } - if err := SkipSlotCache.MarkInProgress(key); err == cache.ErrAlreadyInProgress { + if err := SkipSlotCache.MarkInProgress(key); errors.Is(err, cache.ErrAlreadyInProgress) { cachedState, err = SkipSlotCache.Get(ctx, key) if err != nil { return nil, err diff --git a/beacon-chain/db/kv/kv.go b/beacon-chain/db/kv/kv.go index d4cf9cad6c..823d30285d 100644 --- a/beacon-chain/db/kv/kv.go +++ b/beacon-chain/db/kv/kv.go @@ -52,7 +52,7 @@ func NewKVStore(dirPath string, stateSummaryCache *cache.StateSummaryCache) (*St datafile := path.Join(dirPath, databaseFileName) boltDB, err := bolt.Open(datafile, params.BeaconIoConfig().ReadWritePermissions, &bolt.Options{Timeout: 1 * time.Second, InitialMmapSize: 10e6}) if err != nil { - if err == bolt.ErrTimeout { + if errors.Is(err, bolt.ErrTimeout) { return nil, errors.New("cannot obtain database lock, database may be in use by another process") } return nil, err diff --git a/beacon-chain/p2p/handshake.go b/beacon-chain/p2p/handshake.go index c61834927a..4c9050f26f 100644 --- a/beacon-chain/p2p/handshake.go +++ b/beacon-chain/p2p/handshake.go @@ -2,6 +2,7 @@ package p2p import ( "context" + "errors" "fmt" "io" "sync" @@ -110,7 +111,7 @@ func (s *Service) AddConnectionHandler(reqFunc func(ctx context.Context, id peer } // If peer hasn't sent a status request, we disconnect with them - if _, err := s.peers.ChainState(remotePeer); err == peerdata.ErrPeerUnknown { + if _, err := s.peers.ChainState(remotePeer); errors.Is(err, peerdata.ErrPeerUnknown) { disconnectFromPeer() return } diff --git a/beacon-chain/rpc/beacon/validators_stream.go b/beacon-chain/rpc/beacon/validators_stream.go index bbed068832..78b96ea336 100644 --- a/beacon-chain/rpc/beacon/validators_stream.go +++ b/beacon-chain/rpc/beacon/validators_stream.go @@ -132,7 +132,7 @@ func (is *infostream) handleConnection() error { go func() { for { msg, err := is.stream.Recv() - if err == io.EOF { + if errors.Is(err, io.EOF) { return } if err != nil { diff --git a/beacon-chain/rpc/validator/attester.go b/beacon-chain/rpc/validator/attester.go index 221da8aaea..a947ac9bf4 100644 --- a/beacon-chain/rpc/validator/attester.go +++ b/beacon-chain/rpc/validator/attester.go @@ -2,6 +2,7 @@ package validator import ( "context" + "errors" "fmt" ptypes "github.com/gogo/protobuf/types" @@ -48,7 +49,7 @@ func (vs *Server) GetAttestationData(ctx context.Context, req *ethpb.Attestation } if err := vs.AttestationCache.MarkInProgress(req); err != nil { - if err == cache.ErrAlreadyInProgress { + if errors.Is(err, cache.ErrAlreadyInProgress) { res, err := vs.AttestationCache.Get(ctx, req) if err != nil { return nil, status.Errorf(codes.Internal, "Could not retrieve data from attestation cache: %v", err) diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher.go b/beacon-chain/sync/initial-sync/blocks_fetcher.go index 9fddf2f961..0175ab3251 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher.go @@ -364,7 +364,7 @@ func (f *blocksFetcher) requestBlocks( for i := uint64(0); ; i++ { isFirstChunk := i == 0 blk, err := prysmsync.ReadChunkedBlock(stream, f.p2p, isFirstChunk) - if err == io.EOF { + if errors.Is(err, io.EOF) { break } if err != nil { diff --git a/beacon-chain/sync/initial-sync/blocks_queue.go b/beacon-chain/sync/initial-sync/blocks_queue.go index 34b22af8fb..99211d94b1 100644 --- a/beacon-chain/sync/initial-sync/blocks_queue.go +++ b/beacon-chain/sync/initial-sync/blocks_queue.go @@ -202,7 +202,7 @@ func (q *blocksQueue) loop() { "start": fsm.start, "error": err.Error(), }).Debug("Can not trigger event") - if err == errNoRequiredPeers { + if errors.Is(err, errNoRequiredPeers) { forceExit := q.exitConditions.noRequiredPeersErrRetries > noRequiredPeersErrMaxRetries if q.mode == modeStopOnFinalizedEpoch || forceExit { q.cancel() diff --git a/beacon-chain/sync/rpc_beacon_blocks_by_root.go b/beacon-chain/sync/rpc_beacon_blocks_by_root.go index 07c094ca7d..ac0f79fdee 100644 --- a/beacon-chain/sync/rpc_beacon_blocks_by_root.go +++ b/beacon-chain/sync/rpc_beacon_blocks_by_root.go @@ -31,7 +31,7 @@ func (s *Service) sendRecentBeaconBlocksRequest(ctx context.Context, blockRoots for i := 0; i < len(*blockRoots); i++ { isFirstChunk := i == 0 blk, err := ReadChunkedBlock(stream, s.p2p, isFirstChunk) - if err == io.EOF { + if errors.Is(err, io.EOF) { break } // Exit if peer sends more than max request blocks. diff --git a/beacon-chain/sync/rpc_ping.go b/beacon-chain/sync/rpc_ping.go index eaad89edc7..fc4757c82e 100644 --- a/beacon-chain/sync/rpc_ping.go +++ b/beacon-chain/sync/rpc_ping.go @@ -33,7 +33,7 @@ func (s *Service) pingHandler(_ context.Context, msg interface{}, stream libp2pc valid, err := s.validateSequenceNum(*m, stream.Conn().RemotePeer()) if err != nil { // Descore peer for giving us a bad sequence number. - if err == errInvalidSequenceNum { + if errors.Is(err, errInvalidSequenceNum) { s.p2p.Peers().Scorers().BadResponsesScorer().Increment(stream.Conn().RemotePeer()) s.writeErrorResponseToStream(responseCodeInvalidRequest, seqError, stream) } @@ -122,7 +122,7 @@ func (s *Service) sendPingRequest(ctx context.Context, id peer.ID) error { valid, err := s.validateSequenceNum(*msg, stream.Conn().RemotePeer()) if err != nil { // Descore peer for giving us a bad sequence number. - if err == errInvalidSequenceNum { + if errors.Is(err, errInvalidSequenceNum) { s.p2p.Peers().Scorers().BadResponsesScorer().Increment(stream.Conn().RemotePeer()) } return err diff --git a/beacon-chain/sync/rpc_status.go b/beacon-chain/sync/rpc_status.go index 1ce39a7a4f..c9af1b62d1 100644 --- a/beacon-chain/sync/rpc_status.go +++ b/beacon-chain/sync/rpc_status.go @@ -156,7 +156,7 @@ func (s *Service) sendRPCStatusRequest(ctx context.Context, id peer.ID) error { if err != nil { s.p2p.Peers().Scorers().BadResponsesScorer().Increment(stream.Conn().RemotePeer()) // Disconnect if on a wrong fork. - if err == errWrongForkDigestVersion { + if errors.Is(err, errWrongForkDigestVersion) { if err := s.sendGoodByeAndDisconnect(ctx, codeWrongNetwork, stream.Conn().RemotePeer()); err != nil { return err } diff --git a/shared/aggregation/attestations/maxcover.go b/shared/aggregation/attestations/maxcover.go index 96a5611137..0362b96931 100644 --- a/shared/aggregation/attestations/maxcover.go +++ b/shared/aggregation/attestations/maxcover.go @@ -32,7 +32,7 @@ func MaxCoverAttestationAggregation(atts []*ethpb.Attestation) ([]*ethpb.Attesta // Find maximum non-overlapping coverage. maxCover, err := NewMaxCover(unaggregated) if err != nil { - if err == aggregation.ErrBitsDifferentLen { + if errors.Is(err, aggregation.ErrBitsDifferentLen) { return atts, nil } return aggregated.merge(unaggregated), err diff --git a/shared/prometheus/content_negotiation.go b/shared/prometheus/content_negotiation.go index 4bb56d9e21..0b49e6ab3d 100644 --- a/shared/prometheus/content_negotiation.go +++ b/shared/prometheus/content_negotiation.go @@ -41,7 +41,7 @@ func writeResponse(w http.ResponseWriter, r *http.Request, response generatedRes return fmt.Errorf("unexpected data: %v", response.Data) } if _, err := w.Write(buf.Bytes()); err != nil { - return fmt.Errorf("could not write response body: %v", err) + return fmt.Errorf("could not write response body: %w", err) } case contentTypeJSON: w.Header().Set("Content-Type", contentTypeJSON) diff --git a/shared/promptutil/prompt.go b/shared/promptutil/prompt.go index f2db0f6a44..2d4a4b4174 100644 --- a/shared/promptutil/prompt.go +++ b/shared/promptutil/prompt.go @@ -148,12 +148,12 @@ func InputPassword( for !hasValidPassword { password, err = PasswordPrompt(promptText, passwordValidator) if err != nil { - return "", fmt.Errorf("could not read password: %v", err) + return "", fmt.Errorf("could not read password: %w", err) } if shouldConfirmPassword { passwordConfirmation, err := PasswordPrompt(confirmText, passwordValidator) if err != nil { - return "", fmt.Errorf("could not read password confirmation: %v", err) + return "", fmt.Errorf("could not read password confirmation: %w", err) } if password != passwordConfirmation { log.Error("Passwords do not match") diff --git a/slasher/beaconclient/receivers.go b/slasher/beaconclient/receivers.go index 1a562d1c1e..d06c52a664 100644 --- a/slasher/beaconclient/receivers.go +++ b/slasher/beaconclient/receivers.go @@ -35,7 +35,7 @@ func (bs *Service) ReceiveBlocks(ctx context.Context) { for { res, err := stream.Recv() // If the stream is closed, we stop the loop. - if err == io.EOF { + if errors.Is(err, io.EOF) { break } // If context is canceled we stop the loop. @@ -103,7 +103,7 @@ func (bs *Service) ReceiveAttestations(ctx context.Context) { for { res, err := stream.Recv() // If the stream is closed, we stop the loop. - if err == io.EOF { + if errors.Is(err, io.EOF) { log.Info("Attestation stream closed") break } diff --git a/slasher/db/kv/kv.go b/slasher/db/kv/kv.go index 9cc1a45e0a..dbe5ef1373 100644 --- a/slasher/db/kv/kv.go +++ b/slasher/db/kv/kv.go @@ -90,7 +90,7 @@ func NewKVStore(dirPath string, cfg *Config) (*Store, error) { datafile := path.Join(dirPath, databaseFileName) boltDB, err := bolt.Open(datafile, params.BeaconIoConfig().ReadWritePermissions, &bolt.Options{Timeout: params.BeaconIoConfig().BoltTimeout}) if err != nil { - if err == bolt.ErrTimeout { + if errors.Is(err, bolt.ErrTimeout) { return nil, errors.New("cannot obtain database lock, database may be in use by another process") } return nil, err diff --git a/tools/cluster-pk-manager/server/server.go b/tools/cluster-pk-manager/server/server.go index a1e1c2abbe..97aaf9197c 100644 --- a/tools/cluster-pk-manager/server/server.go +++ b/tools/cluster-pk-manager/server/server.go @@ -223,7 +223,7 @@ func (s *server) checkDepositTxs(ctx context.Context, txMap map[*keystore.Key]*t pks := make([][]byte, 0, len(txMap)) for k, tx := range txMap { receipt, err := s.client.TransactionReceipt(ctx, tx.Hash()) - if err == ethereum.NotFound { + if errors.Is(err, ethereum.NotFound) { // tx still not processed yet. continue } diff --git a/validator/accounts/v1/account.go b/validator/accounts/v1/account.go index a159d8d704..4e59bef743 100644 --- a/validator/accounts/v1/account.go +++ b/validator/accounts/v1/account.go @@ -149,7 +149,7 @@ func Exists(keystorePath string, assertNonEmpty bool) (bool, error) { if assertNonEmpty { _, err = f.Readdirnames(1) // Or f.Readdir(1) - if err == io.EOF { + if errors.Is(err, io.EOF) { return false, nil } } diff --git a/validator/accounts/v2/accounts_import.go b/validator/accounts/v2/accounts_import.go index 073e25b3f1..c4ff733ce7 100644 --- a/validator/accounts/v2/accounts_import.go +++ b/validator/accounts/v2/accounts_import.go @@ -176,7 +176,7 @@ func ImportAccountsCli(cliCtx *cli.Context) error { "Enter the password for your imported accounts", promptutil.NotEmpty, ) if err != nil { - return fmt.Errorf("could not read account password: %v", err) + return fmt.Errorf("could not read account password: %w", err) } } fmt.Println("Importing accounts, this may take a while...") diff --git a/validator/accounts/v2/wallet/wallet.go b/validator/accounts/v2/wallet/wallet.go index f06a70dcd0..7c1e1607bf 100644 --- a/validator/accounts/v2/wallet/wallet.go +++ b/validator/accounts/v2/wallet/wallet.go @@ -109,7 +109,7 @@ func Exists(walletDir string) (bool, error) { return false, errors.Wrap(err, "could not parse wallet directory") } isValid, err := IsValid(walletDir) - if err == ErrNoWalletFound { + if errors.Is(err, ErrNoWalletFound) { return false, nil } else if err != nil { return false, errors.Wrap(err, "could not check if dir is valid") @@ -169,7 +169,7 @@ func OpenWalletOrElseCli(cliCtx *cli.Context, otherwise func(cliCtx *cli.Context return otherwise(cliCtx) } isValid, err := IsValid(cliCtx.String(flags.WalletDirFlag.Name)) - if err == ErrNoWalletFound { + if errors.Is(err, ErrNoWalletFound) { return otherwise(cliCtx) } if err != nil { @@ -222,7 +222,7 @@ func OpenWallet(_ context.Context, cfg *Config) (*Wallet, error) { } valid, err := IsValid(cfg.WalletDir) // ErrNoWalletFound represents both a directory that does not exist as well as an empty directory - if err == ErrNoWalletFound { + if errors.Is(err, ErrNoWalletFound) { return nil, ErrNoWalletFound } if err != nil { @@ -536,13 +536,13 @@ func inputPassword( for !hasValidPassword { walletPassword, err = promptutil.PasswordPrompt(promptText, passwordValidator) if err != nil { - return "", fmt.Errorf("could not read account password: %v", err) + return "", fmt.Errorf("could not read account password: %w", err) } if confirmPassword { passwordConfirmation, err := promptutil.PasswordPrompt(ConfirmPasswordPromptText, passwordValidator) if err != nil { - return "", fmt.Errorf("could not read password confirmation: %v", err) + return "", fmt.Errorf("could not read password confirmation: %w", err) } if walletPassword != passwordConfirmation { log.Error("Passwords do not match") diff --git a/validator/accounts/v2/wallet_recover.go b/validator/accounts/v2/wallet_recover.go index 2eee078a4d..539c608c84 100644 --- a/validator/accounts/v2/wallet_recover.go +++ b/validator/accounts/v2/wallet_recover.go @@ -177,7 +177,7 @@ func inputMnemonic(cliCtx *cli.Context) (string, error) { }, ) if err != nil { - return "", fmt.Errorf("could not get mnemonic language: %v", err) + return "", fmt.Errorf("could not get mnemonic language: %w", err) } bip39.SetWordList(allowedLanguages[selectedLanguage]) mnemonicPhrase, err := promptutil.ValidatePrompt( @@ -185,7 +185,7 @@ func inputMnemonic(cliCtx *cli.Context) (string, error) { "Enter the seed phrase for the wallet you would like to recover", validateMnemonic) if err != nil { - return "", fmt.Errorf("could not get mnemonic phrase: %v", err) + return "", fmt.Errorf("could not get mnemonic phrase: %w", err) } return mnemonicPhrase, nil } diff --git a/validator/client/validator.go b/validator/client/validator.go index 6a039d6aab..b52689c657 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -263,7 +263,7 @@ func (v *validator) WaitForActivation(ctx context.Context) error { for { res, err := stream.Recv() // If the stream is closed, we stop the loop. - if err == io.EOF { + if errors.Is(err, io.EOF) { break } // If context is canceled we stop the loop. diff --git a/validator/db/kv/db.go b/validator/db/kv/db.go index 6225c0822a..b600362261 100644 --- a/validator/db/kv/db.go +++ b/validator/db/kv/db.go @@ -64,7 +64,7 @@ func NewKVStore(dirPath string, pubKeys [][48]byte) (*Store, error) { datafile := filepath.Join(dirPath, ProtectionDbFileName) boltDB, err := bolt.Open(datafile, params.BeaconIoConfig().ReadWritePermissions, &bolt.Options{Timeout: params.BeaconIoConfig().BoltTimeout}) if err != nil { - if err == bolt.ErrTimeout { + if errors.Is(err, bolt.ErrTimeout) { return nil, errors.New("cannot obtain database lock, database may be in use by another process") } return nil, err @@ -105,7 +105,7 @@ func GetKVStore(directory string) (*Store, error) { } boltDb, err := bolt.Open(fileName, params.BeaconIoConfig().ReadWritePermissions, &bolt.Options{Timeout: params.BeaconIoConfig().BoltTimeout}) if err != nil { - if err == bolt.ErrTimeout { + if errors.Is(err, bolt.ErrTimeout) { return nil, errors.New("cannot obtain database lock, database may be in use by another process") } return nil, err diff --git a/validator/rpc/auth.go b/validator/rpc/auth.go index ccdba78670..235c713235 100644 --- a/validator/rpc/auth.go +++ b/validator/rpc/auth.go @@ -133,7 +133,7 @@ func (s *Server) initializeWallet(ctx context.Context, cfg *wallet.Config) error return wallet.ErrNoWalletFound } valid, err := wallet.IsValid(cfg.WalletDir) - if err == wallet.ErrNoWalletFound { + if errors.Is(err, wallet.ErrNoWalletFound) { return wallet.ErrNoWalletFound } if err != nil { diff --git a/validator/rpc/wallet.go b/validator/rpc/wallet.go index 48d3014c0f..9274cb6cd2 100644 --- a/validator/rpc/wallet.go +++ b/validator/rpc/wallet.go @@ -4,6 +4,7 @@ import ( "context" "encoding/hex" "encoding/json" + "errors" "io/ioutil" "path/filepath" "strings" @@ -183,7 +184,7 @@ func (s *Server) WalletConfig(ctx context.Context, _ *ptypes.Empty) (*pb.WalletR return &pb.WalletResponse{}, nil } valid, err := wallet.IsValid(s.walletDir) - if err == wallet.ErrNoWalletFound { + if errors.Is(err, wallet.ErrNoWalletFound) { return &pb.WalletResponse{}, nil } if err != nil { @@ -255,7 +256,7 @@ func (s *Server) ChangePassword(ctx context.Context, req *pb.ChangePasswordReque return nil, status.Errorf(codes.FailedPrecondition, noWalletMsg) } valid, err := wallet.IsValid(s.walletDir) - if err == wallet.ErrNoWalletFound { + if errors.Is(err, wallet.ErrNoWalletFound) { return nil, status.Errorf(codes.FailedPrecondition, noWalletMsg) } if err != nil {