Skip to content

Commit 2466b2c

Browse files
committed
multi: add and use V1 constructor for models.ChannelEdgeInfo
This makes it clear what fields must/can be set for a V1 channel.
1 parent 4adbe56 commit 2466b2c

18 files changed

+968
-560
lines changed

autopilot/prefattach_test.go

Lines changed: 18 additions & 9 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,16 +493,24 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
492493
}
493494

494495
chanID := randChanID()
495-
edge := &models.ChannelEdgeInfo{
496-
Version: lnwire.GossipVersion1,
497-
ChannelID: chanID.ToUint64(),
498-
Capacity: capacity,
499-
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(),
502+
chainhash.Hash{},
503+
nodeKey1,
504+
nodeKey2,
505+
&models.ChannelV1Fields{
506+
BitcoinKey1Bytes: btcKey1,
507+
BitcoinKey2Bytes: btcKey2,
508+
},
509+
models.WithCapacity(capacity),
510+
)
511+
if err != nil {
512+
return nil, nil, err
500513
}
501-
copy(edge.NodeKey1Bytes[:], lnNode1.SerializeCompressed())
502-
copy(edge.NodeKey2Bytes[:], lnNode2.SerializeCompressed())
503-
copy(edge.BitcoinKey1Bytes[:], lnNode1.SerializeCompressed())
504-
copy(edge.BitcoinKey2Bytes[:], lnNode2.SerializeCompressed())
505514

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

discovery/gossiper.go

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,19 +2702,30 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
27022702

27032703
// With the proof validated (if necessary), we can now store it within
27042704
// the database for our path finding and syncing needs.
2705-
edge := &models.ChannelEdgeInfo{
2706-
Version: lnwire.GossipVersion1,
2707-
ChannelID: scid.ToUint64(),
2708-
ChainHash: ann.ChainHash,
2709-
NodeKey1Bytes: ann.NodeID1,
2710-
NodeKey2Bytes: ann.NodeID2,
2711-
BitcoinKey1Bytes: ann.BitcoinKey1,
2712-
BitcoinKey2Bytes: ann.BitcoinKey2,
2713-
AuthProof: proof,
2714-
Features: lnwire.NewFeatureVector(
2715-
ann.Features, lnwire.Features,
2716-
),
2717-
ExtraOpaqueData: ann.ExtraOpaqueData,
2705+
edge, err := models.NewV1Channel(
2706+
scid.ToUint64(),
2707+
ann.ChainHash,
2708+
ann.NodeID1,
2709+
ann.NodeID2,
2710+
&models.ChannelV1Fields{
2711+
BitcoinKey1Bytes: ann.BitcoinKey1,
2712+
BitcoinKey2Bytes: ann.BitcoinKey2,
2713+
ExtraOpaqueData: ann.ExtraOpaqueData,
2714+
},
2715+
models.WithChanProof(proof),
2716+
models.WithFeatures(ann.Features),
2717+
)
2718+
if err != nil {
2719+
key := newRejectCacheKey(
2720+
ann.GossipVersion(),
2721+
scid.ToUint64(),
2722+
sourceToPub(nMsg.source),
2723+
)
2724+
_, _ = d.recentRejects.Put(key, &cachedReject{})
2725+
2726+
log.Errorf("unable to create channel edge: %v", err)
2727+
nMsg.err <- err
2728+
return nil, false
27182729
}
27192730

27202731
// If there were any optional message fields provided, we'll include

discovery/gossiper_test.go

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

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

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

0 commit comments

Comments
 (0)