Commit graph

5 commits

Author SHA1 Message Date
Sangbida Chaudhuri
dbbd757972 lightningd: add watchman storage and persistence skeleton
Introduce the minimal storage scaffolding for the watchman module:

- db_set_blobvar / db_get_blobvar helpers for persisting binary
  values (e.g. block hashes) in the SQL `vars` table.
- load_tip(): recover last_processed_height and last_processed_hash
  from the wallet db.
- apply_rescan(): honour --rescan by adjusting the loaded tip
  downward (negative = absolute height, positive = N blocks back).
- watchman_new(): allocate the struct, initialise the pending-op
  array, and call load_tip + apply_rescan.

Wire the watchman field into struct lightningd via a forward
declaration; instantiation at startup lands in a later commit
along with the rest of the wiring.
2026-06-11 00:31:54 +10:00
Rusty Russell
bfbee055ea db: don't start transactions unless we really need to.
We always start a transaction before processing, but there are cases where
we don't need to.  Switch to doing it on-demand.

This doesn't make a big difference for sqlite3, but it can for Postgres because
of the latency: 12% or so.  Every bit helps!

30 runs, min-max(mean+/-stddev):

	Postgres before:  8.842773-9.769030(9.19531+/-0.21)
	Postgres after: 8.007967-8.321856(8.14172+/-0.066)

	sqlite3 before: 7.486042-8.371831(8.15544+/-0.19)
	sqlite3 after: 7.973411-8.576135(8.3025+/-0.12)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-11-20 16:30:50 +10:30
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
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
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