Skip to content

Commit

Permalink
p2p, log, rpc: use errors.New to replace fmt.Errorf with no parameters (
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2d3c authored Feb 26, 2024
1 parent 32d4d6e commit 26724fc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions log/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package log

import (
"bytes"
"errors"
"fmt"
"io"
"math/big"
Expand Down Expand Up @@ -77,7 +78,7 @@ func benchmarkLogger(b *testing.B, l Logger) {
tt = time.Now()
bigint = big.NewInt(100)
nilbig *big.Int
err = fmt.Errorf("Oh nooes it's crap")
err = errors.New("Oh nooes it's crap")
)
b.ReportAllocs()
b.ResetTimer()
Expand Down Expand Up @@ -106,7 +107,7 @@ func TestLoggerOutput(t *testing.T) {
tt = time.Time{}
bigint = big.NewInt(100)
nilbig *big.Int
err = fmt.Errorf("Oh nooes it's crap")
err = errors.New("Oh nooes it's crap")
smallUint = uint256.NewInt(500_000)
bigUint = &uint256.Int{0xff, 0xff, 0xff, 0xff}
)
Expand Down
4 changes: 2 additions & 2 deletions p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,13 +914,13 @@ func (srv *Server) checkInboundConn(remoteIP net.IP) error {
}
// Reject connections that do not match NetRestrict.
if srv.NetRestrict != nil && !srv.NetRestrict.Contains(remoteIP) {
return fmt.Errorf("not in netrestrict list")
return errors.New("not in netrestrict list")
}
// Reject Internet peers that try too often.
now := srv.clock.Now()
srv.inboundHistory.expire(now, nil)
if !netutil.IsLAN(remoteIP) && srv.inboundHistory.contains(remoteIP.String()) {
return fmt.Errorf("too many attempts")
return errors.New("too many attempts")
}
srv.inboundHistory.add(remoteIP.String(), now.Add(inboundThrottleTime))
return nil
Expand Down
3 changes: 2 additions & 1 deletion p2p/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package p2p
import (
"bytes"
"crypto/ecdsa"
"errors"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -157,7 +158,7 @@ func readProtocolHandshake(rw MsgReader) (*protoHandshake, error) {
return nil, err
}
if msg.Size > baseProtocolMaxMsgSize {
return nil, fmt.Errorf("message too big")
return nil, errors.New("message too big")
}
if msg.Code == discMsg {
// Disconnect before protocol handshake is valid according to the
Expand Down
7 changes: 4 additions & 3 deletions rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package rpc
import (
"context"
"encoding/json"
"errors"
"fmt"
"math"
"strings"
Expand Down Expand Up @@ -104,7 +105,7 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
return err
}
if blckNum > math.MaxInt64 {
return fmt.Errorf("block number larger than int64")
return errors.New("block number larger than int64")
}
*bn = BlockNumber(blckNum)
return nil
Expand Down Expand Up @@ -154,7 +155,7 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
err := json.Unmarshal(data, &e)
if err == nil {
if e.BlockNumber != nil && e.BlockHash != nil {
return fmt.Errorf("cannot specify both BlockHash and BlockNumber, choose one or the other")
return errors.New("cannot specify both BlockHash and BlockNumber, choose one or the other")
}
bnh.BlockNumber = e.BlockNumber
bnh.BlockHash = e.BlockHash
Expand Down Expand Up @@ -202,7 +203,7 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
return err
}
if blckNum > math.MaxInt64 {
return fmt.Errorf("blocknumber too high")
return errors.New("blocknumber too high")
}
bn := BlockNumber(blckNum)
bnh.BlockNumber = &bn
Expand Down

0 comments on commit 26724fc

Please sign in to comment.