Skip to content

Commit 54abb97

Browse files
needkanefjl
authored andcommitted
p2p: use errors.New instead of fmt.Errorf (#18193)
1 parent ef8ced4 commit 54abb97

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

p2p/server.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"crypto/ecdsa"
2323
"encoding/hex"
2424
"errors"
25-
"fmt"
2625
"net"
2726
"sort"
2827
"sync"
@@ -391,7 +390,7 @@ type sharedUDPConn struct {
391390
func (s *sharedUDPConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error) {
392391
packet, ok := <-s.unhandled
393392
if !ok {
394-
return 0, nil, fmt.Errorf("Connection was closed")
393+
return 0, nil, errors.New("Connection was closed")
395394
}
396395
l := len(packet.Data)
397396
if l > len(b) {
@@ -425,7 +424,7 @@ func (srv *Server) Start() (err error) {
425424

426425
// static fields
427426
if srv.PrivateKey == nil {
428-
return fmt.Errorf("Server.PrivateKey must be set to a non-nil key")
427+
return errors.New("Server.PrivateKey must be set to a non-nil key")
429428
}
430429
if srv.newTransport == nil {
431430
srv.newTransport = newRLPX
@@ -903,7 +902,7 @@ func (srv *Server) setupConn(c *conn, flags connFlag, dialDest *enode.Node) erro
903902
if dialDest != nil {
904903
dialPubkey = new(ecdsa.PublicKey)
905904
if err := dialDest.Load((*enode.Secp256k1)(dialPubkey)); err != nil {
906-
return fmt.Errorf("dial destination doesn't have a secp256k1 public key")
905+
return errors.New("dial destination doesn't have a secp256k1 public key")
907906
}
908907
}
909908
// Run the encryption handshake.
@@ -937,7 +936,7 @@ func (srv *Server) setupConn(c *conn, flags connFlag, dialDest *enode.Node) erro
937936
return err
938937
}
939938
if id := c.node.ID(); !bytes.Equal(crypto.Keccak256(phs.ID), id[:]) {
940-
clog.Trace("Wrong devp2p handshake identity", "phsid", fmt.Sprintf("%x", phs.ID))
939+
clog.Trace("Wrong devp2p handshake identity", "phsid", hex.EncodeToString(phs.ID))
941940
return DiscUnexpectedIdentity
942941
}
943942
c.caps, c.name = phs.Caps, phs.Name

0 commit comments

Comments
 (0)