Skip to content

Commit 1d85426

Browse files
authored
Merge pull request #10379 from ellemouton/g175Prep4
[g175:3] graph/db: continue prepping `models` for V2 data
2 parents a5f3006 + 0f61298 commit 1d85426

26 files changed

+1291
-771
lines changed

autopilot/prefattach_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/btcsuite/btcd/btcec/v2"
1414
"github.com/btcsuite/btcd/btcutil"
15+
"github.com/btcsuite/btcd/chaincfg/chainhash"
1516
graphdb "github.com/lightningnetwork/lnd/graph/db"
1617
"github.com/lightningnetwork/lnd/graph/db/models"
1718
"github.com/lightningnetwork/lnd/lnwire"
@@ -492,15 +493,20 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
492493
}
493494

494495
chanID := randChanID()
495-
edge := &models.ChannelEdgeInfo{
496-
ChannelID: chanID.ToUint64(),
497-
Capacity: capacity,
498-
Features: lnwire.EmptyFeatureVector(),
496+
nodeKey1 := route.NewVertex(lnNode1)
497+
nodeKey2 := route.NewVertex(lnNode2)
498+
btcKey1 := route.NewVertex(lnNode1)
499+
btcKey2 := route.NewVertex(lnNode2)
500+
edge, err := models.NewV1Channel(
501+
chanID.ToUint64(), chainhash.Hash{}, nodeKey1, nodeKey2,
502+
&models.ChannelV1Fields{
503+
BitcoinKey1Bytes: btcKey1,
504+
BitcoinKey2Bytes: btcKey2,
505+
}, models.WithCapacity(capacity),
506+
)
507+
if err != nil {
508+
return nil, nil, err
499509
}
500-
copy(edge.NodeKey1Bytes[:], lnNode1.SerializeCompressed())
501-
copy(edge.NodeKey2Bytes[:], lnNode2.SerializeCompressed())
502-
copy(edge.BitcoinKey1Bytes[:], lnNode1.SerializeCompressed())
503-
copy(edge.BitcoinKey2Bytes[:], lnNode2.SerializeCompressed())
504510

505511
if err := d.db.AddChannelEdge(ctx, edge); err != nil {
506512
return nil, nil, err

discovery/chan_series.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
133133

134134
//nolint:ll
135135
chanAnn, edge1, edge2, err := netann.CreateChanAnnouncement(
136-
channel.Info.AuthProof, channel.Info,
137-
channel.Policy1, channel.Policy2,
136+
channel.Info, channel.Policy1, channel.Policy2,
138137
)
139138
if err != nil {
140139
if !yield(nil, err) {
@@ -281,8 +280,7 @@ func (c *ChanSeries) FetchChanAnns(chain chainhash.Hash,
281280
}
282281

283282
chanAnn, edge1, edge2, err := netann.CreateChanAnnouncement(
284-
channel.Info.AuthProof, channel.Info, channel.Policy1,
285-
channel.Policy2,
283+
channel.Info, channel.Policy1, channel.Policy2,
286284
)
287285
if err != nil {
288286
return nil, err

discovery/gossiper.go

Lines changed: 53 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,10 +1996,14 @@ func (d *AuthenticatedGossiper) processRejectedEdge(_ context.Context,
19961996
return nil, nil
19971997
}
19981998

1999+
// Attach the proof to the channel info before creating the
2000+
// announcement.
2001+
chanInfo.AuthProof = proof
2002+
19992003
// We'll then create then validate the new fully assembled
20002004
// announcement.
20012005
chanAnn, e1Ann, e2Ann, err := netann.CreateChanAnnouncement(
2002-
proof, chanInfo, e1, e2,
2006+
chanInfo, e1, e2,
20032007
)
20042008
if err != nil {
20052009
return nil, err
@@ -2392,44 +2396,13 @@ func (d *AuthenticatedGossiper) updateChannel(ctx context.Context,
23922396
// have a full channel announcement for this channel.
23932397
var chanAnn *lnwire.ChannelAnnouncement1
23942398
if info.AuthProof != nil {
2395-
chanID := lnwire.NewShortChanIDFromInt(info.ChannelID)
2396-
chanAnn = &lnwire.ChannelAnnouncement1{
2397-
ShortChannelID: chanID,
2398-
NodeID1: info.NodeKey1Bytes,
2399-
NodeID2: info.NodeKey2Bytes,
2400-
ChainHash: info.ChainHash,
2401-
BitcoinKey1: info.BitcoinKey1Bytes,
2402-
Features: lnwire.NewRawFeatureVector(),
2403-
BitcoinKey2: info.BitcoinKey2Bytes,
2404-
ExtraOpaqueData: info.ExtraOpaqueData,
2405-
}
2406-
chanAnn.NodeSig1, err = lnwire.NewSigFromECDSARawSignature(
2407-
info.AuthProof.NodeSig1Bytes,
2408-
)
2409-
if err != nil {
2410-
return nil, nil, err
2411-
}
2412-
chanAnn.NodeSig2, err = lnwire.NewSigFromECDSARawSignature(
2413-
info.AuthProof.NodeSig2Bytes,
2414-
)
2415-
if err != nil {
2416-
return nil, nil, err
2417-
}
2418-
chanAnn.BitcoinSig1, err = lnwire.NewSigFromECDSARawSignature(
2419-
info.AuthProof.BitcoinSig1Bytes,
2420-
)
2421-
if err != nil {
2422-
return nil, nil, err
2423-
}
2424-
chanAnn.BitcoinSig2, err = lnwire.NewSigFromECDSARawSignature(
2425-
info.AuthProof.BitcoinSig2Bytes,
2426-
)
2399+
chanAnn, err = info.ToChannelAnnouncement()
24272400
if err != nil {
24282401
return nil, nil, err
24292402
}
24302403
}
24312404

2432-
return chanAnn, chanUpdate, err
2405+
return chanAnn, chanUpdate, nil
24332406
}
24342407

24352408
// SyncManager returns the gossiper's SyncManager instance.
@@ -2692,28 +2665,36 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
26922665
// If the proof checks out, then we'll save the proof itself to
26932666
// the database so we can fetch it later when gossiping with
26942667
// other nodes.
2695-
proof = &models.ChannelAuthProof{
2696-
NodeSig1Bytes: ann.NodeSig1.ToSignatureBytes(),
2697-
NodeSig2Bytes: ann.NodeSig2.ToSignatureBytes(),
2698-
BitcoinSig1Bytes: ann.BitcoinSig1.ToSignatureBytes(),
2699-
BitcoinSig2Bytes: ann.BitcoinSig2.ToSignatureBytes(),
2700-
}
2668+
proof = models.NewV1ChannelAuthProof(
2669+
ann.NodeSig1.ToSignatureBytes(),
2670+
ann.NodeSig2.ToSignatureBytes(),
2671+
ann.BitcoinSig1.ToSignatureBytes(),
2672+
ann.BitcoinSig2.ToSignatureBytes(),
2673+
)
27012674
}
27022675

27032676
// With the proof validated (if necessary), we can now store it within
27042677
// the database for our path finding and syncing needs.
2705-
edge := &models.ChannelEdgeInfo{
2706-
ChannelID: scid.ToUint64(),
2707-
ChainHash: ann.ChainHash,
2708-
NodeKey1Bytes: ann.NodeID1,
2709-
NodeKey2Bytes: ann.NodeID2,
2710-
BitcoinKey1Bytes: ann.BitcoinKey1,
2711-
BitcoinKey2Bytes: ann.BitcoinKey2,
2712-
AuthProof: proof,
2713-
Features: lnwire.NewFeatureVector(
2714-
ann.Features, lnwire.Features,
2715-
),
2716-
ExtraOpaqueData: ann.ExtraOpaqueData,
2678+
edge, err := models.NewV1Channel(
2679+
scid.ToUint64(), ann.ChainHash, ann.NodeID1, ann.NodeID2,
2680+
&models.ChannelV1Fields{
2681+
BitcoinKey1Bytes: ann.BitcoinKey1,
2682+
BitcoinKey2Bytes: ann.BitcoinKey2,
2683+
ExtraOpaqueData: ann.ExtraOpaqueData,
2684+
},
2685+
models.WithChanProof(proof), models.WithFeatures(ann.Features),
2686+
)
2687+
if err != nil {
2688+
key := newRejectCacheKey(
2689+
ann.GossipVersion(),
2690+
scid.ToUint64(),
2691+
sourceToPub(nMsg.source),
2692+
)
2693+
_, _ = d.recentRejects.Put(key, &cachedReject{})
2694+
2695+
log.Errorf("unable to create channel edge: %v", err)
2696+
nMsg.err <- err
2697+
return nil, false
27172698
}
27182699

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

35603541
ca, _, _, err := netann.CreateChanAnnouncement(
3561-
chanInfo.AuthProof, chanInfo, e1, e2,
3542+
chanInfo, e1, e2,
35623543
)
35633544
if err != nil {
35643545
log.Errorf("unable to gen ann: %v",
@@ -3620,21 +3601,29 @@ func (d *AuthenticatedGossiper) handleAnnSig(ctx context.Context,
36203601
// We now have both halves of the channel announcement proof, then
36213602
// we'll reconstruct the initial announcement so we can validate it
36223603
// shortly below.
3623-
var dbProof models.ChannelAuthProof
3604+
var dbProof *models.ChannelAuthProof
36243605
if isFirstNode {
3625-
dbProof.NodeSig1Bytes = ann.NodeSignature.ToSignatureBytes()
3626-
dbProof.NodeSig2Bytes = oppProof.NodeSignature.ToSignatureBytes()
3627-
dbProof.BitcoinSig1Bytes = ann.BitcoinSignature.ToSignatureBytes()
3628-
dbProof.BitcoinSig2Bytes = oppProof.BitcoinSignature.ToSignatureBytes()
3606+
dbProof = models.NewV1ChannelAuthProof(
3607+
ann.NodeSignature.ToSignatureBytes(),
3608+
oppProof.NodeSignature.ToSignatureBytes(),
3609+
ann.BitcoinSignature.ToSignatureBytes(),
3610+
oppProof.BitcoinSignature.ToSignatureBytes(),
3611+
)
36293612
} else {
3630-
dbProof.NodeSig1Bytes = oppProof.NodeSignature.ToSignatureBytes()
3631-
dbProof.NodeSig2Bytes = ann.NodeSignature.ToSignatureBytes()
3632-
dbProof.BitcoinSig1Bytes = oppProof.BitcoinSignature.ToSignatureBytes()
3633-
dbProof.BitcoinSig2Bytes = ann.BitcoinSignature.ToSignatureBytes()
3613+
dbProof = models.NewV1ChannelAuthProof(
3614+
oppProof.NodeSignature.ToSignatureBytes(),
3615+
ann.NodeSignature.ToSignatureBytes(),
3616+
oppProof.BitcoinSignature.ToSignatureBytes(),
3617+
ann.BitcoinSignature.ToSignatureBytes(),
3618+
)
36343619
}
36353620

3621+
// Attach the proof to the channel info before creating the
3622+
// announcement.
3623+
chanInfo.AuthProof = dbProof
3624+
36363625
chanAnn, e1Ann, e2Ann, err := netann.CreateChanAnnouncement(
3637-
&dbProof, chanInfo, e1, e2,
3626+
chanInfo, e1, e2,
36383627
)
36393628
if err != nil {
36403629
log.Error(err)
@@ -3660,7 +3649,7 @@ func (d *AuthenticatedGossiper) handleAnnSig(ctx context.Context,
36603649
// attest to the bitcoin keys by validating the signatures of
36613650
// announcement. If proof is valid then we'll populate the channel edge
36623651
// with it, so we can announce it on peer connect.
3663-
err = d.cfg.Graph.AddProof(ann.ShortChannelID, &dbProof)
3652+
err = d.cfg.Graph.AddProof(ann.ShortChannelID, dbProof)
36643653
if err != nil {
36653654
err := fmt.Errorf("unable add proof to the channel chanID=%v:"+
36663655
" %v", ann.ChannelID, err)

discovery/gossiper_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,15 @@ func (r *mockGraphSource) GetChannelByID(chanID lnwire.ShortChannelID) (
272272
return nil, nil, nil, graphdb.ErrEdgeNotFound
273273
}
274274

275-
return &models.ChannelEdgeInfo{
276-
NodeKey1Bytes: pubKeys[0],
277-
NodeKey2Bytes: pubKeys[1],
278-
}, nil, nil, graphdb.ErrZombieEdge
275+
zombieEdge, err := models.NewV1Channel(
276+
0, chainhash.Hash{}, pubKeys[0], pubKeys[1],
277+
&models.ChannelV1Fields{},
278+
)
279+
if err != nil {
280+
return nil, nil, nil, err
281+
}
282+
283+
return zombieEdge, nil, nil, graphdb.ErrZombieEdge
279284
}
280285

281286
edges := r.edges[chanID.ToUint64()]

docs/release-notes/release-notes-0.21.0.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@
6868
* Freeze the [graph SQL migration
6969
code](https://github.com/lightningnetwork/lnd/pull/10338) to prevent the
7070
need for maintenance as the sqlc code evolves.
71-
* Prepare the graph DB for handling gossip [V2
72-
nodes](https://github.com/lightningnetwork/lnd/pull/10339).
71+
* Prepare the graph DB for handling gossip V2
72+
nodes and channels [1](https://github.com/lightningnetwork/lnd/pull/10339)
73+
[2](https://github.com/lightningnetwork/lnd/pull/10379).
7374

7475
## Code Health
7576

0 commit comments

Comments
 (0)