Commit graph

2336 commits

Author SHA1 Message Date
Viktor Torstensson
472b71b665
Merge pull request #1234 from ViktorT-11/2026-02-add-firewalldb-benchmarking
[sql-64] firewalldb: add database benchmarking for firewalldb package
2026-03-09 17:38:39 +01:00
Viktor Torstensson
97260eebf8
docs: update benchmarking docs with firewalldb pkg 2026-03-09 10:23:02 +01:00
Viktor Torstensson
445313dfb8
firewalldb: add database backend benchmark test 2026-03-09 10:22:57 +01:00
Viktor Torstensson
6b58a828eb
Merge pull request #1233 from ViktorT-11/2026-02-add-session-benchmarking
[sql-63] session: add database benchmarking for session package
2026-03-09 10:19:06 +01:00
Viktor Torstensson
8179b857a9
Merge pull request #1238 from ViktorT-11/2026-02-improve-list_accounts-sql-performance
[sql-65] multi: improve `ListAccounts` performance for SQL database backends
2026-03-05 14:57:45 +01:00
Viktor Torstensson
7090fece49
accounts: add TestAccountStoreAccountsGrouping
Add a store test that verifies that Accounts groups invoices and
payments by account ID and does not leak linked data across accounts
when using the store.Accounts function.
2026-03-05 14:18:07 +01:00
Viktor Torstensson
2780d40223
sqlcmig6: add new queries to the sqlcmig6 package
Add the ListAllAccountInvoices & ListAllAccountPayments queries to the
sqlcmig6 package, to mimic the sqlc queries present before the kvdb to
sql migration is added to prod.
2026-03-05 14:18:07 +01:00
Viktor Torstensson
93b9dec9b1
accounts+sqlc: improve ListAccounts for SQL store
Optimize SQL account listing by preloading linked invoices and payments
for all accounts in bulk.

Before this change, Accounts() queried ListAllAccounts and then did two
extra queries per account (ListAccountInvoices/ListAccountPayments),
which scales poorly as account count grows.

Add ListAllAccountInvoices and ListAllAccountPayments queries, group
their rows by account_id in memory, and marshal each account from the
preloaded data. Keep conversion logic shared through
marshalDBAccountWithLinkedData to preserve behavior between
single-account and list-account paths.

This reduces query count from 1 + 2N to 3 and improves list-path
performance without changing external semantics.
2026-03-05 14:18:07 +01:00
Viktor Torstensson
e2ef65d32d
docs: update benchmarking docs with session pkg 2026-03-05 13:04:16 +01:00
Viktor Torstensson
bebe33b4ee
session: add database backend benchmark test 2026-03-05 13:04:16 +01:00
Viktor Torstensson
b8f6ad1ec2
Merge pull request #1243 from ViktorT-11/2026-02-cleanup-migration-itests
itest: add kvdb -> SQL migration test
2026-03-04 16:40:14 +01:00
Viktor Torstensson
1222951d5c
itest: add kvdb -> SQL migration test
This commit implements an itest kvdb -> SQL migration itest. The
intention of the itest is to verify that the kvdb -> SQL migration flow
works for a litd node which has data inserted to the bbolt database.
To verify that, the minimum amount of data required to trigger the full
migration flow is inserted into the bbolt database, which is one object
to each database file. Those objects are:
* One account - accounts.DB file
* One session - session.db file
* One action - rules.db file

As the respective unit tests for each migration extensively tests that
data of all forms for each database file can successfully be migrated,
the itest only focuses on testing that the full migration flow works,
and leaves the responsibility of data variation coverage to the
respective unit test.

The test is executed in different steps, and uses RPCs to seed and
validate migration fixtures:
1. Start a node with a bbolt backend.
2. Insert one account, one session and one action via RPC.
3. Snapshot the inserted objects via RPC.
4. Restart with the configured SQL backend to trigger migration.
5. Query objects again via RPC.
6. Compare the new objects to the pre-migration snapshot.
7. Assert the migrated objects in SQL via direct queries, to verify that
it's actually the SQL database that contains the migrated objects.
2026-03-04 16:10:28 +01:00
Viktor Torstensson
80615c2a90
Merge pull request #1227 from ViktorT-11/2026-02-add-accounts-benchmarking
[sql-62] multi: add database benchmarking for `accounts` package
2026-02-25 19:48:59 +01:00
Viktor Torstensson
54c6186998
docs: add doc for benchmarking database backends 2026-02-19 11:48:35 +01:00
Viktor Torstensson
f4dc9b623e
make: add make unit-bench command 2026-02-19 11:43:27 +01:00
Viktor Torstensson
420aaf0dc1
accounts: add database backend benchmark test 2026-02-19 11:43:27 +01:00
Viktor Torstensson
28629dfab2
Merge pull request #1114 from ViktorT-11/origin/2025-07-trigger-kvdb-to-sql-migrations-in-dev-builds
[sql-46] trigger kvdb to sql migration using `sqldb/v2`
2026-02-18 13:30:46 +01:00
Viktor Tigerström
7bba957c8b
multi: add dev kvdb to sql code migration
Add the necessary code to trigger the kvdb to sql code migration in dev
builds.
2026-02-18 12:07:15 +01:00
Viktor Tigerström
42dae22f26
accounts: export kvdb DB
The next commit that adds the kvdb to sql code migration will need to
initialize the accounts kvdb DB.

This commit exports that struct so that it can be referenced outside of
the accounts package.
2026-02-17 13:29:18 +01:00
Viktor Tigerström
4efa6098f8
multi: introduce dev migrations
When the kvdb to sql migration is initially introduced, we will want to
ensure that it is only run under dev builds during the testing phase.

We therefore introduce the functionality to have separate dev
migrations, which are only included in a separate migration stream that
is used only in dev builds.

Note that these dev migrations are currently not included in the
`sqlc.yaml` file, to ensure that the main sqlc models doesn't include
the dev migrations.
2026-02-17 13:25:03 +01:00
Viktor Tigerström
0d96fd8dad
migstreams: introduce migstreams package
The upcoming kvdb to sql code migration will be added to as part of the
`sqldb/v2` migration stream. However, since the kvdb to sql migration
will need to use the migration functions present in the `accounts`,
`firewalldb`, and `session` packages, the migration will need to
referernce those packages. That would lead to a circular dependency
though if the migration stream was defined in the `db` package, as those
packages need to import the `db` package.

To avoid this, we introduce a new `migstreams` package that
contains the migration streams, and ensure that the `db` package doesn't
import the `migstreams` package.
2026-02-17 13:24:41 +01:00
Viktor Tigerström
08b91b09ef
multi: introduce migration stream for unit tests
In upcoming commits, we will introduce a new migration stream package
that will need to reference the db package, as well as the accounts,
session and firewalldb package in future commits. To avoid circular
dependencies, we therefore introduce a new migration stream that unit
tests can use, in order to avoid having to import the new migration
stream package.
2026-02-16 10:28:57 +01:00
Viktor Tigerström
f995f9cb44
db: export the embed.FS SqlSchemas
In upcoming commits, other packages than the `db` package will need to
be able to access the `SqlSchemas`. This commit exports it in
preparation for those changes
2026-02-13 20:24:24 +01:00
Viktor Torstensson
dafd47de64
Merge pull request #1113 from ViktorT-11/2025-07-sqldb-v2-mig6-package
[sql-45] package queries & models present at the time of the kvdb to sql migration
2026-02-13 20:19:59 +01:00
Viktor Torstensson
c53dcb414e
sqlc: remove UpdateAccountAliasForTests query
As no code path uses the sqlc.UpdateAccountAliasForTests query, now that
migrations tests have been updated to use the sqlcmig6 version, we can
remove the query from the sqlc package. As this query is only intended
to be used for testing, it is beneficial to not expose it to the rest of
the codebase to avoid accidental usage in the future.
2026-02-13 19:37:31 +01:00
Viktor Tigerström
f1be7c4335
firewalldb: refactor execution of mig test assert
Since the `assertMigrationResults` now expects a `*sqlcmig6.Queries`
instance to be passed directly into the function, there is no need to
create a separate *sqlcmig6.Queries instance than the one created when
the `*sqlcmig6.TxExecutor` transaction is created. We therefore
refactor the execution of the `assertMigrationResults` function to be
called in the scope of that transaction.

Due to this change, there's also no longer a need to return the `*SQLDB`
instance from the `makeSQLDB` helper function.
2026-02-13 19:37:31 +01:00
Viktor Tigerström
4ca77b4e2d
firewalldb: use sqlcmig6 for kvdb to sql migration
This commit updates the firewalldb package to use the new `sqlcmig6`
package for kvdb to SQL migration.
2026-02-13 19:37:31 +01:00
Viktor Tigerström
6baf7cbf49
firewalldb: use queries to assert migration results
As the firewalldb package kvdb to sql migration tests creates `sqlc`
models to assert the migration results, we will need to update those
call sites to instead use the `sqlcmig6` models instead, in order to
be compatible with the `sqlcmig6.Queries` queries.

However, since we can't update the `SQLDB` methods to use `sqlcmig6`
models as params, we need to update the test code assertion to instead
use the `sqlc.Queries` object directly instead of the `SQLDB` object.
This makes it easy to swap that `sqlc.Queries` object to a
`sqlcmig6.Queries` object in the commit that updates the firewalldb
package to use the `sqlcmig6` package for the kvdb to sql migration.
2026-02-13 19:37:30 +01:00
Viktor Tigerström
787c80cd02
session: use sqlcmig6 for kvdb to sql migration
This commit updates the session package to use the new `sqlcmig6`
package for kvdb to SQL migration.
2026-02-13 19:37:30 +01:00
Viktor Tigerström
990dcdb709
accounts: use sqlcmig6 for kvdb to sql migration
This commit updates the accounts package to use the new `sqlcmig6`
package for kvdb to SQL migration.
2026-02-13 19:37:30 +01:00
Viktor Tigerström
9bdcdb5bd2
sqlcmig6: add transaction executor for Queries
This commit adds a helper struct that creates a `sqldb/v2` transaction
executor that wraps the `sqlcmig6.Queries` type.
2026-02-13 19:37:29 +01:00
Viktor Tigerström
4f3975fc5e
sqlcmig6: add CustomQueries to Queries
In order to be able to use the custom queries with the
`sqlcmig6.Queries`, we assert at compile time that `sqlcmig6.Queries`
implements the `CustomQueries` interface.
2026-02-13 19:37:29 +01:00
Viktor Tigerström
21be674552
sqlcmig6: add sqlcmig6 package
This commit introduces the `sqlcmig6` package, which at the time of this
commit contains the same queries and models as `sqlc` package.
Importantly though, once the kvdb to sql migration is made available in
production, the `sqlcmig6` package will not change, as it is intended
to represent the sql db as it was at the time of the migration.

The sqlcmig6 package is therefore intended to be used in the kvdb to sql
migration code, as it is will always be compatible with the sql database
when all sql migrations prior to the kvdb to sql migration are applied.

When additional sql migrations are added in the future, they may effect
the `sqlc` package in such a way that the standard `sqlc` queries and
models aren't compatible with kvdb to sql migration code any longer.

By preserving the `sqlcmig6` package, we ensure that the kvdb to sql
migration code can always use the same queries and models that were
available at the time of the migration, even if the `sqlc` package
changes in the future.

Note that the `sqlcmig6` package have not been generated by `sqlc` (the
queries and models are copied from the `sqlc` package), as it is not
intended to be changed in the future.
2026-02-13 19:37:29 +01:00
Viktor Torstensson
61297e7493
Merge pull request #1085 from ViktorT-11/2025-05-sqldb-v2
[sql-43] Add support for `sqldb/v2` in litd
2026-02-06 21:01:24 +01:00
Viktor Tigerström
f525a7f49d
mutli: rename db.NewTestPostgresV2DB function
As the legacy `NewTestPostgresDB` function is no longer used and has
been removed, it no longer makes sense to have a `V2` suffix on the
`NewTestPostgresV2DB` function. This commit renames it to
`NewTestPostgresDB`, to indicate that this function now replaces the
legacy function.
2026-02-06 20:14:35 +01:00
Viktor Tigerström
f68652d26e
multi: remove unused db code
As we've now switched over to using sqldb v2 for most of the db objects,
we can remove a lot of deprecated code that's no longer used in the litd
project. This commit removes that code.
2026-02-06 20:14:35 +01:00
Viktor Torstensson
6d350d6270
firewalldb: use sqldb/v2 in firewalldb package
Update the firewalldb package to use the `sqldb/v2` package instead of
the older version.
2026-02-06 20:14:35 +01:00
Viktor Tigerström
d743bf27ff
firewalldb: rename sqlStore to store in mig test
rename `sqlStore` to `store` in the firewalldb sql migration test file,
to make the name shorted. This is done in preparation for future commits
which will lengthen the lines where `sqlStore` is used, which otherwise
would make the lines exceed the 80 character limit.
2026-02-06 20:14:35 +01:00
Viktor Tigerström
bf07779ac6
firewalldb: add ListAllKVStoresRecords to queries
Previous commits had forgotten to add the `ListAllKVStoresRecords` query
to the `firewalldb.SQLKVStoreQueries` interface. As that is required to
make the query useable when defining the `sqldb/v2`
`TransactionExecutor` for the `firewalldb` package, this commit
adds it to the interface.
2026-02-06 20:14:34 +01:00
Viktor Tigerström
265ce94be1
multi: use sqldb/v2 in session package
Update the session package to use the `sqldb/v2` package instead of the
older version.
2026-02-06 20:14:34 +01:00
Viktor Tigerström
062d5343cb
multi: use sqldb/v2 in accounts package
Update the accounts package to use the `sqldb/v2` package instead of the
older version.
2026-02-06 20:14:34 +01:00
Viktor Tigerström
6d5a537baf
db: add sqldb/v2 PostgresStore creation helper
As we will change the `accounts`, `session` & `firewalldb` packages to
use the `sqldb/v2` package, we need to make those packages use the
`sqldb/v2` `PostgresStore` when setting up their test postgres
databases, instead of `litd`'s own `PostgresStore` version.

In order to enable that functionality, we add a new helper function that
creates a `PostgresStore` using the `sqldb/v2` package, in addition to
helper function that creates a `PostgresStore` using the `litd`
version.

Once we have shifted all of `litd`'s code to use the `sqldb/v2`
definition, we will remove the `litd` version.
2026-02-06 20:14:34 +01:00
Viktor Tigerström
d2eb60658f
sqlc: introduce NewForType helper method
The upcoming implementation of `sqldb/v2` will extensively create
a `Queries` object on the fly. To make more intuitive how to create
the queries object for specific database types, we introduce a
`NewForType` helper method.
This also mimics how `tapd` creates the `Queries` object, and in order
not let `litd` have it's own definition of how `Queries` object are
created on the fly, the upcoming `sqldb/v2` usage will utilize this
helper method.
2026-02-06 20:14:34 +01:00
Viktor Tigerström
c5e068e0cc
db+sqlc: use sqldb/v2 BackendType definition
The `sqldb/v2` package now provides a definition for the `BackendType`
type. As useage of `sqldb/v2` requires useage of that type, we update
`litd` to use the `BackendType` definition from `sqldb/v2`, instead of
it's own definition.
2026-02-06 20:14:34 +01:00
Viktor Tigerström
436ba9d750
db: add LitdMigrationStream
A core component of `sqldb/v2` useage, is that the package allows and
requires that the callsite defines a `sqldb.MigrationStream` that will
be run during the initialization of the `sqldb/v2 database instance.
The `sqldb.MigrationStream` defines the exact sql migrations to run,
as well as additional code migrations will be run after each individual
migration version.

This commit introduces the core definition of the migration stream for
`litd`, and will be further exteded in upcoming commits that will
introduce kvdb to sql code migration.

Note that as of this commit, as no part of the `litd` codebase uses the
`sqldb/v2` database instances, this migration stream is not yet
used.
2026-02-06 20:14:34 +01:00
Viktor Tigerström
8195106e5a
mod: add sqldb/v2 dependency to litd
In upcoming commits, we will introduce support for sqldb/v2 in Lightning
Terminal, in order to support code migrations. This is needed, so that
we can ensure that the kvdb to sql migration is run exactly after an
exact sql migration version, and not after all sql migrations have been
executed. The reason why that's important is that sql table definition
may change with future sql migrations, while the kvdb to sql migration
will remain the same and always expect the same table definition.
Therefore, if the kvdb to sql migration is run after all sql migrations,
it may fail due to a table definition mismatch.

This commit adds the sqldb/v2 dependency to `litd`, so that we can
implement it's usage and execution of the kvdb to sql migration
correctly in the upcoming commits.

NOTE: currently the sqldb/v2 dependency hasn't been shipped in any
lnd release, so this dependency currently a forked version of
sqldb/v2.
2026-02-06 20:11:08 +01:00
Viktor Torstensson
e5a9bdad7e
build: bump migrate dependency & taproot-assets
In the upcoming commits, we'll updating litd to use the new sqldb/v2
package. In order for the migrations run by the sqldb/v2 package to
work correctly, we need to bump the `migrate` dependency to the latest
version.
When doing so, we also need to bump taproot-assets to a version which
uses that migrate dependency version, which currently only the `main`
branch on taproot-assets does.

As the /universerpc.Universe/Info call now requires a macaroon, we
need to add the `taproot-assets.allow-public-uni-proof-courier` to the
node config in order to whitelist the call.
2026-02-06 20:11:02 +01:00
Viktor Torstensson
6321194038
Merge pull request #1224 from ZZiigguurraatt/bump-go-1.24.11
build: bump go to v1.24.11
2026-02-05 14:47:34 +01:00
ZZiigguurraatt
432a228bd6 build: bump go to v1.24.11 2026-02-05 02:57:05 -05:00
Elle
79ae6e26ad
Merge pull request #1223 from ViktorT-11/2026-02-claude-forked-repo-fix
workflows/claude: fix PR checkout for fork PRs
2026-02-03 15:34:59 +02:00