mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-14 18:30:52 +02:00
netann: let ValidateChannelAnn take the new interface
This commit is contained in:
@@ -1890,7 +1890,7 @@ func (d *AuthenticatedGossiper) processRejectedEdge(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = netann.ValidateChannelAnn(chanAnn)
|
err = netann.ValidateChannelAnn(chanAnn, d.fetchPKScript)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("assembled channel announcement proof "+
|
err := fmt.Errorf("assembled channel announcement proof "+
|
||||||
"for shortChanID=%v isn't valid: %v",
|
"for shortChanID=%v isn't valid: %v",
|
||||||
@@ -2540,7 +2540,8 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
|
|||||||
// the signatures within the proof as it should be well formed.
|
// the signatures within the proof as it should be well formed.
|
||||||
var proof *models.ChannelAuthProof
|
var proof *models.ChannelAuthProof
|
||||||
if nMsg.isRemote {
|
if nMsg.isRemote {
|
||||||
if err := netann.ValidateChannelAnn(ann); err != nil {
|
err := netann.ValidateChannelAnn(ann, d.fetchPKScript)
|
||||||
|
if err != nil {
|
||||||
err := fmt.Errorf("unable to validate announcement: "+
|
err := fmt.Errorf("unable to validate announcement: "+
|
||||||
"%v", err)
|
"%v", err)
|
||||||
|
|
||||||
@@ -3434,7 +3435,8 @@ func (d *AuthenticatedGossiper) handleAnnSig(nMsg *networkMsg,
|
|||||||
|
|
||||||
// With all the necessary components assembled validate the full
|
// With all the necessary components assembled validate the full
|
||||||
// channel announcement proof.
|
// channel announcement proof.
|
||||||
if err := netann.ValidateChannelAnn(chanAnn); err != nil {
|
err = netann.ValidateChannelAnn(chanAnn, d.fetchPKScript)
|
||||||
|
if err != nil {
|
||||||
err := fmt.Errorf("channel announcement proof for "+
|
err := fmt.Errorf("channel announcement proof for "+
|
||||||
"short_chan_id=%v isn't valid: %v", shortChanID, err)
|
"short_chan_id=%v isn't valid: %v", shortChanID, err)
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ package netann
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
@@ -88,10 +89,25 @@ func CreateChanAnnouncement(chanProof *models.ChannelAuthProof,
|
|||||||
return chanAnn, edge1Ann, edge2Ann, nil
|
return chanAnn, edge1Ann, edge2Ann, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateChannelAnn validates the channel announcement message and checks
|
// FetchPkScript defines a function that can be used to fetch the output script
|
||||||
|
// for the transaction with the given SCID.
|
||||||
|
type FetchPkScript func(*lnwire.ShortChannelID) ([]byte, error)
|
||||||
|
|
||||||
|
// ValidateChannelAnn validates the channel announcement.
|
||||||
|
func ValidateChannelAnn(a lnwire.ChannelAnnouncement, _ FetchPkScript) error {
|
||||||
|
switch ann := a.(type) {
|
||||||
|
case *lnwire.ChannelAnnouncement1:
|
||||||
|
return validateChannelAnn1(ann)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unhandled implementation of "+
|
||||||
|
"lnwire.ChannelAnnouncement: %T", a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// validateChannelAnn1 validates the channel announcement message and checks
|
||||||
// that node signatures covers the announcement message, and that the bitcoin
|
// that node signatures covers the announcement message, and that the bitcoin
|
||||||
// signatures covers the node keys.
|
// signatures covers the node keys.
|
||||||
func ValidateChannelAnn(a *lnwire.ChannelAnnouncement1) error {
|
func validateChannelAnn1(a *lnwire.ChannelAnnouncement1) error {
|
||||||
// First, we'll compute the digest (h) which is to be signed by each of
|
// First, we'll compute the digest (h) which is to be signed by each of
|
||||||
// the keys included within the node announcement message. This hash
|
// the keys included within the node announcement message. This hash
|
||||||
// digest includes all the keys, so the (up to 4 signatures) will
|
// digest includes all the keys, so the (up to 4 signatures) will
|
||||||
|
Reference in New Issue
Block a user