Commit Graph

322 Commits

Author SHA1 Message Date
Elle Mouton
522e200c0e graph/db: add missing counter increment 2025-08-07 08:12:40 +02:00
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
4cc5cfef2a graph/db: add ChanUpdatesInHorizon benchmark 2025-08-07 08:04:19 +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
6ac19b4330 graph/db: cover more DB methods in benchmark test
So that we can properly measure upcoming performance improvements.
2025-08-05 08:00:18 +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
1a60edbd33 make+graph/db: add -short helper and skip tests in short mode
In this commit, we add a makefile helper that can be used to add the
"-short" flag to the "go test" command when running unit tests via "make
unit ...".

Tests can then be expanded with a `testing.Short()` check to potentially
skip the test in short mode. This is useful for if a dev wants to
quickly run most of the tests in a package but would like to opt out of
running the longer form tests such as stress tests or rapid generation
tests.

This commit adds this check to two graph/db tests.
2025-08-05 06:34:38 +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
c8c86717f2 graph/db: add NodeUpdatesInHorizon benchmark 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
5800a3e054 graph/db: benchmark various graph read calls
This commit adds benchmark tests for the ForEachNode and ForEachChannel
DB calls which are called by DescribeGraph.
2025-07-30 14:06:33 +02:00
Elle Mouton
f5ce4a5656 graph/db: add BenchmarkCacheLoading
Add a benchmark test to test graph cache loading against various local
graph DBs.
2025-07-30 14:06:33 +02:00
Elle Mouton
45033b8c54 graph/db: add SQL migration progress logs 2025-07-30 14:06:33 +02:00
Elle Mouton
77fe1816f6 graph/db: add test helper for populating via migration
This commit adds a helper test that is similar to TestPopulateDBs except
for the fact that it uses the MigrateGraphToSQL function directly to
migrate a local kvdb-sql graph to a native SQL one.
2025-07-30 14:06:33 +02:00
Elle Mouton
afbe6b12ed graph/db: define various db connection helpers for incoming tests
This is a prep commit that just adds all the boilerplate connection
logic for connecting to various graph DBs. These will be used in
upcoming commits which will add tests and benchmarks.
2025-07-30 14:06:33 +02:00
Elle Mouton
240966de90 graph/db+log: use v2 logger for graph subsystem 2025-07-29 11:34:47 +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