mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-26 17:52:25 +01:00
multi: use models.ChannelAuthProof interface where possible
This commit is contained in:
parent
fea428daba
commit
dcf72014a2
@ -1855,7 +1855,7 @@ func remotePubFromChanInfo(chanInfo models.ChannelEdgeInfo,
|
||||
// assemble the proof and craft the ChannelAnnouncement.
|
||||
func (d *AuthenticatedGossiper) processRejectedEdge(
|
||||
chanAnnMsg *lnwire.ChannelAnnouncement1,
|
||||
proof *models.ChannelAuthProof1) ([]networkMsg, error) {
|
||||
proof models.ChannelAuthProof) ([]networkMsg, error) {
|
||||
|
||||
// First, we'll fetch the state of the channel as we know if from the
|
||||
// database.
|
||||
@ -2557,7 +2557,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
|
||||
|
||||
// If this is a remote channel announcement, then we'll validate all
|
||||
// the signatures within the proof as it should be well formed.
|
||||
var proof *models.ChannelAuthProof1
|
||||
var proof models.ChannelAuthProof
|
||||
if nMsg.isRemote {
|
||||
if err := ann.Validate(d.fetchPKScript); err != nil {
|
||||
err := fmt.Errorf("unable to validate announcement: "+
|
||||
@ -2577,11 +2577,14 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
|
||||
// If the proof checks out, then we'll save the proof itself to
|
||||
// the database so we can fetch it later when gossiping with
|
||||
// other nodes.
|
||||
proof = &models.ChannelAuthProof1{
|
||||
NodeSig1Bytes: ann.NodeSig1.ToSignatureBytes(),
|
||||
NodeSig2Bytes: ann.NodeSig2.ToSignatureBytes(),
|
||||
BitcoinSig1Bytes: ann.BitcoinSig1.ToSignatureBytes(),
|
||||
BitcoinSig2Bytes: ann.BitcoinSig2.ToSignatureBytes(),
|
||||
proof, err = buildChanProof(ann)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("unable to build channel "+
|
||||
"announcement proof: %v", err)
|
||||
log.Error(err)
|
||||
nMsg.err <- err
|
||||
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
|
||||
@ -3581,6 +3584,29 @@ func (d *AuthenticatedGossiper) ShouldDisconnect(pubkey *btcec.PublicKey) (
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func buildChanProof(ann lnwire.ChannelAnnouncement) (
|
||||
models.ChannelAuthProof, error) {
|
||||
|
||||
switch a := ann.(type) {
|
||||
case *lnwire.ChannelAnnouncement1:
|
||||
return &models.ChannelAuthProof1{
|
||||
NodeSig1Bytes: a.NodeSig1.ToSignatureBytes(),
|
||||
NodeSig2Bytes: a.NodeSig2.ToSignatureBytes(),
|
||||
BitcoinSig1Bytes: a.BitcoinSig1.ToSignatureBytes(),
|
||||
BitcoinSig2Bytes: a.BitcoinSig2.ToSignatureBytes(),
|
||||
}, nil
|
||||
|
||||
case *lnwire.ChannelAnnouncement2:
|
||||
return &models.ChannelAuthProof2{
|
||||
SchnorrSigBytes: a.Signature.ToSignatureBytes(),
|
||||
}, nil
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("unhandled lnwire.ChannelAnnouncement "+
|
||||
"implementation: %T", a)
|
||||
}
|
||||
}
|
||||
|
||||
// buildEdgeInfo builds constructs an appropriate models.ChannelEdgeInfo using
|
||||
// the given lnwire.ChannelAnnouncement and some optional fields.
|
||||
func (d *AuthenticatedGossiper) buildEdgeInfo(ann lnwire.ChannelAnnouncement,
|
||||
|
@ -186,7 +186,7 @@ func (r *mockGraphSource) CurrentBlockHeight() (uint32, error) {
|
||||
}
|
||||
|
||||
func (r *mockGraphSource) AddProof(chanID lnwire.ShortChannelID,
|
||||
proof *models.ChannelAuthProof1) error {
|
||||
proof models.ChannelAuthProof) error {
|
||||
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
@ -1635,7 +1635,7 @@ func (b *Builder) ForAllOutgoingChannels(cb func(kvdb.RTx,
|
||||
//
|
||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||
func (b *Builder) AddProof(chanID lnwire.ShortChannelID,
|
||||
proof *models.ChannelAuthProof1) error {
|
||||
proof models.ChannelAuthProof) error {
|
||||
|
||||
info, _, _, err := b.cfg.Graph.FetchChannelEdgesByID(chanID.ToUint64())
|
||||
if err != nil {
|
||||
|
@ -35,7 +35,7 @@ type ChannelGraphSource interface {
|
||||
// AddProof updates the channel edge info with proof which is needed to
|
||||
// properly announce the edge to the rest of the network.
|
||||
AddProof(chanID lnwire.ShortChannelID,
|
||||
proof *models.ChannelAuthProof1) error
|
||||
proof models.ChannelAuthProof) error
|
||||
|
||||
// UpdateEdge is used to update edge information, without this message
|
||||
// edge considered as not fully constructed.
|
||||
|
Loading…
x
Reference in New Issue
Block a user