node/pkg/p2p: Prevent potential nil pointer dereference when processing heartbeats

Resolves the problem occurring when dereferencing a nil `gk *ecdsa.PublicKey`
during heartbeat processing. This issue arises when non-guardian processes
utilizing the p2p package set the key to `nil`.
This commit is contained in:
Kevin Peters 2023-11-14 16:04:32 -06:00 committed by kev1n-peters
parent 745351199b
commit dfbdc9afb4
1 changed files with 1 additions and 1 deletions

View File

@ -607,7 +607,7 @@ func Run(
zap.String("from", envelope.GetFrom().String())) zap.String("from", envelope.GetFrom().String()))
} else { } else {
guardianAddr := eth_common.BytesToAddress(s.GuardianAddr) guardianAddr := eth_common.BytesToAddress(s.GuardianAddr)
if guardianAddr != ethcrypto.PubkeyToAddress(gk.PublicKey) { if gk == nil || guardianAddr != ethcrypto.PubkeyToAddress(gk.PublicKey) {
prevPeerId, ok := components.ProtectedHostByGuardianKey[guardianAddr] prevPeerId, ok := components.ProtectedHostByGuardianKey[guardianAddr]
if ok { if ok {
if prevPeerId != peerId { if prevPeerId != peerId {