Commit graph

2452 commits

Author SHA1 Message Date
Viktor Torstensson
aabf8b08e9
terminal: remove DevConfig.Validate params
As the `DevConfig.Validate` params are no longer used in the Validate
method, we can remove them from the method signature.
2026-06-08 11:23:58 +02:00
Viktor Torstensson
66e9d3c46d
terminal: move databasebackend option to Config
Move the database backend selection from the `dev` config file into the
main `Config` struct, i.e. into production.

This will enable an sql database backend to be used in production.
2026-06-08 11:23:58 +02:00
Viktor Torstensson
10949c7bb8
db: remove kvdb to sql migration from dev db stream
Remove the KVDB-to-SQL migration from the dev SQL migration set now
that this migration is now part of the production migration set.

As the migrations_dev folder no longer contains any migrations, we also
update the db logic and the gen_sqlc_docker.sh script to not error when
the folder(s) are empty.
2026-06-08 11:23:58 +02:00
Viktor Torstensson
85d0739019
db: move kvdb to SQL programmatic migration to prod
Move the programmatic KVDB-to-SQL migration out of the dev-only
migration stream and into the production SQL migration set.

This also requires that we add a new migration file for the prod
migration, which will trigger the kvdb to sql programmatic migration to
run in production.
2026-06-08 11:23:58 +02:00
Viktor Torstensson
3d8779693a
migsets: rename post migration callbacks mentions
With the latest version of the `sqldb/v2` & `migrate` packages, Post
Migration Callbacks were renamed to Programmatic Migrations.
Our previous codebase still had some mentions of Post Migration
Callbacks, and therefore we rename those to use the word Programmatic
Migrations instead.
2026-06-08 11:23:57 +02:00
Elle
e47348680f
Merge pull request #1257 from lightninglabs/dependabot/go_modules/perms/google.golang.org/grpc-1.79.3
build(deps): bump google.golang.org/grpc from 1.67.0 to 1.79.3 in /perms
2026-05-19 17:29:57 -07:00
Elle
5c78d4c96a
Merge pull request #1310 from ViktorT-11/2026-05-use-fillPlaceHolders-in-CountActions
[sql-73] use `fillPlaceHolders` in `CountActions`
2026-05-19 17:29:14 -07:00
Elle
4af5788819
Merge pull request #1309 from ViktorT-11/2026-05-add-master-additions-to-migration-code
[sql-72] Add `master` additions to migration code
2026-05-19 17:28:45 -07:00
Viktor Torstensson
36eb65c526
Merge pull request #1312 from ViktorT-11/2026-05-sql-migration-fixes
[sql-74] Handle empty VerificationIDs for sessions & normalize action timestamp handling to UTC
2026-05-19 11:54:47 +02:00
Viktor Torstensson
0f31fb594b
Merge pull request #1301 from ViktorT-11/2026-05-improve-migration-progress-logging
[sql-69] multi: improve kvdb migration progress logging
2026-05-19 11:54:05 +02:00
Viktor Torstensson
d9d5432a10
firewalldb: canonicalize action timestamps to UTC
Normalize action timestamp handling to UTC during KV and SQL
marshalling so migration validation behaves consistently on
Postgres backends outside UTC.

This also allows the action time comparison helper to use the
same timezone normalization approach as the other migration
paths.
2026-05-19 11:27:12 +02:00
Viktor Torstensson
7b3916596f
session: cover empty caveat verification ids
Add migration coverage for nested empty caveat verification IDs
and normalize the migrated SQL representation so empty byte
slices compare consistently with the KV store.
2026-05-19 11:27:12 +02:00
Viktor Torstensson
2f5de800c8
multi: improve kvdb migration progress logging
Add clearer progress logging across the KVDB to SQL migration paths
for accounts, sessions, and firewalldb.

Log the total number of items to migrate where it is cheap to
determine up front, and emit progress updates every 100 migrated
items.
2026-05-19 11:22:45 +02:00
Viktor Torstensson
ebd7ac39c6
Merge pull request #1308 from lightninglabs/sql-migration-base
[sql-71] Merge `sql-migration-base` into `master`
2026-05-19 10:54:52 +02:00
dependabot[bot]
49a6ccbee0
build(deps): bump google.golang.org/grpc from 1.67.0 to 1.79.3 in /perms
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.67.0 to 1.79.3.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.67.0...v1.79.3)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-version: 1.79.3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-05-16 00:29:03 +00:00
Elle
4ed4b03324
Merge pull request #1246 from lightninglabs/dependabot/go_modules/perms/github.com/docker/cli-29.2.0incompatible
build(deps): bump github.com/docker/cli from 28.1.1+incompatible to 29.2.0+incompatible in /perms
2026-05-15 17:26:53 -07:00
Elle
e984b531de
Merge pull request #1256 from lightninglabs/dependabot/go_modules/autopilotserverrpc/google.golang.org/grpc-1.79.3
build(deps): bump google.golang.org/grpc from 1.56.3 to 1.79.3 in /autopilotserverrpc
2026-05-15 17:26:09 -07:00
Elle
0117453dea
Merge pull request #1247 from lightninglabs/dependabot/go_modules/litrpc/github.com/docker/cli-29.2.0incompatible
build(deps): bump github.com/docker/cli from 28.1.1+incompatible to 29.2.0+incompatible in /litrpc
2026-05-15 17:25:48 -07:00
Elle
4541fe88e0
Merge pull request #1280 from lightninglabs/dependabot/go_modules/perms/go.opentelemetry.io/otel/sdk-1.43.0
build(deps): bump go.opentelemetry.io/otel/sdk from 1.40.0 to 1.43.0 in /perms
2026-05-15 17:25:21 -07:00
Viktor Torstensson
67804670c6
multi: use fillPlaceHolders in CountActions
This commits ensures that the `CountActions` function in the `sqlc` &
`sqlcmig6` packages utilizes the `fillPlaceHolders` function to properly
handle SQL query placeholders.

This ensures that the function works correctly on `Postgres` backends
when it contains ? placeholders instead of positional ones (e.g., $1).
2026-05-14 12:23:18 +02:00
Viktor Torstensson
6a29185689
sqlcmig6: add UpdateAccountLabel to sqlcmig6
Commit 24d7307a in `master` added a a new `UpdateAccountLabel` method to
the `Querier` interface. This commit also updates to `sqlcmig6` package
to support that query.
2026-05-14 12:04:17 +02:00
Viktor Torstensson
ddb750251e
accounts: update account mig to use 21933e8
commit 21933e8 in PR 1281 in master resolved the following issue:

"Get returns a byte slice that points directly into bbolt's
mmap'd file. This slice is only valid for the lifetime of the
transaction. In Account() and LastIndexes(), the slices were escaping
the View callback and being read after the transaction closed. Under
concurrent write transactions the file gets remapped, invalidating
the pointer and causing a segmentation fault.

Copy the byte slices inside the transaction so deserialization
operates on stable, heap-allocated memory."

This commit also updates the SQL migration to apply the same fix when
reading the Last Indexes.
2026-05-14 12:04:09 +02:00
Viktor Torstensson
003041271a
itest: add deprecated bbolt db coverage
Expand the kvdb -> SQL migration itest to cover the full post-migration
startup behavior, not just the initial data copy and SQL assertions.

Verify that bbolt startup is blocked once kvdb files are deprecated,
that deleting the SQL database reruns the migration successfully, and
that older litd binaries still fail to start against deprecated kvdb
files.

Also add ordered blocker checks for the deprecated kvdb files so the
test shows startup fails first on accounts.db, then session.db, and
finally rules.db as earlier files are removed.
2026-05-14 11:39:19 +02:00
Viktor Torstensson
d43d4446b8
itest: avoid blocking on failed litd exits
Close the process exit signal before forwarding litd startup errors from
the wait goroutine. This lets the harness observe that the process has
already exited even when no receiver is currently ready on the error
channel.

Use a non-blocking send for the captured process error so failed startup
paths do not hang the goroutine while holding back log finalization or
process exit handling.

This will be needed for the upcoming commit which adds itest coverage
of deprecated kvdb databases.
2026-05-14 11:39:17 +02:00
Viktor Torstensson
000d28a4fb
multi: deprecate kvdb stores after SQL migration
Mark the legacy kvdb stores as deprecated once the kvdb -> SQL
migration commits successfully. This prevents normal bbolt startup
from reopening accounts.db, session.db, or rules.db after their data
has already been migrated.

Add explicit deprecation checks to the three kvdb store open paths and
provide migration-only constructors that can still reopen deprecated
files when the SQL database is deleted or downgraded and the migration
must be rerun.

Use store-specific tombstones for the deprecation markers and add
tests that verify deprecated stores are rejected while migration
reruns continue to work.
2026-05-14 11:39:14 +02:00
Viktor Torstensson
c16ff48da6
migstreams: rename package to migsets 2026-05-14 11:39:12 +02:00
Viktor Torstensson
f78ddf1702
multi: rename MigrationStream names to MigrationSet 2026-05-14 11:39:09 +02:00
Viktor Torstensson
10337691cb
multi: use published sqldb/v2 dependency
Update the `sqldb/v2` dependency in go.mod to the published version, and
update the litd code to adhere to the new changes in the `sqldb/v2`
package.

Given that the official `sqldb/v2` package is now used, we can also
remove the `sqldb/v1` dependency from the go.mod file, as it is no
longer used in the codebase.
2026-05-14 11:39:07 +02:00
Viktor Torstensson
911c3bb5d1
docs: update benchmarking docs with firewalldb pkg 2026-05-14 11:39:04 +02:00
Viktor Torstensson
6fd5a6c053
firewalldb: add database backend benchmark test 2026-05-14 11:39:01 +02:00
Viktor Torstensson
66952a3d12
docs: update benchmarking docs with session pkg 2026-05-14 11:38:59 +02:00
Viktor Torstensson
d1743c3b29
session: add database backend benchmark test 2026-05-14 11:38:55 +02:00
Viktor Torstensson
1f25ea60a1
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-05-14 11:38:52 +02:00
Viktor Torstensson
08a1a7421f
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-05-14 11:38:50 +02:00
Viktor Torstensson
fb5b0af8d8
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-05-14 11:38:48 +02:00
Viktor Torstensson
067eeafd7e
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-05-14 11:38:45 +02:00
Viktor Torstensson
4271db936d
docs: add doc for benchmarking database backends 2026-05-14 11:38:42 +02:00
Viktor Torstensson
5898e35762
make: add make unit-bench command 2026-05-14 11:38:40 +02:00
Viktor Torstensson
fe28ff7e60
accounts: add database backend benchmark test 2026-05-14 11:38:37 +02:00
Viktor Torstensson
f90f468a32
multi: add dev kvdb to sql code migration
Add the necessary code to trigger the kvdb to sql code migration in dev
builds.
2026-05-14 11:38:35 +02:00
Viktor Torstensson
9c6464f7e4
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-05-14 11:38:32 +02:00
Viktor Torstensson
0c6b3c0539
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-05-14 11:38:30 +02:00
Viktor Torstensson
83f3e223fb
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-05-14 11:38:26 +02:00
Viktor Torstensson
f77ae5dcf2
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-05-14 11:38:24 +02:00
Viktor Torstensson
a5f727279f
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-05-14 11:38:21 +02:00
Viktor Torstensson
ff0eaa9774
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-05-14 11:38:18 +02:00
Viktor Torstensson
3c09dd6072
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-05-14 11:38:15 +02:00
Viktor Torstensson
0d7b07c0a4
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-05-14 11:38:11 +02:00
Viktor Torstensson
d8e6abac8b
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-05-14 11:38:08 +02:00
Viktor Torstensson
80dead031f
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-05-14 11:38:06 +02:00