Commit Graph

322 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
9059a4e7ba Merge pull request #10080 from ellemouton/graphPrefixTables
sqldb+graph/db: prefix graph SQL objects with "graph_"
2025-07-15 15:21:02 -07: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
d7b8259a36 graph/db: add graph SQL migration rapid unit test 2025-07-15 18:17:23 +02:00
Elle Mouton
955f4c9182 graph/db: refactor to make postgres fixtures re-usable
In preparation for tests where we will want to spin up SQL DBs many
times, we do some refactoring so that it is easy to re-use postgres
fixtures since those are expensive to spin up.
2025-07-15 18:06:05 +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
Elle Mouton
57d4ce0f9b graph/db: expose KVStore locations where a reset is needed
This commit passes no-op reset callbacks to various places where they
are needed in the KVStore. Upcoming commits will replace the no-ops by
adding reset params to the methods that require it.
2025-07-15 11:23:26 +02:00
Elle Mouton
8b82a5c8fe graph/db: migrate zombie index to SQL
This commit expands `MigrateGraphToSQL` to include migration of the
zombie index.

NOTE: we take this opportunity to clean up the zombie index a bit by
first checking for each channel in the zombie index if it has been
marked as closed in the closed-scid index. If it has, then there is no
need to include it in the zombie index. A special case test for this
is added too.
2025-07-11 09:36:17 +02:00
Elle Mouton
0cb17bbbe5 graph/db: migrate closed SCID index
This commit expands `MigrateGraphToSQL` to include the migration of the
closed-scid index.
2025-07-11 09:36:14 +02:00
Elle Mouton
03ede9ccef graph/db: migrate prune log
This commit expands the `MigrateGraphToSQL` to include migration of the
prune log.
2025-07-11 09:15:47 +02:00
Elle Mouton
36f8a66b5a graph/db: remove temporary test skip
The skip is no longer needed.
2025-07-10 14:54:04 +02:00
Elle Mouton
b7d4f80e3e graph/db: pass in ctx to test method
Fix compilation error.
2025-07-10 14:53:10 +02:00
Oliver Gugger
8ee661f18f Merge pull request #10043 from ellemouton/ctx3
multi: add context.Context param to more graphdb.V1Store methods
2025-07-10 13:40:51 +02:00
Elle Mouton
b58089049a graph/db: migrate channels and polices to SQL
In this commit, the `MigrateGraphToSQL` function is expanded to migrate
the channel and channe policy data. Both of these have the special case
where the kvdb store records may contain invalid TLV. If we encounter a
channel with invalid TLV, we skip it and its policies. If we encounter a
policy with invalid TLV, we skip it.

The `TestMigrateGraphToSQL` and `TestMigrationWithChannelDB` tests are
updated accordingly.
2025-07-09 10:18:57 +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
3d5e852c8c graph/db: let ForEachNodeCached take a context 2025-07-08 15:11:02 +02:00
Elle Mouton
1e804a3d5f graph/db: let ForEachNode take a context 2025-07-08 15:11:02 +02:00
Elle Mouton
f05ef2db97 graph/db: let ForEachNodeCacheable take a context 2025-07-08 15:10:30 +02:00
Elle Mouton
046e106a17 graph/db: let ForEachChannel take a context 2025-07-08 15:10:30 +02:00
Elle Mouton
f8d3a3f3ba graph/db: let ForEachNodeChannel take a context 2025-07-08 15:10:30 +02:00
Elle Mouton
67c0f54e13 graph/db+server: let ForEachSourceNodeChannel take a context 2025-07-08 15:10:30 +02:00
Elle Mouton
61c1d258c3 graph/db: factor out helper code
Here we factor out some of the crud code in TestEdgePolicyMissingMaxHtcl
so that we can re-use it later on.
2025-07-08 14:30:14 +02:00
Elle Mouton
0162ee949c graph/db: move TLV validation for KVStore
Here, we move TLV validation for the KVStore out of `updateEdgePolicy`
so that we can re-use `updateEdgePolicy` in our tests to write policies
with invalid TLV (since that was possible before the recently added TLV
sanity check) so that we can test that our SQL migration behaves
correctly for these cases.
2025-07-08 14:28:45 +02:00
Elle Mouton
9657707175 graph/db: migrate source node to SQL store 2025-07-08 11:37:41 +02:00
Elle Mouton
8b2f4821d4 graph/db: migrate nodes to SQL store
This commit expands MigrateGraphToSQL so that it migrates all the graph
nodes from kvdb to SQL.

The TestMigrateGraphToSQL test is updated to cover the basic
LightningNode cases. A new test, `TestSQLMigrationEdgeCases`, is also
added and a case is added to tests the edge case where a node exists in
our kvdb store that has invalid TLV bytes.
2025-07-08 11:37:39 +02:00
Elle Mouton
5c09652e1a graph/db: add dev migration test helper
This commit was inspired by the invoices package
TestMigrationWithChannelDB test helper.

This test is purely for running locally to test the graph SQL migration.
It allows a dev to run the migration against a local `channel.sqlite` or
even `channel.db` file.
2025-07-07 13:35:30 +02:00
Elle Mouton
e3572e77c5 graph/db: add SQL migration function and test framework
In this commit, the basic framework for the graph SQL migration is
added. This sets us up for the commits to follow which will add
migration logic for each table in the graph commit by commit.
2025-07-07 13:34:19 +02:00
Elle Mouton
5d7abcdf03 graph/db: refactor SQL DB creation files
Factor out the transaction executor construction so that we can have
access to the raw BatchedSQLQueries type from within tests.
2025-07-07 08:36:12 +02:00
Elle Mouton
c9a775e7fb graph/db: fix build flag directive
Fix a typo in the build directive.
2025-07-07 08:36:12 +02:00
Elle Mouton
2f2845dfc0 refactor+multi: use *lnwire.FeatureVector for ChannelEdgeInfo features
In this commit, we move the serialisation details of a channel's
features to the DB layer and change the `models` field to instead use a
more useful `*lnwire.FeatureVector` type.

This makes the features easier to work with and moves the serialisation
to where it is actually used.
2025-07-01 17:02:07 +02:00
Elle Mouton
92849388b8 graph/db: return channel DB info from insertChannel
In preparation for the kvdb->migration code, this commit updates
`insertChannel` to return the ID of the newly inserted channel along
with the IDs of the nodes that the channel links to.
2025-07-01 13:37:09 +02:00
Elle Mouton
4bde8e2d04 graph/db: refactor and clean-up
Refactor channelIDToBytes to return a slice instead of an 8 byte array
so that we dont need to use `[:]` everywhere.

Also make sure we are using this helper everywhere.
2025-07-01 13:37:09 +02:00
Elle Mouton
2310756307 graph/db: refactor source node fetching logic
Small refactor to introduce a re-usable getSourceNode function that we
can then make use of in the upcoming kvdb->SQL migration logic.
2025-07-01 13:37:07 +02:00
Elle Mouton
016fd9bb4d graph/db: create a re-usable forEachChannel
Create a forEachChannel function that does not rely on a KVStore being
instantiated. We will use this in our upcoming kvdb->SQL migration.
2025-07-01 13:31:48 +02:00
Elle Mouton
9452c0b950 graph/db: detach getChannelMap from KVStore 2025-07-01 13:31:48 +02:00
Elle Mouton
8660f76b20 graph/db: detach forEachNode from KVStore
So that we can use it in a context that only has access to a
kvdb.Backend. We'll use this in our kvdb->SQL migration.
2025-07-01 13:31:48 +02:00
Oliver Gugger
500808fadd Merge pull request #10010 from ellemouton/sqlGraphUpdates
graph/db: various misc updates
2025-07-01 12:40:50 +02:00
Elle Mouton
c5b2e4e50a graph/db: update outdated comments 2025-07-01 10:12:54 +02:00
Elle Mouton
e4137a3f14 graph/db: fix ChanUpdate message/channel flag bug
Here we start using the newly added message_flags and channel_flags
columns of the channel_policies table. The test added previoulsy to
demonstrate the bug is now updated to show that the bug has been fixed.
2025-07-01 10:12:54 +02:00
Elle Mouton
fa32f97c05 graph/db: unit test to demonstrate SQL chan policies bug
This commit adds a new graph store unit test that demonstrates that
there is currently a bug in the SQL version of the graph store where
unknown message or channel flags in a channel_update are not persisted
correctly. This will be fixed in an upcoming commit.
2025-07-01 10:12:53 +02:00
Elle Mouton
64fc92abe7 graph/db: update nextUpdateTime in tests
Let it return time.Time instead. Also, make use of the helper in a few
more places.
2025-07-01 10:04:03 +02:00
Elle
c7aa17971b Merge pull request #10006 from ellemouton/fixSQLFetchChannelEdgesByID
graph/db: let FetchChannelEdgesByID behave as promised
2025-07-01 10:01:36 +02:00