219 Commits
Author SHA1 Message Date
Elle Mouton 0bb0d66952 graphdb: pass context to GraphSession 2026-02-25 16:11:46 +02:00
Elle Mouton 8722a96a4e graphdb: pass context to IsClosedScid 2026-02-25 16:11:46 +02:00
Elle Mouton 4dcaf1c16a graphdb: pass context to PutClosedScid 2026-02-25 16:11:46 +02:00
Elle Mouton 68c5206017 graphdb: pass context to AddEdgeProof 2026-02-25 16:11:46 +02:00
Elle Mouton 3dc2efd7f3 graphdb: pass context to DisconnectBlockAtHeight 2026-02-25 16:11:46 +02:00
Elle Mouton a31c86b0ee graphdb: pass context to PruneTip 2026-02-25 16:11:46 +02:00
Elle Mouton 9f855175d5 graphdb: pass context to ChannelView 2026-02-25 16:11:46 +02:00
Elle Mouton 7dbaa691c4 graphdb: pass context to PruneGraph 2026-02-25 16:11:46 +02:00
Elle Mouton 13668ce45f graphdb: pass context to PruneGraphNodes 2026-02-25 16:11:46 +02:00
Elle Mouton 072244ee18 graphdb: pass context to FilterKnownChanIDs 2026-02-25 16:11:46 +02:00
Elle Mouton 46d37a691f graphdb: pass context to FetchChanInfos 2026-02-25 16:11:46 +02:00
Elle Mouton f62ea62cfe graphdb: pass context to IsPublicNode 2026-02-25 16:11:42 +02:00
Elle Mouton 397330cbdb graphdb: pass context to ChannelID 2026-02-25 16:11:29 +02:00
Elle Mouton 3079c07afb graphdb: pass context to HasChannelEdge 2026-02-25 16:11:29 +02:00
Elle Mouton 87ed09a829 graphdb: pass context to HasV1ChannelEdge 2026-02-25 16:11:29 +02:00
Elle Mouton 1d4c6aadb4 graph/db: thread context through FetchChannelEdgesByOutpoint 2026-02-25 16:11:29 +02:00
Elle Mouton 6bbb9a32fc graph/db: thread context through FetchChannelEdgesByID 2026-02-25 16:11:25 +02:00
Elle Mouton acdef84d30 graph/db: thread context through DeleteChannelEdges 2026-02-25 15:33:59 +02:00
Elle Mouton 37cc6b29d9 graph/db: thread context through NumZombies 2026-02-25 15:33:34 +02:00
Elle Mouton f98905ae99 graph/db: thread context through IsZombieEdge 2026-02-25 15:33:34 +02:00
Elle Mouton 8a96e5f3d2 graph/db: thread context through MarkEdgeLive 2026-02-25 15:33:34 +02:00
Elle Mouton c270367071 graph/db: thread context through MarkEdgeZombie 2026-02-25 15:33:34 +02:00
Elle Mouton bb38aa8922 graph/db: thread context through FilterChannelRange 2026-02-25 15:33:34 +02:00
Elle Mouton e8e714f6a3 graph/db: thread context through ForEachChannelCacheable 2026-02-25 15:33:34 +02:00
Elle Mouton dc9dae8dd6 graph/db: thread context through ChanUpdatesInHorizon 2026-02-25 15:33:34 +02:00
Elle Mouton 6ccf93c2c9 graph/db: thread context through ForEachNodeDirectedChannel 2026-02-25 15:33:34 +02:00
Elle Mouton 2f0d2962dd graph/db: thread context through NodeUpdatesInHorizon 2026-02-25 15:33:34 +02:00
Elle Mouton 0597250ae4 graph/db: thread context through DisabledChannelIDs 2026-02-25 15:33:33 +02:00
Elle Mouton b1873e63ec graph/db: thread context through FetchNodeFeatures 2026-02-25 15:32:05 +02:00
Elle Mouton 7c7a0ae13d graph/db: fetch policy version in cache paginated query
The ListChannelsWithPoliciesForCachePaginated query was missing the
policy version column, causing extractChannelPolicies to hardcode
lnwire.GossipVersion1 for that row type. Add cp1.version and
cp2.version to the query and use the fetched values instead.
2026-02-20 09:28:13 +02:00
Elle Mouton acb3240d3d graph/db: version fetch chan infos
Add a gossip version parameter to FetchChanInfos in the Store interface
and both KV/SQL implementations. Update the graph builder caller and
refactor related tests.
2026-02-20 09:28:13 +02:00
Elle Mouton 769d6260f5 graph/db: version highest chan id
Add a gossip version parameter to HighestChanID in the Store interface
and both KV/SQL implementations. Update callers in the discovery
ChanSeries and server bootstrap code.
2026-02-20 09:28:13 +02:00
Elle Mouton fc19a24d07 graph/db: version disabled channel IDs
Add a gossip version parameter to DisabledChannelIDs in the Store
interface and both implementations. Add a new version-filtered SQL
query and update the builder caller.
2026-02-20 09:19:23 +02:00
Elle Mouton 672b999d22 graph/db: version edge info and policy update tests
Convert testEdgeInfoUpdates and testBatchedUpdateEdgePolicy to run
against both v1 and v2 gossip versions, exercising the versioned
Store methods added in prior commits.
2026-02-20 09:19:23 +02:00
Elle Mouton 28fe3585ac graph/db: version ChannelID lookup
Add a gossip version parameter to the ChannelID method (outpoint to
short channel ID lookup) in the Store interface and both KV/SQL
implementations. Update the VersionedGraph wrapper and tests.
2026-02-20 09:19:22 +02:00
Elle Mouton 0b1a1e3dc5 graph/db: version ForEachNodeDirectedChannel and cacheable traversal
Add a gossip version parameter to ForEachNodeDirectedChannel on the
Store interface and both DB implementations (KVStore, SQLStore). The
NodeTraverser and routing.Graph interfaces remain unversioned since
pathfinding operates on the merged cross-version cache view.

The cache population in populateCache is updated in the same commit
because it is logically atomic with the versioning changes: the graph
cache is the unversioned, merged view used by pathfinding, so it must
be populated with data from all gossip versions. Without this change,
only v1 data would be loaded into the cache, making v2 nodes and
channels invisible to pathfinding.
2026-02-20 08:50:46 +02:00
Elle Mouton f5c91691bc graph/db: version cacheable iteration methods
Add gossip version parameters to ForEachNodeCacheable and
ForEachChannelCacheable in the Store interface and both implementations.

Thread the version through SQL helpers and update call sites/tests
accordingly.
2026-02-20 08:50:43 +02:00
Elle Mouton 898e4ef854 graph/db: add gossip version aliases
Introduce gossipV1 and gossipV2 package-level aliases in sql_store.go
to reduce verbosity in version switch statements. Leave hard-coded
v1/v2 call sites untouched so remaining upgrades are obvious.

In other words, it is now easy to see where our remaining work in the
sql_store.go file is by just searching for instances of
`lnwire.GossipVersion1`.
2026-02-20 08:46:59 +02:00
Elle Mouton 3ea2423f25 graph/db: version ForEachSourceNodeChannel
Add a gossip version parameter to ForEachSourceNodeChannel in the Store
interface and both KV/SQL implementations. The VersionedGraph wrapper
delegates with its baked-in version. Convert the
testAddChannelEdgeShellNodes and testForEachSourceNodeChannel tests to
run against both v1 and v2 gossip versions.
2026-02-20 08:46:58 +02:00
Elle Mouton 2aaa52adf9 graph/db: version channelCache by gossip version
Add a channelCacheKey struct keyed by {GossipVersion, chanID}, matching
the pattern already used by rejectCache. This prevents v1 and v2
channel data from colliding in the shared cache.

All callers in KVStore (always GossipVersion1) and SQLStore (version
from context) are updated to pass the version parameter.

This will be needed for later on when we update methods that use this
cache to be versioned (like ChannelUpdatesInHorizon).
2026-02-20 08:46:57 +02:00
Elle Mouton 1e35f258e4 graph/db: add gossip version parameter to ForEachNodeChannel
Update ForEachNodeChannel to accept a gossip version parameter,
allowing callers to specify which gossip version's channels should be
iterated. This change mirrors the approach taken in ForEachChannel and
prepares the graph database for supporting multiple gossip versions
while maintaining backward compatibility.

The Store interface is updated to include the version parameter, and
both KVStore and SQLStore implementations are updated accordingly:

- KVStore validates that only GossipVersion1 is requested, returning
  ErrVersionNotSupportedForKVDB for other versions.
- SQLStore passes the version through to the underlying node query,
  enabling version-specific channel iteration.

The ChannelGraph wrapper is updated to accept and pass through the
version parameter. VersionedGraph gains a ForEachNodeChannel method
that automatically uses its configured gossip version, providing a
clean interface for version-specific operations.

Update all call sites to explicitly pass lnwire.GossipVersion1, except
for the local channel manager in server.go which now uses the v1Graph
directly (matching the pattern used in other parts of the codebase).
2026-02-13 07:21:24 +02:00
Elle Mouton 0cfb9c9d2c graph/db: add gossip version parameter to ForEachChannel
Update ForEachChannel to accept a gossip version parameter, allowing
callers to specify which gossip version's channels should be iterated.
This change prepares the graph database for supporting multiple gossip
versions while maintaining backward compatibility.

The KVStore implementation validates that only GossipVersion1 is
requested, returning ErrVersionNotSupportedForKVDB for other versions.
The SQLStore implementation validates known versions and passes the
version through to the underlying paginated query.

Update VersionedGraph to include a ForEachChannel method that
automatically uses its configured gossip version, and update the
DescribeGraph RPC handler to use the v1Graph instead of the global
graphDB.
2026-02-13 07:21:24 +02:00
Elle Mouton 506ec037e2 graph/db: add versioned HasChannelEdge method
Add a new HasChannelEdge method that takes a gossip version parameter
and returns only existence and zombie status, without timestamp data.
This supports both v1 and v2 gossip protocols.

The original HasChannelEdge method is renamed to HasV1ChannelEdge to
preserve v1-specific functionality for callers that need timestamp
information. All call sites are updated accordingly.

The SQL store implementation now handles both gossip versions, using
timestamps for v1 and block heights for v2 policies, with proper
reject cache support for both versions.
2026-02-13 07:21:24 +02:00
Elle Mouton 4a6213c35e graph/db: version reject cache for policies
Make the reject cache version-aware so v1 and v2 policy state can be
cached independently per channel ID.  Add helpers to store v1 timestamps
or v2 block heights and thread the versioned cache key through KV/SQL
store cache accesses.
2026-02-13 07:21:24 +02:00
Elle Mouton 40e3ac964f graph/db: update policy builders to support v2 fields
Update buildChanPolicy and related functions in both KV and SQL stores
to properly construct ChannelEdgePolicy with version-specific fields:

KVStore changes:
- Reject non-v1 policies in updateEdgePolicy and serializeChanEdgePolicy
  since KV store only supports v1 gossip protocol.
- Set Version to GossipVersion1 when deserializing policies from KV.

SQLStore changes:
- Add isNode1 parameter to buildChanPolicy functions to properly set
  SecondPeer field (v2 uses SecondPeer instead of ChannelFlags direction).
- Extract Version from database and populate version-specific fields:
  - For v1: MessageFlags, ChannelFlags, LastUpdate, ExtraOpaqueData
  - For v2: DisableFlags, LastBlockHeight, ExtraSignedFields
- Thread isNode1 through buildChanPolicyWithBatchData and
  buildCachedChanPolicies call sites.

This enables the SQL store to read and reconstruct both v1 and v2
channel policies from the database with proper field mapping.
2026-02-13 07:21:24 +02:00
Elle Mouton bd215b1a7d graph/db: set policy version for cache load
Ensure policies loaded for graph cache reconstruction are tagged as v1.
2026-02-13 07:21:24 +02:00
Elle Mouton 0aa93c93e7 graph/db: add v2 policy fields to database layer
Extend channel policy queries and structs to support v2-specific fields:

- Add BlockHeight field to track the block height for v2 policy updates.
- Add DisableFlags field for v2 channel disable messages.

Both fields are nullable (sql.NullInt64/Int16) to maintain backwards
compatibility with v1 channels. The fields are initialized as null in
updateChanEdgePolicy and threaded through all policy-related queries
(GetChannelBySCIDWithPolicies, ListChannelsByNodeID, UpsertEdgePolicy,
etc.) and the extractChannelPolicies helper.

This commit includes both the hand-written SQL query updates and the
corresponding sqlc-generated Go code.
2026-02-13 07:21:23 +02:00
Elle Mouton 03050a589d graph/db: add version parameter to IsZombieEdge
Make IsZombieEdge version-aware and add corresponding method to
VersionedGraph. Convert TestEdgeInsertionDeletion to versioned test
using the createEdge helper for both v1 and v2 channel testing.
2026-02-13 07:21:23 +02:00
Elle Mouton d88fa01162 graph/db: add version parameter to FetchChannelEdgesByID/Outpoint
Make channel edge fetching version-aware by adding gossip version
parameter to FetchChannelEdgesByID and FetchChannelEdgesByOutpoint.
Add corresponding methods to VersionedGraph. V2 policy building is
marked as TODO.
2026-02-13 07:21:23 +02:00
Elle Mouton 971c0f6eb8 graph/db: add version parameter to IsPublicNode
Make IsPublicNode version-aware by routing to the appropriate SQL
query based on gossip version. V1 and v2 have different criteria for
determining node publicity (v1 requires four signatures, v2 requires
one). Convert TestNodeIsPublic to versioned test for both protocols.
2026-02-13 07:21:23 +02:00