mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-28 06:32:18 +02:00
netadd: split ValidatenodeAnn into sig and field checks
Check that the node ann doesnt contain more than 1 DNS addr. This will ensure that we now start rejecting new node announcements with multiple DNS addrs since this check is called in the gossiper before persisting a node ann to our local graph. It also validates the DNS fields according to BOLT #7 specs.
This commit is contained in:
committed by
Mohamed Awnallah
parent
41bd519859
commit
a7ae21d685
@@ -2,6 +2,7 @@ package netann
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"net"
|
||||
@@ -81,10 +82,45 @@ func SignNodeAnnouncement(signer lnwallet.MessageSigner,
|
||||
return err
|
||||
}
|
||||
|
||||
// ValidateNodeAnn validates the node announcement by ensuring that the
|
||||
// ValidateNodeAnn validates the fields and signature of a node announcement.
|
||||
func ValidateNodeAnn(a *lnwire.NodeAnnouncement) error {
|
||||
err := ValidateNodeAnnFields(a)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid node announcement fields: %w", err)
|
||||
}
|
||||
|
||||
return ValidateNodeAnnSignature(a)
|
||||
}
|
||||
|
||||
// ValidateNodeAnnFields validates the fields of a node announcement.
|
||||
func ValidateNodeAnnFields(a *lnwire.NodeAnnouncement) error {
|
||||
// Check that it only has at most one DNS address.
|
||||
hasDNSAddr := false
|
||||
for _, addr := range a.Addresses {
|
||||
dnsAddr, ok := addr.(*lnwire.DNSAddress)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if hasDNSAddr {
|
||||
return errors.New("node announcement contains " +
|
||||
"multiple DNS addresses. Only one is allowed")
|
||||
}
|
||||
|
||||
hasDNSAddr = true
|
||||
|
||||
err := lnwire.ValidateDNSAddr(dnsAddr.Hostname, dnsAddr.Port)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateNodeAnnSignature validates the node announcement by ensuring that the
|
||||
// attached signature is needed a signature of the node announcement under the
|
||||
// specified node public key.
|
||||
func ValidateNodeAnn(a *lnwire.NodeAnnouncement) error {
|
||||
func ValidateNodeAnnSignature(a *lnwire.NodeAnnouncement) error {
|
||||
// Reconstruct the data of announcement which should be covered by the
|
||||
// signature so we can verify the signature shortly below
|
||||
data, err := a.DataToSign()
|
||||
|
Reference in New Issue
Block a user