Commit Graph

122 Commits

Author SHA1 Message Date
Elle Mouton
8de33fa601 graph/db: batch fetching for FetchChanInfos 2025-08-07 08:12:40 +02:00
Elle Mouton
594c842aeb graph/db: batch loading for DisconnectBlockAtHeight 2025-08-07 08:12:40 +02:00
Elle Mouton
69bcf47dca graph/db: use batch loading for PruneGraph 2025-08-07 08:12:40 +02:00
Elle Mouton
556af8e221 graph/db: use batch fetching for DeleteChannelEdges 2025-08-07 08:12:40 +02:00
Elle Mouton
ebe6a8af9f graph/db: use batch loading for ChanUpdatesInHorizon
The following performance gains were measured using the new benchmark
test.

```
name                                      old time/op  new time/op  delta
ChanUpdatesInHorizon-native-sqlite-10     18.5s ± 3%    2.0s ± 5%  -89.11%  (p=0.000 n=9+9)
ChanUpdatesInHorizon-native-postgres-10   59.0s ± 3%    0.8s ±10%  -98.65%  (p=0.000 n=10+9)
```
2025-08-07 08:12:40 +02:00
Elle Mouton
ce3401ee5d graph/db: refactor buildNode to not take a pointer
Since the type returned from the DB is not a pointer. This will be
useful later on.
2025-08-07 08:04:20 +02:00
Elle Mouton
f51adaf31f graph/db: refactor makeZombiePubkeys
Let the helper method only take the params it needs so that we dont need
to construct an entire models.ChannelEdgeInfo object to pass to it. This
will be useful later on.
2025-08-07 08:04:20 +02:00
Elle Mouton
8aa8c7cc42 multi: remove the NodeRTx interface type 2025-08-06 09:56:21 +02:00
Elle Mouton
15e17e1270 graph/db: remove NodeRTx ForEachChannel method 2025-08-06 09:52:10 +02:00
Elle Mouton
5727bfa688 graph/db: let ForEachNodeCached maybe fetch node addresses
Here we adjust the ForEachNodeCached graph DB method to pass in a node's
addresses into the provided call-back if requested. This will allow us
to improve the performance of node/channel iteration in the autopilot
subserver.
2025-08-06 09:50:54 +02:00
Elle Mouton
ae566744c4 graph/db+autopilot: remove NodeRTx FetchNode method
In this commit, we remove the need for the NodeRTx interface to have the
FetchNode method on it.
2025-08-05 09:59:13 +02:00
Elle Mouton
0850bf4781 graph/db: batch fetch channel data in forEachNodeChannel
Update the forEachNodeChannel helper to batch fetch channel data.
2025-08-05 08:00:19 +02:00
Elle Mouton
dc6f9256bc graph/db: batch fetch channels in ForEachNodeCached
Previously, ForEachNodeCached would batch fetch node _feature_ data but
would still fetch the channel set of each node in a node-by-node fashion
which is not ideal. So this commit updates this method to make use of
the new sqldb.ExecuteCollectAndBatchWithSharedDataQuery helper. It lets
us batch load channel data for a range of node IDs.

This _greatly_ improves the performance of the method.
2025-08-05 08:00:19 +02:00
Elle Mouton
ada349dcf2 graph/db: batch collect node feature data
In this commit, we update the SQLStore's ForEachNodeCacheable and
ForEachNodeCached methods to use batch collection for node feature bits.

This results in the following performance gains:

```
name                                      old time/op  new time/op  delta

ForEachNodeCacheable-native-sqlite-10     184ms ± 2%   145ms ±10%  -21.45%  (p=0.000 n=10+10)
ForEachNodeCacheable-native-postgres-10   697ms ± 8%    51ms ± 4%  -92.68%  (p=0.000 n=9+10)
```
2025-08-05 08:00:19 +02:00
Elle Mouton
ae13158b68 graph/db: update ForEachChannel to use new sqldb helper
Refactor to let ForEachChannel make use of the new
sqldb.ExecuteCollectAndBatchWithSharedDataQuery helper.
2025-08-05 06:36:36 +02:00
Elle Mouton
1219cdb7f1 graph/db: use sqldb helper for ForEachNode
A pure refactor commit which updates the ForEachNode method to make use
of the new sqldb.ExecuteCollectAndBatchWithSharedDataQuery helper.
2025-08-05 06:36:34 +02:00
Elle Mouton
31978b99f4 graph/db: update forEachNodeCacheable to use sqldb helper
A pure refactor which updates forEachNodeCacheable to make use of the
new sqldb.ExecutePaginatedQuery helper.
2025-07-31 15:33:08 +02:00
Elle Mouton
2d09acfca2 graph/db: update ForEachChannelCacheable to use new helper
A pure refactor commit which updates ForEachChannelCacheable to make use
of the new sqldb.ExecutePaginatedQuery helper.
2025-07-31 15:33:08 +02:00
Elle Mouton
61299894e1 graph/db: add buildCachedChanPolicies helper
Here we just remove some code duplication by adding a
buildCachedChanPolicies helper.
2025-07-31 15:33:08 +02:00
Elle Mouton
0f7c0ae9e7 graph/db: refactor to use sqldb.QueryConfig value
This commit is a pure refactor. Here all we are doing is removing the
old `pageSize` constant used in the SQLStore code and instead using the
value provided in the QueryConfig struct.
2025-07-31 15:33:08 +02:00
Elle Mouton
a6248872cb sqldb: rename ExecutePagedQuery to ExecuteBatchQuery
We rename this helper along the config types & helper types for it
because the word "page" is used more often in the context of paging
through results using an offset and limit whereas this helper is
specifically used to split up the slice in queries of the form
"WHERE x in []slice". We do this rename so that there is mimimal
confusion in contexts where we use batching along with actual paging.

The config struct is also renamed to QueryConfig in preparation for it
holding more config options.
2025-07-31 15:32:53 +02:00
Elle Mouton
c1ba7a97a8 graph/db: increase default page size 2025-07-31 07:19:15 +02:00
Elle Mouton
a6b077064f graph/db: use batch loading for ForEachChannel 2025-07-31 07:19:15 +02:00
Elle Mouton
d5da637a38 graph/db: remove unused param 2025-07-31 07:19:14 +02:00
Elle Mouton
f39edae6e3 graph/db: use new batch helpers for edge loading
Use the new batch helpers to replace the existing logic for loading an
edge.
2025-07-31 07:19:14 +02:00
Elle Mouton
8ad5f633bc sqldb: add channel data batch queries
Also add the calling logic for these queries. This logic is not yet
used.
2025-07-31 07:19:14 +02:00
Elle Mouton
36eb0e3ff6 graph/db: use batch loading for NodeUpdatesInHorizon 2025-07-30 19:29:22 +02:00
Elle Mouton
84b1670742 graph/db: use batch loading for ForEachNode 2025-07-30 19:29:22 +02:00
Elle Mouton
d05b918c7a graph/db: refactor buildNode to use batch fetching
Here, we add a new `buildNodeWithBatchData` helper method that can be
used to construct a `models.LightningNode` object using pre-fetched
batch data. The existing `buildNode` method is then adjusted to use this
new helper.
2025-07-30 19:29:22 +02:00
Elle Mouton
0dc0d320f8 graph/db+sqldb: queries and logic for batch fetching node data
In this commit, we add the queries that will be needed to batch-fetch
the data of a set of nodes. The logic for using these new queries is
also added but not used yet.
2025-07-30 19:29:21 +02:00
Elle Mouton
5a1184c664 graph/db+sqldb: remove LEFT JOIN for fetching node addresses
In this commit, we remove the LEFT JOIN query that was used for fetching
a nodes addresses. The reason it was used before was to ensure that we'd
get an empty address list if the node did exist but had no addresses.
This was for the purposes of the `AddrsForNode` method since it needs to
return false/true to indicate if the given node exists.
2025-07-30 18:11:01 +02:00
Elle Mouton
43db6683d2 graph/db+sqldb: only fetch what is needed for graph cache
Add a ListChannelsWithPoliciesForCachePaginated query that only fetches
the channel/policy fields that the cache requires.
2025-07-30 18:11:01 +02:00
Elle Mouton
858c064ca2 graph/db: fix potential nil pointer derefs
Here, we fix two bugs that could lead to a nil pointer dereference.
Both are caused by refering to policies that may be nil at the
call-site.
2025-07-28 14:39:28 +02:00
Elle Mouton
ddc0e95eda graph/db+sqldb: delete channels in batches
Use the new `SLICES` directive to add a DeleteChannels query which takes
a set of DB channel IDs. Then replace all our calls to DeleteChannel
with a paginated call to DeleteChannels.
2025-07-22 17:17:23 +02:00
Elle Mouton
de6c030f29 graph/db: let DeleteChannelEdges use new wrapped SQL call
Update it to use the new wrapped version of
GetChannelsBySCIDWithPolicies to reduce the number of DB calls.
2025-07-22 17:17:13 +02:00
Elle Mouton
e269d57ffa sqldb+graph/db: use pagination for FetchChanInfos 2025-07-22 17:17:11 +02:00
Elle Mouton
88e9a21d63 sqldb+graph/db: update FilterKnownChanIDs to use pagination
Remove a TODO by making use of the new sqldb.ExecutePagedQuery to fetch
channels in batches rather than one by one.
2025-07-22 17:16:59 +02:00
Elle Mouton
f72c48b283 graph/db+sqldb: pass set of outpoints to SQL
This commit adds a new GetChannelsByOutpoints query which takes a slice
of outpoint strings. This lets us then update PruneGraph to use
paginated calls to GetChannelsByOutpoints instead of making one DB call
per outpoint.
2025-07-22 17:16:49 +02:00
Elle Mouton
2fa30e8735 graph+config: add sql pagination config to ChannelGraph 2025-07-22 17:16:41 +02:00
Elle Mouton
74b70a5108 sqldb+graph/db: prefix graph SQL objects with "graph_"
This makes it more clear what each table is for especially when viewed
with other invoice/payments tables.
2025-07-15 18:40:16 +02:00
Elle Mouton
83f6dc4983 multi: reset for ForEachNodeDirectedChannel 2025-07-15 11:25:10 +02:00
Elle Mouton
13d0bd5ef6 graph/db: let ForEachChannelCacheable take a reset param 2025-07-15 11:25:10 +02:00
Elle Mouton
b3f3766fe6 multi: pass reset to GraphSession 2025-07-15 11:25:09 +02:00
Elle Mouton
e17fd58a1d graph/db: pass reset to ForEachNodeCacheable 2025-07-15 11:25:09 +02:00
Elle Mouton
21ac7ef6f4 multi: add reset to ForEachNode 2025-07-15 11:25:09 +02:00
Elle Mouton
c32bf642d2 multi: pass reset to ForEachNodeCached 2025-07-15 11:23:27 +02:00
Elle Mouton
e5fbca8299 multi: let ForEachNodeChannel take a reset param 2025-07-15 11:23:27 +02:00
Elle Mouton
16126d7703 graph/db: expose reset in ForEachSourceNodeChannel 2025-07-15 11:23:27 +02:00
Elle Mouton
88261834e5 graph/db: expose reset in ForEachChannel
Add a `reset` call-back param to the V1Store ForEachChannel method.
2025-07-15 11:23:26 +02:00
Elle Mouton
e00f0a03fc graph/db: prep SQLStore for reset param
This commit just surfaces the locations in the SQLStore where we will
later pass reset params through.
2025-07-15 11:23:26 +02:00