86 Commits
Author SHA1 Message Date
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 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 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 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 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 dc9dae8dd6 graph/db: thread context through ChanUpdatesInHorizon 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 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 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 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 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 a73c45946b multi: add ChanEdgePolicyFromWire constructor for ChannelEdgePolicy
Add ChanEdgePolicyFromWire to construct ChannelEdgePolicy from channel
update messages, centralizing v1/v2 field mapping.
Update call sites to use the helper:

- discovery/gossiper: handleChanUpdate
- graph/builder: ApplyChannelUpdate
- routing/router_test: ApplyChannelUpdate test helper

This consolidates update-to-policy conversion logic across versions.
2026-02-13 07:21:24 +02:00
Elle Mouton 3fe40c6540 graph/db: add v2 fields to ChannelEdgePolicy model
Extend ChannelEdgePolicy to support v2 channel updates by adding:

- Version field to track gossip protocol version (v1 or v2).
- LastBlockHeight for v2's block-height-based timestamps.
- SecondPeer flag to indicate which peer announced the policy in v2.
- DisableFlags for v2-specific channel disable signaling.
- ExtraSignedFields map for v2 extra signed TLV data.

Add version-aware methods:
- IsNode1() determines if the policy was announced by node_1, handling
  both v1 (via ChannelFlags direction bit) and v2 (via SecondPeer).
- IsDisabled() checks disable status using ChannelFlags for v1 and
  DisableFlags for v2.
- String() provides version-appropriate string representations.

The new fields use zero values for v1 compatibility (Version defaults
to GossipVersion1, LastBlockHeight to 0, SecondPeer to false). This
lays the groundwork for v2 policy support; a subsequent commit will
handle reading and writing these fields from/to the database.
2026-02-13 07:21:24 +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
Elle Mouton b3cf9a806f multi: add DeleteChannelEdges to VersionedGraph
Add version-aware DeleteChannelEdges method to VersionedGraph and
update call sites in graph builder, rpcserver, and server to use
versioned graphs. This ensures channel deletion operations are
properly scoped to the correct gossip version.
2026-02-13 07:21:23 +02:00
Elle Mouton 4db5198079 graph/db: introduce VersionedGraph
For now, all instances will use V1 only so as not to change behaviour
yet.
2026-02-13 07:21:21 +02:00
Elle Mouton 97143a74ab graph/db: split HasNode into two methods
HasNode currently is very v1 specific since it returns a time.Time
timestamp which is specific to V1 node announcements. However, it is
mostly only used for the "exists" return value. So here we split it up
into HasNode which just checks existence and HasV1Node which retains the
same behavaiour as before.
2026-02-13 07:21:20 +02:00
Elle Mouton 855e579c3f graph: remove DB interface 2025-11-12 22:54:05 +08:00
Elle Mouton 14cf937419 graph: fix log formatting 2025-10-06 10:59:39 +02:00
Olaoluwa Osuntokun f3a8fd842d graph+discovery: update graph/db gossip backlog interfaces to use iter.Seq2
This lets us emit a rich error if things fail when first creating the
iterator, or if any of the yield attempts fail.
2025-09-26 17:01:11 -07:00
Olaoluwa Osuntokun 069888b51a graph/db: convert ChanUpdatesInHorizon to use iterators
In this commit, we refactor the ChanUpdatesInHorizon method to return
an iterator instead of a slice. This change significantly reduces
memory usage when dealing with large result sets by allowing callers to
process items incrementally rather than loading everything into memory
at once.
2025-09-26 16:57:11 -07:00
Elle Mouton 330f697937 graph: rename HasLightningNode
to HasNode
2025-09-03 10:14:35 +02:00
Elle Mouton cd3bd05810 multi: rename FetchLightningNode
to FetchNode
2025-09-03 10:14:35 +02:00
Elle Mouton 060219780b multi: rename AddLightningNode methods
to AddNode
2025-09-03 10:14:35 +02:00
Elle Mouton c663a557c4 multi: rename models.LightningNode to models.Node 2025-09-03 10:14:35 +02:00
Elle Mouton 75691163a9 graph: remove outdated TODO
This todo has been addressed.
2025-08-13 08:45:52 +02:00
Elle Mouton e5fbca8299 multi: let ForEachNodeChannel take a reset param 2025-07-15 11:23:27 +02:00
Elle Mouton 793c1057bb graph: remove one context.TODO
By threading a context through to the Builder's ForAllOutgoingChannels
method.
2025-07-08 15:11:02 +02:00
Elle Mouton f8d3a3f3ba graph/db: let ForEachNodeChannel take a context 2025-07-08 15:10:30 +02:00
Elle Mouton 8cf567b948 multi: use the "errors" package everywhere
Replace all usages of the "github.com/go-errors/errors" and
"github.com/pkg/errors" packages with the standard lib's "errors"
package. This ensures that error wrapping and `errors.Is` checks will
work as expected.
2025-06-30 09:46:55 +02:00
Elle Mouton 81c063eb96 graph/db: thread context through to UpdateEdgePolicy 2025-06-19 14:49:31 +02:00
Elle Mouton 3fdb9b84f4 graph/db: thread context to AddChannelEdge 2025-06-19 14:47:41 +02:00
Elle Mouton dc6259fcc3 graph/db: thread context through to HasLightningNode 2025-06-17 19:20:56 +02:00
Elle Mouton 66c5a97202 graph/db: thread context through to FetchLightingNode 2025-06-17 19:20:27 +02:00
Elle Mouton d1cfb47428 graph/db: thread context to AddLightningNode 2025-06-17 19:20:27 +02:00
Elle Mouton 6d8bc63ad6 discovery+graph: get inbound fee directly from ChannelUpdate
Remove the previously added TODOs which would extract InboundFee info
from the ExtraOpaqueData of a ChannelUpdate at the time of
ChannelEdgePolicy construction. These can now be replaced by using the
newly added InboundFee record on the ChannelUpdate message.
2025-06-09 08:44:47 +02:00
Elle Mouton 9890d74622 multi: set the InboundFee on ChannelEdgePolicy
In this commit, we make sure to set the new field wherever appropriate.
This will be any place where the ChannelEdgePolicy is constructed other
than its disk deserialisation.
2025-06-09 08:31:10 +02:00
Elle Mouton da3deeee7c multi: remove kvdb.RTx from ForEachNodeChannel
Since we have not removed all call-sites that make use of this
parameter, we can remove it. This helps hide DB-specific details from
the interface we will introduce for the graph store.
2025-05-22 14:14:39 +02:00
Elle Mouton 2221aaa889 graph/db: move Topology client management to ChannelGraph
We plan to later on add an option for a remote graph source which will
be managed from the ChannelGraph. In such a set-up, a node would rely on
the remote graph source for graph updates instead of from gossip sync.
In this scenario, however, our topology subscription logic should still
notify clients of all updates and so it makes more sense to have the
logic as part of the ChannelGraph so that we can send updates we receive
from the remote graph.
2025-03-24 15:05:48 +02:00
Elle Mouton c89b616e7d graph: refactor Builder network message handling
The exposed AddNode, AddEdge and UpdateEdge methods of the Builder are
currently synchronous since even though they pass messages to the
network handler which spins off the handling in a goroutine, the public
methods still wait for a response from the handling before returning.
The only part that is actually done asynchronously is the topology
notifications.

We previously tried to simplify things in [this
commit](https://github.com/lightningnetwork/lnd/pull/9476/commits/d757b3bcfc77b0fbb543ef5db800e6c6b058930f)
but we soon realised that there was a reason for sending the messages to
the central/synchronous network handler first: it was to ensure
consistency for topology clients: ie, the ordering between when there is
a new topology client or if it is cancelled needs to be consistent and
handled synchronously with new network updates. So for example, if a new
update comes in right after a topology client cancels its subscription,
then it should _not_ be notified. Similariy for new subscriptions. So
this commit was reverted soon after.

We can, however, still simplify things as is done in this commit by
noting that _only topology subscriptions and notifications_ need to be
handled separately. The actual network updates do not need to. So that
is what is done here.

This refactor will make moving the topology subscription logic to a new
subsystem later on much easier.
2025-02-21 10:39:00 -03:00
Elle Mouton 9df8773163 graph: update proof by ID
This commit restricts the graph CRUD interface such that one can only
add a proof to a channel announcement and not update any other fields.
This pattern is better suited for SQL land too.
2025-02-18 11:05:28 -03:00