Skip to content

Commit 6f02dfc

Browse files
committed
graph/db/models: keep v2 onion addresses v3-only
Filter out non-v3 onion addresses when setting v2 node addresses, since v2 gossip only supports v3 onion addresses. Also update the SQL store to handle v2 node address filtering during persistence and retrieval.
1 parent f90328f commit 6f02dfc

4 files changed

Lines changed: 30 additions & 5 deletions

File tree

graph/db/graph.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,14 @@ func (c *ChannelGraph) HasV1Node(ctx context.Context,
641641
return c.db.HasV1Node(ctx, nodePub)
642642
}
643643

644+
// ForEachNode iterates through all nodes in the graph across all gossip
645+
// versions, yielding each unique node exactly once.
646+
func (c *ChannelGraph) ForEachNode(ctx context.Context,
647+
cb func(*models.Node) error, reset func()) error {
648+
649+
return c.db.ForEachNode(ctx, cb, reset)
650+
}
651+
644652
// ForEachChannel iterates through all channel edges stored within the graph
645653
// across all gossip versions.
646654
func (c *ChannelGraph) ForEachChannel(ctx context.Context,
@@ -907,7 +915,7 @@ func (c *VersionedGraph) FilterKnownChanIDs(ctx context.Context,
907915
// alive, and we let it be added to the set of IDs to query
908916
// our peer for.
909917
err := c.db.MarkEdgeLive(
910-
ctx, info.Version,
918+
ctx, c.v,
911919
info.ShortChannelID.ToUint64(),
912920
)
913921
// Since there is a chance that the edge could have been

graph/db/models/node.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ func (n *Node) toNodeAnnouncement2(signed bool) (*lnwire.NodeAnnouncement2,
308308
}
309309

310310
case *tor.OnionAddr:
311-
torV3 = append(torV3, a)
311+
// Only v3 onion addresses are supported in gossip v2.
312+
if len(a.OnionService) == tor.V3Len {
313+
torV3 = append(torV3, a)
314+
}
312315

313316
case *lnwire.DNSAddress:
314317
nodeAnn.DNSHostName = tlv.SomeRecordT(

graph/db/models/node_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func TestNodeAnnouncementV2AddressCategorization(t *testing.T) {
174174
ipv4Addr := &net.TCPAddr{IP: net.ParseIP("1.2.3.4").To4(), Port: 9735}
175175
ipv6Addr := &net.TCPAddr{IP: net.ParseIP("::1"), Port: 9736}
176176
torAddr := &tor.OnionAddr{
177-
OnionService: "abcdefghijklmnopqrstuvwxyz234567aaaa",
177+
OnionService: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.onion",
178178
Port: 9737,
179179
}
180180
dnsAddr := &lnwire.DNSAddress{Hostname: "example.com", Port: 9738}

graph/db/sql_store.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ func (s *SQLStore) ForEachNodeCached(ctx context.Context,
16221622
// page.
16231623
allChannels, err := db.ListChannelsForNodeIDs(
16241624
ctx, sqlc.ListChannelsForNodeIDsParams{
1625-
Version: int16(lnwire.GossipVersion1),
1625+
Version: int16(v),
16261626
Node1Ids: nodeIDs,
16271627
Node2Ids: nodeIDs,
16281628
},
@@ -3902,7 +3902,21 @@ func (s *sqlNodeTraverser) FetchNodeFeatures(ctx context.Context,
39023902
nodePub route.Vertex) (
39033903
*lnwire.FeatureVector, error) {
39043904

3905-
return fetchNodeFeatures(ctx, s.db, lnwire.GossipVersion1, nodePub)
3905+
// Try v2 first, fall back to v1 if the v2 features are empty.
3906+
for _, v := range []lnwire.GossipVersion{gossipV2, gossipV1} {
3907+
features, err := fetchNodeFeatures(
3908+
ctx, s.db, v, nodePub,
3909+
)
3910+
if err != nil {
3911+
return nil, err
3912+
}
3913+
3914+
if !features.IsEmpty() {
3915+
return features, nil
3916+
}
3917+
}
3918+
3919+
return lnwire.EmptyFeatureVector(), nil
39063920
}
39073921

39083922
// forEachNodeDirectedChannel iterates through all channels of a given

0 commit comments

Comments
 (0)