104 Commits

Author SHA1 Message Date
500808fadd Merge pull request #10010 from ellemouton/sqlGraphUpdates
graph/db: various misc updates
2025-07-01 12:40:50 +02:00
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
4a05e5a226 sqldb/sqlc: add message and channe flags to channel_policies table
We need to explicitly store the entire bitfield types since we may have
channel_updates with bitfields containing bits we just dont need or
understand but we still need to store the entire bitfield so that the
reconstructed announcement remains valid.

This commit only adds the new columns but does not use them yet. NOTE:
this is ok since the migration adding this schema is not available in
the production build yet.
2025-07-01 10:12:54 +02:00
90aacaae2a sqldb: add SQLInt16 helper 2025-07-01 10:12:53 +02:00
f1b7ccc6b2 sqldb+graph/db: prune graph nodes in a single query
Update the pruneGraphNodes routine to prune the graph nodes in a single
query instead of two.
2025-06-30 18:41:28 +02:00
e38aa6d1e0 multi: itest jobs with SQL graph backend
In this commit, a new `test_native_sql` build flag is defined. If this
build flag is used along with the `--use-native-sql` config option, then
the SQLStore implementation of the graphdb.V1Store will be initialised.
This is then used to run our itest suite against the new SQLStore graph
implementation.

NOTE that this only works for new nodes currently - the migration from
kv-to-sql is yet to be implemeneted.
2025-06-26 10:12:54 +02:00
933ab3c6b7 graph/db+sqldb: impl PutClosedScid and IsClosedScid 2025-06-25 13:26:52 +02:00
5effa96766 sqldb: closed_scids table 2025-06-25 13:26:52 +02:00
d46552f5ad graph/db+sqldb: implement AddEdgeProof
And run `TestAddEdgeProof` against the SQL backends.
2025-06-25 13:26:51 +02:00
e875183c4f sqldb+graph/db: impl DisconnectBlockAtHeight
Which lets us run `TestDisconnectBlockAtHeight` and
`TestStressTestChannelGraphAPI` against our SQL backends.
2025-06-25 11:22:03 +02:00
9dd0361ed0 graph/db+sqldb: impl PruneGraph, PruneTip, ChannelView
Which lets us run `TestGraphPruning` and `TestBatchedAddChannelEdge`
against our SQL backends.
2025-06-25 11:22:00 +02:00
2da701cc4f graph/db+sqldb: impl PruneGraphNodes
Which lets us run `TestChannelEdgePruningUpdateIndexDeletion` against
our SQL backends.
2025-06-25 10:48:35 +02:00
102c04daaf sqldb/sqlc: prune_log schema
Define the schema for the prune log.
2025-06-25 10:48:35 +02:00
eec89362a5 graph/db+sqldb: impl DisabledChannelIDs
Which lets us run `TestDisabledChannelIDs` against our SQL DB backends.
2025-06-24 21:04:36 +02:00
f1da3812de graph/db+sqldb: impl IsPublicNode
Which lets us run `TestNodeIsPublic` against our SQL DB backends.
Note that we need to tweak the tests a little bit so that
`AddLightningNode` for the same node is always called with a newer
LastUpdate time else it will fail the SQL constraint that only allows
the upsert if the update is newer than the persisted one.
2025-06-24 21:04:36 +02:00
13bf6a549f graph/db+sqldb: implement HasChannelEdge and ChannelID
And run `TestEdgeInfoUpdates` against our SQL backends.
2025-06-24 21:04:35 +02:00
4fad4a7023 graph/db+sqldb: implement FetchChannelEdgesByOutpoint/SCID
And run `TestEdgeInsertionDeletion` against our SQL backends.
2025-06-24 21:04:35 +02:00
2a6e6683eb graph/db+sqldb: implement DeleteChannelEdges
This lets us run TestGraphZombieIndex against the SQL backends.
2025-06-24 19:02:45 +02:00
00b6e0204c graph/db+sqldb: implement various zombie index methods
Here we implement the SQLStore methods:
- MarkEdgeZombie
- MarkEdgeLive
- IsZombieEdge
- NumZombies

These will be tested in the next commit as one more method
implementation is required.
2025-06-24 19:02:14 +02:00
c648c7a22d sqldb/sqlc: add zombie index table
Note that this table will only contain entries for channels that we have
deleted from the `channels` table which is why we cannot use foreign
keys. Similarly, we may no longer have node entries for the nodes in the
table.
2025-06-24 18:35:19 +02:00
3687171cd5 sqldb+graph/db: implement FilterChannelRange
This lets us run `TestFilterChannelRange` against the SQL backends.
2025-06-24 12:17:52 +02:00
ff84fa1cb2 graph/db+sqldb: impl ForEachNodeCached and ForEachChannel
Which let's us run `TestGraphTraversal` against our SQL backends.
2025-06-24 12:17:52 +02:00
6aa2933379 sqldb: add index on node & chan policy last_update columns
So that we can have efficient lookups during the "*UpdatesInHorizon"
calls.
2025-06-24 12:17:52 +02:00
39e521e12b graph/db+sqldb: implement ChanUpdatesInHorizon
Add `ChanUpdatesInHorizon` method to the SQLStore. This lets us run
`TestChanUpdatesInHorizon` against our SQL backends.
2025-06-24 12:17:52 +02:00
0607982886 graph/db: implement ForEachNodeDirectedChannel and ForEachNodeCacheable
Here we add the `ForEachNodeDirectedChannel` and `ForEachNodeCacheable`
SQLStore implementations which then lets us run
`TestGraphTraversalCacheable` and `TestGraphCacheForEachNodeChannel`
against SQL backends.
2025-06-18 16:55:00 +02:00
8af32951c7 graph/db+sqldb: implement ForEachNode
In this commit the `ForEachNode` method is added to the SQLStore. With
this, the `TestGraphCacheTraversal` unit test can be run against SQL
backends.
2025-06-18 16:54:59 +02:00
f89e3ceced graph/db+sqldb: implement ForEachSourceNodeChannel
In this commit, the ForEachSourceNodeChannel implementation of the
SQLStore is added. Since this is the first method of the SQLStore that
fetches channel and policy info, it also adds all the helpers that are
required to do so. These will be re-used in upcoming commits as more
"For"-type methods are added.

With this implementation, we convert the `TestForEachSourceNodeChannel`
such that it is run against SQL backends.
2025-06-18 08:43:56 +02:00
c327988bb3 graph/db+sqldb: implement UpdateEdgePolicy
In this commit, the various SQL queries are defined that we will need in
order to implement the SQLStore UpdateEdgePolicy method. Channel
policies can be "replaced" and so we use the upsert pattern for them
with the rule that any new channel policy must have a timestamp greater
than the previous one we persisted.

As is done for the KVStore implementation of the method, we use the
batch scheduler for this method.
2025-06-17 13:43:07 +02:00
4e2750e179 sqldb: channel policy tables
Define the SQL tables for representing channel policies. Namely:

- channel_policies
- channel_policy_extra_types
2025-06-12 07:16:18 +02:00
3a264aabca sqldb: fix graph DROP order
Ensure that the graph tables are dropped in reverse dependency order.
2025-06-12 07:15:04 +02:00
73251952d1 mod: update btclog library 2025-06-03 13:06:28 +02:00
547b836180 sqldb+graph/db: fix UpsertNode bug
Account for the last_update field being null.
2025-06-02 17:29:03 +02:00
cf542458bd graph/db+sqldb: add HighestChanID to SQLStore 2025-06-02 14:53:18 +02:00
d93d104a66 graph/db+sqldb: implement AddChannelEdge on SQLStore
In this commit, the `AddChannelEdge` method of the SQLStore is
implemented. Like the KVStore implementation, it makes use of the
available channel `batch.Scheduler` and also updates the reject and
channel caches.

This then lets us convert the following 2 unit tests to run against the
SQL backends:
- TestPartialNode
- TestAddChannelEdgeShellNodes
2025-06-02 14:53:18 +02:00
e5d099ef14 sqldb/sqlc: add graph channel schemas
In this commit, we define the SQL schemas for storing graph channel
data. This includes a new `channels` table and a new `channel_features`
table along with various indices.
2025-06-02 14:53:17 +02:00
9cbc1f804e multi: use sqldb.NoOpReset helper
Define a re-usable "reset" function, sqldb.NoOpReset, that can be used
for the reset parameter in sql ExecTx calls.
2025-05-28 10:18:53 +02:00
c4e6f23c5b multi: add a re-usable TxOptions type
Add a re-usable implementation of the sqldb.TxOptions interface and make
use of this in the various spots (invoices, batch and graph/db) where we
had previously defined individual implementations that were all doing
the same thing.
2025-05-28 10:18:10 +02:00
0064d33cda sqldb+graph/db: source nodes table, queries and CRUD
In this commit, we add the `source_nodes` table. It points to entries in
the `nodes` table. This table will store one entry per protocol version
that we are announcing a node_announcement on.

With this commit, we can run the TestSourceNode unit test against our
SQL backends.
2025-05-27 18:36:59 +02:00
86d48390ca sqldb+graph/db: implement SQLStore.NodeUpdatesInHorizon
In this commit we add the necessary SQL queries and then implement the
SQLStore's NodeUpdatesInHorizon method. This lets us run the
TestNodeUpdatesInHorizon unit tests against SQL backends.
2025-05-27 18:36:59 +02:00
d1f7cce68b sqldb+graphdb: SQL methods for Node CRUD
In this commit, we add the various sqlc queries that we need in order
to implement the following V1Store methods:

- AddLightningNode
- FetchLightningNode
- HasLightningNode
- AddrsForNode
- DeleteLightningNode
- FetchNodeFeatures

These are implemented by SQLStore which then lets us use the SQLStore
backend for the following unit tests:

- TestNodeInsertionAndDeletion
- TestLightningNodePersistence
2025-05-27 18:36:59 +02:00
ffbe4f6ffc sqldb: define schemas for all graph node tables
In this commit, the various SQL schemas required to store graph node
related data is defined. Specifically, the following tables are defined:

- nodes
- node_extra_types
- node_features
- node_addresses
2025-05-27 16:28:37 +02:00
ab717c301b Merge pull request #9864 from ziggie1984/update-sqlc
sqlc: update sqlc compiler to 1.29.0
2025-05-26 09:27:01 +02:00
5baaa3e7c5 sqlc: update sqlc compiler to 1.29.0 2025-05-25 18:23:35 +02:00
be915f2be7 sqldb: add support for test migrations
Add `migrations_dev.go` and `migrations_prod.go` files which each define
a `migrationAdditions` slice to be appended to the `migrationConfig`
slice. The `migrations_dev.go` file is only built if either the
`test_db_postgres` or `test_db_sqlite` build flags are used.

This slice will be used to add any migrations that are still under
development that we want access to via unit tests and itests but do not
want to expose to our release build.
2025-05-22 14:14:42 +02:00
383453635b sqldb+go.mod: update sqldb test methods
Update the test methods to take a `testing.TB` param instead of a
`*testing.T` so that the test functions can be used for all the graph's
tests including benchmark tests.

We also add a temporary replace so that we can make use of these changes
and also since we will soon be adding graph related schemas and queries
in this submodule that we'll want to have access to.
2025-05-22 14:14:42 +02:00
9f5bf49ac7 sqldb/sqlite: enable incremental auto_vacuum on DB creation 2025-04-04 15:49:29 -07:00
4c4aeddeb0 sqldb: add unit test for the v0.19.0-rc1 migration bug 2025-03-28 11:00:58 +01:00
83d62308e9 sqldb: test schema migration idempotency 2025-03-28 11:00:57 +01:00
7e54682493 sqldb: fix dirty migration in v0.19.0-rc1 2025-03-28 11:00:57 +01:00
dae212697d sqldb: establish a base DB version even if it's not yet tracked
Previously, if a DB version wasn't available, we re-ran all schema
migrations without verifying the schema version. However, setting a
base schema version is essential because some earlier migrations were
not idempotent. This commit addresses the issue by using the current
schema version provided by sqlc as the base.
2025-03-28 11:00:57 +01:00