Skip to content

Commit f90328f

Browse files
committed
graph/db: add sql support for versioned node traversal
Add SQL queries for version-aware node traversal used by the sqlNodeTraverser: ListChannelsForNodeV2, GetV2NodesByPubKeys, ListChannelsWithPoliciesForCachePaginatedV2, and ListChannelsPaginatedV2. Update the KV store's ForEachNodeDirectedChannel to return ErrVersionNotSupportedForKVDB for non-v1 instead of silently returning no results.
1 parent 97134ce commit f90328f

6 files changed

Lines changed: 538 additions & 10 deletions

File tree

graph/db/graph_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,13 +3000,11 @@ func TestFilterKnownChanIDsZombieRevival(t *testing.T) {
30003000

30013001
// Mark channel 1 and 2 as zombies.
30023002
err := graph.MarkEdgeZombie(
3003-
ctx, lnwire.GossipVersion1, scid1.ToUint64(),
3004-
[33]byte{}, [33]byte{},
3003+
ctx, scid1.ToUint64(), [33]byte{}, [33]byte{},
30053004
)
30063005
require.NoError(t, err)
30073006
err = graph.MarkEdgeZombie(
3008-
ctx, lnwire.GossipVersion1, scid2.ToUint64(),
3009-
[33]byte{}, [33]byte{},
3007+
ctx, scid2.ToUint64(), [33]byte{}, [33]byte{},
30103008
)
30113009
require.NoError(t, err)
30123010

graph/db/kv_store.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4174,8 +4174,9 @@ func (c *KVStore) FetchChannelEdgesByID(_ context.Context,
41744174
return edgeInfo, policy1, policy2, nil
41754175
}
41764176

4177-
// FetchChannelEdgesByIDPreferHighest looks up the channel by ID. The KV store
4178-
// only supports gossip v1, so this simply delegates to the versioned fetch.
4177+
// FetchChannelEdgesByIDPreferHighest looks up the channel by SCID. The KV
4178+
// store only supports gossip v1, so this simply delegates to the versioned
4179+
// fetch.
41794180
//
41804181
// NOTE: part of the Store interface.
41814182
func (c *KVStore) FetchChannelEdgesByIDPreferHighest(ctx context.Context,

graph/db/sql_store.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3871,9 +3871,27 @@ func (s *sqlNodeTraverser) ForEachNodeDirectedChannel(
38713871
ctx context.Context, nodePub route.Vertex,
38723872
cb func(channel *DirectedChannel) error, _ func()) error {
38733873

3874-
return forEachNodeDirectedChannel(
3875-
ctx, s.db, lnwire.GossipVersion1, nodePub, cb,
3876-
)
3874+
// Iterate across all gossip versions (highest first) so that
3875+
// channels announced via v2 are preferred over v1.
3876+
seen := make(map[uint64]struct{})
3877+
for _, v := range []lnwire.GossipVersion{gossipV2, gossipV1} {
3878+
err := forEachNodeDirectedChannel(
3879+
ctx, s.db, v, nodePub,
3880+
func(channel *DirectedChannel) error {
3881+
if _, ok := seen[channel.ChannelID]; ok {
3882+
return nil
3883+
}
3884+
seen[channel.ChannelID] = struct{}{}
3885+
3886+
return cb(channel)
3887+
},
3888+
)
3889+
if err != nil {
3890+
return err
3891+
}
3892+
}
3893+
3894+
return nil
38773895
}
38783896

38793897
// FetchNodeFeatures returns the features of the given node. If the node is

0 commit comments

Comments
 (0)