Commit Graph

11 Commits

Author SHA1 Message Date
Rusty Russell 95f20a3978 lightningd, pyln-testing: do extra checks to make sure check *cannot* write to db.
Put an assertion inside db.c, and run every command we do (in testing) through
a `check` variant.

I inserted a deliberate bug (made addpsbtoutput call wallet_get_newindex()
before returning when running `check`, and indeed, backtrace as expected.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-26 12:59:55 +10:30
Rusty Russell 0bcff1e76d db/bindings: now bindings are always in order, remove index.
Simply always bind the next one.  No arithmetic required now!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-18 14:24:01 +09:30
Rusty Russell eee40615e2 wallet/invoices.c: use BIND_NEXT
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-18 14:24:01 +09:30
Rusty Russell 04f485aee0 db: add generic warn/error function.
This avoids the mess where we override db_fatal for teqsts, and keeps it
generic.

Also allows us to get rid of one #if DEVELOPER, and an ugly global for
bookkeeper.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-09 16:49:48 +09:30
Rusty Russell eee3965d02 db: db_set_intvar/db_get_var should take a const char *.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-06 09:50:32 +09:30
Rusty Russell df9552bcc1 db: make db_exec_prepared_v2 return void.
It calls db_fatal() if it fails anyway, so don't expect anyone to check.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-06 09:50:32 +09:30
Rusty Russell 9bcf28afb3 db: catch SQL errors unless we're expecting them.
I couldn't figure out why my new SQL query was returning 0 rows,
and it was because we were ignoring errors.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-06 09:50:32 +09:30
Alex Myers a9eb17adf9 db: catch postgres error on uninitialized database
Avoids the following when postgres returns no query result:
==63458== Conditional jump or move depends on uninitialised value(s)
==63458==    at 0x226A1F: db_postgres_step (db_postgres.c:156)
==63458==    by 0x22535B: db_step (utils.c:155)
==63458==    by 0x1E089A: db_data_version_get (exec.c:49)
==63458==    by 0x194F6F: db_setup (db.c:1029)
==63458==    by 0x199A2F: wallet_new (wallet.c:101)
==63458==    by 0x154B70: main (lightningd.c:1035)

Changelog-None
2023-01-31 10:25:25 +10:30
Rusty Russell d7aa2749c3 db: fix migrations which write to db.
valgrind noticed that this was uninitialized when I tried a complex
migration.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-09-12 14:00:41 +02:00
Vincenzo Palazzo 6a146bed26 db: small code cleanup
Changelog-None: db: small code cleanup

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-03-11 16:43:15 +10:30
niftynei ce12d2b8a9 database: pull out database code into a new module
We're going to reuse the database controllers for the accounting plugin
2022-03-05 15:03:34 +10:30