Commit Graph

19597 Commits

Author SHA1 Message Date
Elle Mouton
238052438e graph/db: let the rapid migration test also tests idempotency 2025-08-15 13:46:46 +02:00
Elle Mouton
b6d48dd23c 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-08-15 13:46:45 +02:00
Elle Mouton
3d89ec4b18 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-08-15 13:46:45 +02:00
Elle Mouton
136fe076d2 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-08-15 13:46:45 +02:00
Elle Mouton
d9754c6e3a 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-08-15 13:46:45 +02:00
Elle Mouton
7b61744bed graph/db+sqldb: make node migration idempotent
In this commit, the graph SQL migration is updates 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-08-15 13:46:45 +02:00
Elle Mouton
265f42aff5 graph/db: thread through reset call-backs
In preparation for handling retries on the source DB side, we thread
through the `reset` call-backs properly so that we can reset appropriate
variables.
2025-08-15 13:46:45 +02:00
Elle Mouton
612d424196 graph/db: migration test for channels with no policies
In preparation for making the channel & policy migration logic
idempotent in a step-by-step manner, we add a test here that only tests
the migration of channels _without_ policies so that we can first focus
on just making the channel migration idempotent.
2025-08-15 13:46:45 +02:00
Elle Mouton
5fa5ca1073 graph/db: let migration test test retry safety
Currently, the graph SQL migration is not retry safe. Meaning that if
the source DB exeutes a retry under the hood, this could result in the
migration failing. In preparation for fixing this, we adust the
migration test accordingly.
2025-08-15 13:46:45 +02:00
Elle Mouton
849d81c691 graph/db: let test policy have some extra opaque data
This will help us test idempotency later on, but it also ensures that
TestMigrateGraphToSQL is properly testing writes to the
graph_channel_policy_extra_types table.
2025-08-15 13:46:45 +02:00
Elle Mouton
a69762f3bf unwrap dns addresses from opaque ones during migration 2025-08-15 13:45:40 +02:00
Elle Mouton
6b38f8d9df graph/db: update TestAddrSerialization 2025-08-15 05:53:04 +00:00
Elle Mouton
3fa137e187 graph/db+chanbackup: dns add encoding/decoding for persistence 2025-08-15 05:53:04 +00:00
Elle Mouton
dc4111aad0 graph/db: update test opaque addr to be valid
The first byte of an opaque addr must be one that we dont understand
yet. We do this update in preparation for doing an on-the-fly parse of
persisted opaque addrs to see if they contain addrs that we now support.
For this to work, the first byte cant be 0x01 since this maps to a known
address.
2025-08-15 05:53:04 +00:00
Elle Mouton
0a064d531c lnwire: extract addr descriptor reading logic
cause we will need to be able to deserialise any persisted OpaqueAddrs
which will have a Payload that we should be able to decode with this
lnwire method to extract any new addresses that we now support.

Co-authored-by: Elle Mouton <elle.mouton@gmail.com>
2025-08-15 05:53:04 +00:00
Elle Mouton
5844bb0477 discovery+gossip: make sure we dont advertise node anns with bad DNS
We may have already persisted node announcements that have multiple DNS
addresses since we may have received them before updating our code to
check for this. So here we just make sure not to send these on to our
peers.
2025-08-15 05:53:04 +00:00
Elle Mouton
a7ae21d685 netadd: split ValidatenodeAnn into sig and field checks
Check that the node ann doesnt contain more than 1 DNS addr.
This will ensure that we now start rejecting new node announcements
with multiple DNS addrs since this check is called in the gossiper
before persisting a node ann to our local graph.

It also validates the DNS fields according to BOLT #7 specs.
2025-08-15 05:53:03 +00:00
Elle Mouton
41bd519859 lnwire: add encoding/decoding for DNS addr
Co-authored-by: Elle Mouton <elle.mouton@gmail.com>
2025-08-15 05:49:13 +00:00
Mohamed Awnallah
4d9f884c3f lnwire: add DNSAddress type 2025-08-15 05:49:11 +00:00
Mohamed Awnallah
05e4370ebd lnwire: remove AddrLen helper
In this commit, we remove `AddrLen` as prepration step
before adding DNS address type which will have a var length.

Co-authored-by: Elle Mouton <elle.mouton@gmail.com>
2025-08-15 03:35:00 +00: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
Oliver Gugger
4b3ede5cb0 Merge pull request #10154 from ellemouton/graphPerf11
graph/db: use batch validation to improve SQL migration performance
2025-08-14 05:54:21 -06:00
ziggie
35e9979d67 docs: add schema update doc 2025-08-14 12:00:40 +02:00
ziggie
b98cc24cfe docs: add release-notes 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
d5729845d0 graph/db: remove outdated TODO 2025-08-14 08:00:07 +02:00
Elle Mouton
b1c643f4f1 graph/db: add migration timing logs
Time the full duration of each graph migration step for the purposes of
logging.
2025-08-14 08:00:07 +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
218aa9eaa8 graph/db: move sanity check out of insertChannel
We do this so that this lookup is only done in the situation it is
actually needed. During a migration, we dont need to special case this
AlreadyExists error since we will terminate the transaction either way.
So there is no need for the extra lookup during the migration.

A timing analysis showed that this query was significantly impacting the
performance of the migration when run with a postgres backend.
2025-08-14 07:57:33 +02:00
Elle
5f3055944a Merge pull request #10148 from ellemouton/graphPerf10
graph/db+sqldb: different defaults for SQLite and Postgres query options
2025-08-14 07:56:28 +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
1082eaaeb3 graph/db: fix progress logs 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
Yong
c6a9116e3a Merge pull request #9844 from ziggie1984/refactor-payments-code-03
Refactor Payment PR 3
2025-08-13 06:05:01 -04:00
Elle Mouton
75691163a9 graph: remove outdated TODO
This todo has been addressed.
2025-08-13 08:45:52 +02:00
Olaoluwa Osuntokun
8810793e61 Merge pull request #9871 from GeorgeTsagk/htlc-noop-add
Add `NoopAdd` HTLCs
2025-08-12 11:56:04 -07:00
ziggie
4e0af2f495 channeldb: rename storedPaymentSeq 2025-08-11 16:44:15 +02:00
ziggie
a4b1569647 channeldb: rename currPaymentSeq 2025-08-11 16:44:15 +02:00
ziggie
6bae3c98b3 channeldb: rename paymentSeqMx 2025-08-11 16:44:14 +02:00
ziggie
88da582526 mulit: use kvdb.Backend for the kv payment db
Instead of the ChannelState struct we now use the kv backend
interface for the payment kv database.
2025-08-11 16:44:14 +02:00
ziggie
3aec40293d paymentsdb: add subsystem logging for payments package 2025-08-11 16:44:14 +02:00