166 Commits

Author SHA1 Message Date
ziggie
a9c30dacb5 sqldb: add helper for type boolean 2025-09-05 09:53:59 +02:00
ziggie
2d032044f9 sqldb: Make sure we do not replace keywords if they have a prefix
We don't for example want to replace CURRENT_TIMESTAMP when using
it in our tables.
2025-09-05 09:52:41 +02:00
Elle Mouton
9ce14371e1 multi: switch on graph SQL migration
In this commit, the graph SQL migration is added to the production
build.
2025-09-04 18:52:00 +02:00
Elle Mouton
40b279687f sqldb: add SQLStrValid helper
The SQL* helpers are meant to always set the `Valid` field of the
sql.Null* type to true. Otherwise they cannot be used to set a valid,
empty field. However, we dont want to break the behaviour of the
existing SQLStr helper and so this commit adds a new helper with the
desired functionality.
2025-09-03 15:46:11 +02:00
Yong
84b2c20ea0 Merge pull request #10167 from starius/go124
multi: bump Go to 1.24.6
2025-09-01 20:03:54 +08:00
Elle Mouton
f2ed5564ef graph/db+sqldb: improve performance of chan update sql migration
This commit simplifies insertChanEdgePolicyMig. Much of the logic can be
removed given that this method is only used in the context of the graph
SQL migration.

This should improve the performance of the migration quite a lot since
it removes the extra GetChannelAndNodesBySCID call.
2025-09-01 08:07:57 +02:00
Elle Mouton
22bf88e900 graph/db+sqldb: make policy migration idempotent
Finally, we make the channel-policy part of the SQL migration idempotent
by adding a migration-only policy insert query which will not error out
if the policy already exists and does not have a timestamp that is newer
than the existing records timestamp. To keep the commit simple, a
insertChanEdgePolicyMig function is added which is basically identical
to the updateChanEdgePolicy function except for the fact that it uses
the newly added query. In the next commit, it will be simplified even
more.
2025-09-01 08:06:12 +02:00
Elle Mouton
8736fcafa8 graph/db+sqldb: make channel SQL mig retry-safe
In this commit, we make the channel part of the graph SQL migration
idempotent (retry-safe!). We do this by adding a migration-only channel
insert query that will not error out if a the query is called and a
chanenl with the given scid&version already exists. We also ensure that
errors are not thrown if existing channel features & extra types are
re-added.
2025-09-01 08:05:21 +02:00
Elle Mouton
a291d6f1a6 graph/db+sqldb: improve efficiency of node migration
There is no need to use the "collect-then-update" pattern for node
insertion during the SQL migration since if we do have any previously
persisted data for the node and happen to re-run the insertion for that
node, the data will be exactly the same. So we can make use of "On
conflict, no nothing" here too.
2025-09-01 08:02:38 +02:00
Elle Mouton
ddea6d59ce graph/db+sqldb: make node migration idempotent
In this commit, the graph SQL migration is updated so that the node
migration step is retry-safe. This is done by using migration specific
logic & queries that do not use the same node-update-constraint as the
normal node upsert logic. For normal "run-time" logic, we always expect
a node update to have a newer timestamp than any previously stored one.
But for the migration, we will only ever be dealing with a single
announcement for a given node & to make things retry-safe, we dont want
the query to error if we re-insert the exact same node.
2025-09-01 07:56:34 +02:00
Boris Nagaev
dee8ad3754 multi: context.Background() -> t.Context()
Use the new feature of Go 1.24, fix linter warnings.

This change was produced by:
 - running golangci-lint run --fix
 - sed 's/context.Background/t.Context/' -i `git grep -l context.Background | grep test.go`
 - manually fixing broken tests
 - itest, lntest: use ht.Context() where ht or hn is available
 - in HarnessNode.Stop() we keep using context.Background(), because it is
   called from a cleanup handler in which t.Context() is canceled already.
2025-08-30 14:13:44 -03:00
Boris Nagaev
6ffe257004 multi: bump Go to 1.24.6 2025-08-30 14:13:44 -03:00
Oliver Gugger
31fc556507 Merge pull request #10155 from ziggie1984/add-missing-invoice-settle-index
Add missing invoice index for native sql
2025-08-14 09:23:37 -06:00
ziggie
35e9979d67 docs: add schema update doc 2025-08-14 12:00:40 +02:00
ziggie
ea9fb80eff sqldb: use the new schema
We put this new schema update into the main line and change the
versions of the schema updates which are currently only available
in dev builds. The schemas need to be chronological therefore we
also need to rename the file numbers.
2025-08-14 11:59:09 +02:00
ziggie
506d226eb3 sqldb: add missing index for settled invoices 2025-08-14 08:17:15 +02:00
ziggie
22fbbee837 sqldb: delete wrong index names and add missing one 2025-08-14 08:17:15 +02:00
Elle Mouton
f560c4d95b sqldb: use uint32 for config values 2025-08-14 08:03:28 +02:00
Elle Mouton
5b06474744 graph/db+sqldb: batch validation for zombie index migration
Finally, we update the migrateZombieIndex function to use batch
validation just like was done in the previous commits. Here, we
additionally make sure to validate the entire zombie index entry and not
just the SCID.
2025-08-14 08:00:07 +02:00
Elle Mouton
a490e03479 graph/db+sqldb: use batch validation for closed SCID migration
As was done in the previous commits for nodes & channels, we update the
migrateClosedSCIDIndex function here so that it validates migrated
entries in batches rather than one-by-one.
2025-08-14 08:00:06 +02:00
Elle Mouton
8554f17b3f graph/db+sqldb: validate prune log migration using batching
As was done in the previous commits for nodes & channels, we update the
migratePruneLog function here so that it validates migrated entries in
batches rather than one-by-one.
2025-08-14 08:00:06 +02:00
Elle Mouton
81c54611c1 graph/db+sqldb: use batch fetching during channel&policy migration
Restructue the `migrateChannelsAndPolicies` function so that it does the
validation of migrated channels and policies in batches. So instead of
fetching channel and its policies individually after migrating it, we
wait for a minimum batch size to be reached and then validate a batch of
them together. This lets us make way fewer DB round trips.
2025-08-14 08:00:06 +02:00
Elle Mouton
03ef2740a6 graph/db+sqldb: use batch validation for node migration
Restructue the `migrateNodes` function so that it does the validation of
migrated nodes in batches. So instead of fetching each node individually
after migrating it, we wait for a minimum batch size to be reached and
then validate a batch of nodes together. This lets us make way fewer DB
round trips.
2025-08-14 08:00:06 +02:00
Elle Mouton
b1deddec44 multi: remove DefaultQueryConfig
And always make use of either the new DefaultSQLiteConfig or
DefaultPostgresConfig.
2025-08-13 14:43:31 +02:00
Elle Mouton
6a31e06817 graph/db+sqldb: find best default query cfg values for sqlite & postgres
This commit adds a BenchmarkFindOptimalSQLQueryConfig test in the
graph/db package which runs ForEachNode and ForEachChannel queries
against a local backend using various different values for the sql
QueryConfig struct. This is done to determine good default values to
use for the config options for sqlite vs postgres.
2025-08-13 14:43:31 +02:00
Elle Mouton
185166b8d3 sqldb+config: validate maximum batch size config value
Now that the SQL query config values are configurable, we add some
validation to make sure that the user doesnt set a max batch size that
is larger than the limits for sqlite/postgres that have been determined
by the TestSQLSliceQueries test.
2025-08-13 14:43:31 +02:00
Elle Mouton
ee292786b1 config+sqldb: make native SQL query config options configurable
Here, we make the sql query option params (batch size and pagination
size) configurable. The defaults for SQLite vs Postgres are still the
same but will be changed in an upcoming commit.
2025-08-13 14:43:31 +02:00
Elle
a3793b2523 Merge pull request #10129 from ellemouton/graphPerf9
[8] graph/db: use batch loading for various graph SQL methods
2025-08-08 10:22:51 +02:00
ziggie
87844cd5b4 multi: bump Golang version to v1.23.12 2025-08-07 16:53:45 +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
3b60d33ac8 sqlc: add ListChannelsForNodeIDs batch query
Add a ListChannelsForNodeIDs query which will let us fetch all channels
belonging to a set of nodes.
2025-08-05 08:00:19 +02:00
Elle Mouton
905941067e sqldb: add ExecuteCollectAndBatchWithSharedDataQuery helper
In this commit we add a new helper method in the sqldb package:
ExecuteCollectAndBatchWithSharedDataQuery. This can be used to paginate
through items in the database while at the same time performing batch
data collection for those items.
2025-08-05 06:34:38 +02:00
Elle Mouton
e276f1ec3e sqldb: add ExecutePaginatedQuery helper
In this commit we add the ExecutePaginatedQuery helper function which
can be used to execute cursor-based paginated queries.
2025-07-31 15:33:07 +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
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
6ca43173a1 sqldb: change default slices page size 2025-07-30 19:29:23 +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
3eed2f94c1 sqldb/sqlc: add index on graph_channels(version, id)
This new index greatly improves the speed of the
ListChannelsWithPoliciesPaginated query.
2025-07-30 18:11:01 +02:00
Boris Nagaev
d02520d2b9 go.mod: bump mapstructure/v2 to v2.3.0 2025-07-25 12:21:18 -03:00
Boris Nagaev
3ff11e0765 go.mod: bump runc to v1.1.14 2025-07-25 12:21:13 -03: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
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