Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions autopilot/prefattach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
graphdb "github.com/lightningnetwork/lnd/graph/db"
"github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/lnwire"
Expand Down Expand Up @@ -492,15 +493,24 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
}

chanID := randChanID()
edge := &models.ChannelEdgeInfo{
ChannelID: chanID.ToUint64(),
Capacity: capacity,
Features: lnwire.EmptyFeatureVector(),
nodeKey1 := route.NewVertex(lnNode1)
nodeKey2 := route.NewVertex(lnNode2)
btcKey1 := route.NewVertex(lnNode1)
btcKey2 := route.NewVertex(lnNode2)
edge, err := models.NewV1Channel(
chanID.ToUint64(),
chainhash.Hash{},
nodeKey1,
nodeKey2,
&models.ChannelV1Fields{
BitcoinKey1Bytes: btcKey1,
BitcoinKey2Bytes: btcKey2,
},
models.WithCapacity(capacity),
)
if err != nil {
return nil, nil, err
}
copy(edge.NodeKey1Bytes[:], lnNode1.SerializeCompressed())
copy(edge.NodeKey2Bytes[:], lnNode2.SerializeCompressed())
copy(edge.BitcoinKey1Bytes[:], lnNode1.SerializeCompressed())
copy(edge.BitcoinKey2Bytes[:], lnNode2.SerializeCompressed())

if err := d.db.AddChannelEdge(ctx, edge); err != nil {
return nil, nil, err
Expand Down
6 changes: 2 additions & 4 deletions discovery/chan_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,

//nolint:ll
chanAnn, edge1, edge2, err := netann.CreateChanAnnouncement(
channel.Info.AuthProof, channel.Info,
channel.Policy1, channel.Policy2,
channel.Info, channel.Policy1, channel.Policy2,
)
if err != nil {
if !yield(nil, err) {
Expand Down Expand Up @@ -281,8 +280,7 @@ func (c *ChanSeries) FetchChanAnns(chain chainhash.Hash,
}

chanAnn, edge1, edge2, err := netann.CreateChanAnnouncement(
channel.Info.AuthProof, channel.Info, channel.Policy1,
channel.Policy2,
channel.Info, channel.Policy1, channel.Policy2,
)
if err != nil {
return nil, err
Expand Down
121 changes: 57 additions & 64 deletions discovery/gossiper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1996,10 +1996,14 @@ func (d *AuthenticatedGossiper) processRejectedEdge(_ context.Context,
return nil, nil
}

// Attach the proof to the channel info before creating the
// announcement.
chanInfo.AuthProof = proof

// We'll then create then validate the new fully assembled
// announcement.
chanAnn, e1Ann, e2Ann, err := netann.CreateChanAnnouncement(
proof, chanInfo, e1, e2,
chanInfo, e1, e2,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -2392,44 +2396,13 @@ func (d *AuthenticatedGossiper) updateChannel(ctx context.Context,
// have a full channel announcement for this channel.
var chanAnn *lnwire.ChannelAnnouncement1
if info.AuthProof != nil {
chanID := lnwire.NewShortChanIDFromInt(info.ChannelID)
chanAnn = &lnwire.ChannelAnnouncement1{
ShortChannelID: chanID,
NodeID1: info.NodeKey1Bytes,
NodeID2: info.NodeKey2Bytes,
ChainHash: info.ChainHash,
BitcoinKey1: info.BitcoinKey1Bytes,
Features: lnwire.NewRawFeatureVector(),
BitcoinKey2: info.BitcoinKey2Bytes,
ExtraOpaqueData: info.ExtraOpaqueData,
}
chanAnn.NodeSig1, err = lnwire.NewSigFromECDSARawSignature(
info.AuthProof.NodeSig1Bytes,
)
if err != nil {
return nil, nil, err
}
chanAnn.NodeSig2, err = lnwire.NewSigFromECDSARawSignature(
info.AuthProof.NodeSig2Bytes,
)
if err != nil {
return nil, nil, err
}
chanAnn.BitcoinSig1, err = lnwire.NewSigFromECDSARawSignature(
info.AuthProof.BitcoinSig1Bytes,
)
if err != nil {
return nil, nil, err
}
chanAnn.BitcoinSig2, err = lnwire.NewSigFromECDSARawSignature(
info.AuthProof.BitcoinSig2Bytes,
)
chanAnn, err = info.ToChannelAnnouncement()
if err != nil {
return nil, nil, err
}
}

return chanAnn, chanUpdate, err
return chanAnn, chanUpdate, nil
}

// SyncManager returns the gossiper's SyncManager instance.
Expand Down Expand Up @@ -2692,28 +2665,40 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
// 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.ChannelAuthProof{
NodeSig1Bytes: ann.NodeSig1.ToSignatureBytes(),
NodeSig2Bytes: ann.NodeSig2.ToSignatureBytes(),
BitcoinSig1Bytes: ann.BitcoinSig1.ToSignatureBytes(),
BitcoinSig2Bytes: ann.BitcoinSig2.ToSignatureBytes(),
}
proof = models.NewV1ChannelAuthProof(
ann.NodeSig1.ToSignatureBytes(),
ann.NodeSig2.ToSignatureBytes(),
ann.BitcoinSig1.ToSignatureBytes(),
ann.BitcoinSig2.ToSignatureBytes(),
)
}

// With the proof validated (if necessary), we can now store it within
// the database for our path finding and syncing needs.
edge := &models.ChannelEdgeInfo{
ChannelID: scid.ToUint64(),
ChainHash: ann.ChainHash,
NodeKey1Bytes: ann.NodeID1,
NodeKey2Bytes: ann.NodeID2,
BitcoinKey1Bytes: ann.BitcoinKey1,
BitcoinKey2Bytes: ann.BitcoinKey2,
AuthProof: proof,
Features: lnwire.NewFeatureVector(
ann.Features, lnwire.Features,
),
ExtraOpaqueData: ann.ExtraOpaqueData,
edge, err := models.NewV1Channel(
scid.ToUint64(),
ann.ChainHash,
ann.NodeID1,
ann.NodeID2,
&models.ChannelV1Fields{
BitcoinKey1Bytes: ann.BitcoinKey1,
BitcoinKey2Bytes: ann.BitcoinKey2,
ExtraOpaqueData: ann.ExtraOpaqueData,
},
models.WithChanProof(proof),
models.WithFeatures(ann.Features),
)
if err != nil {
key := newRejectCacheKey(
ann.GossipVersion(),
scid.ToUint64(),
sourceToPub(nMsg.source),
)
_, _ = d.recentRejects.Put(key, &cachedReject{})

log.Errorf("unable to create channel edge: %v", err)
nMsg.err <- err
return nil, false
}

// If there were any optional message fields provided, we'll include
Expand Down Expand Up @@ -3558,7 +3543,7 @@ func (d *AuthenticatedGossiper) handleAnnSig(ctx context.Context,
ann.ChannelID, peerID)

ca, _, _, err := netann.CreateChanAnnouncement(
chanInfo.AuthProof, chanInfo, e1, e2,
chanInfo, e1, e2,
)
if err != nil {
log.Errorf("unable to gen ann: %v",
Expand Down Expand Up @@ -3620,21 +3605,29 @@ func (d *AuthenticatedGossiper) handleAnnSig(ctx context.Context,
// We now have both halves of the channel announcement proof, then
// we'll reconstruct the initial announcement so we can validate it
// shortly below.
var dbProof models.ChannelAuthProof
var dbProof *models.ChannelAuthProof
if isFirstNode {
dbProof.NodeSig1Bytes = ann.NodeSignature.ToSignatureBytes()
dbProof.NodeSig2Bytes = oppProof.NodeSignature.ToSignatureBytes()
dbProof.BitcoinSig1Bytes = ann.BitcoinSignature.ToSignatureBytes()
dbProof.BitcoinSig2Bytes = oppProof.BitcoinSignature.ToSignatureBytes()
dbProof = models.NewV1ChannelAuthProof(
ann.NodeSignature.ToSignatureBytes(),
oppProof.NodeSignature.ToSignatureBytes(),
ann.BitcoinSignature.ToSignatureBytes(),
oppProof.BitcoinSignature.ToSignatureBytes(),
)
} else {
dbProof.NodeSig1Bytes = oppProof.NodeSignature.ToSignatureBytes()
dbProof.NodeSig2Bytes = ann.NodeSignature.ToSignatureBytes()
dbProof.BitcoinSig1Bytes = oppProof.BitcoinSignature.ToSignatureBytes()
dbProof.BitcoinSig2Bytes = ann.BitcoinSignature.ToSignatureBytes()
dbProof = models.NewV1ChannelAuthProof(
oppProof.NodeSignature.ToSignatureBytes(),
ann.NodeSignature.ToSignatureBytes(),
oppProof.BitcoinSignature.ToSignatureBytes(),
ann.BitcoinSignature.ToSignatureBytes(),
)
}

// Attach the proof to the channel info before creating the
// announcement.
chanInfo.AuthProof = dbProof

chanAnn, e1Ann, e2Ann, err := netann.CreateChanAnnouncement(
&dbProof, chanInfo, e1, e2,
chanInfo, e1, e2,
)
if err != nil {
log.Error(err)
Expand All @@ -3660,7 +3653,7 @@ func (d *AuthenticatedGossiper) handleAnnSig(ctx context.Context,
// attest to the bitcoin keys by validating the signatures of
// announcement. If proof is valid then we'll populate the channel edge
// with it, so we can announce it on peer connect.
err = d.cfg.Graph.AddProof(ann.ShortChannelID, &dbProof)
err = d.cfg.Graph.AddProof(ann.ShortChannelID, dbProof)
if err != nil {
err := fmt.Errorf("unable add proof to the channel chanID=%v:"+
" %v", ann.ChannelID, err)
Expand Down
16 changes: 12 additions & 4 deletions discovery/gossiper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,18 @@ func (r *mockGraphSource) GetChannelByID(chanID lnwire.ShortChannelID) (
return nil, nil, nil, graphdb.ErrEdgeNotFound
}

return &models.ChannelEdgeInfo{
NodeKey1Bytes: pubKeys[0],
NodeKey2Bytes: pubKeys[1],
}, nil, nil, graphdb.ErrZombieEdge
zombieEdge, err := models.NewV1Channel(
0,
chainhash.Hash{},
pubKeys[0],
pubKeys[1],
&models.ChannelV1Fields{},
)
if err != nil {
return nil, nil, nil, err
}

return zombieEdge, nil, nil, graphdb.ErrZombieEdge
}

edges := r.edges[chanID.ToUint64()]
Expand Down
5 changes: 3 additions & 2 deletions docs/release-notes/release-notes-0.21.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@
* Freeze the [graph SQL migration
code](https://github.com/lightningnetwork/lnd/pull/10338) to prevent the
need for maintenance as the sqlc code evolves.
* Prepare the graph DB for handling gossip [V2
nodes](https://github.com/lightningnetwork/lnd/pull/10339).
* Prepare the graph DB for handling gossip V2
nodes and channels [1](https://github.com/lightningnetwork/lnd/pull/10339)
[2](https://github.com/lightningnetwork/lnd/pull/10379).

## Code Health

Expand Down
Loading
Loading