From 6c3513c0775e1e1e69a7c9e5c86255804fa3fb36 Mon Sep 17 00:00:00 2001 From: zhiqiangxu <652732310@qq.com> Date: Mon, 14 Feb 2022 19:05:48 +0800 Subject: [PATCH] p2p: reduce the scope of variable dialPubkey (#24385) dialPubkey isn't used anywhere else after dialDest.Load, so it should be safe to restrict its scope to the if clause. --- p2p/server.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/p2p/server.go b/p2p/server.go index bcfc1bd10..138975e54 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -943,9 +943,8 @@ func (srv *Server) setupConn(c *conn, flags connFlag, dialDest *enode.Node) erro } // If dialing, figure out the remote public key. - var dialPubkey *ecdsa.PublicKey if dialDest != nil { - dialPubkey = new(ecdsa.PublicKey) + dialPubkey := new(ecdsa.PublicKey) if err := dialDest.Load((*enode.Secp256k1)(dialPubkey)); err != nil { err = errors.New("dial destination doesn't have a secp256k1 public key") srv.log.Trace("Setting up connection failed", "addr", c.fd.RemoteAddr(), "conn", c.flags, "err", err)