cln/db/exec.h
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

66 lines
1.8 KiB
C

#ifndef LIGHTNING_DB_EXEC_H
#define LIGHTNING_DB_EXEC_H
#include "config.h"
#include <ccan/short_types/short_types.h>
#include <ccan/take/take.h>
#include <ccan/tal/tal.h>
struct db;
/**
* db_set_intvar - Set an integer variable in the database
*
* Utility function to store generic integer values in the
* database.
*/
void db_set_intvar(struct db *db, const char *varname, s64 val);
/**
* db_get_intvar - Retrieve an integer variable from the database
*
* Either returns the value in the database, or @defval if
* the query failed or no such variable exists.
*/
s64 db_get_intvar(struct db *db, const char *varname, s64 defval);
void db_set_blobvar(struct db *db, const char *varname, const u8 *val, size_t len);
/* Returns a tal-allocated blob, or NULL if not found. */
const u8 *db_get_blobvar(const tal_t *ctx, struct db *db, const char *varname);
/* Get the current data version (entries). */
u32 db_data_version_get(struct db *db);
/* Get the current database version (migrations). */
int db_get_version(struct db *db);
/**
* db_begin_transaction - Begin a transaction
*
* Begin a new DB transaction. fatal() on database error.
*/
#define db_begin_transaction(db) \
db_begin_transaction_((db), __FILE__ ":" stringify(__LINE__))
void db_begin_transaction_(struct db *db, const char *location);
bool db_in_transaction(struct db *db);
/**
* db_need_transaction: we now need to actually enable the transaction, if not
* already. */
void db_need_transaction(struct db *db, const char *location);
/**
* db_commit_transaction - Commit a running transaction
*
* Requires that we are currently in a transaction. fatal() if we
* fail to commit.
*/
void db_commit_transaction(struct db *db);
/**
* db_set_readonly - make writes fatal or allowed.
*/
void db_set_readonly(struct db *db, bool readonly);
#endif /* LIGHTNING_DB_EXEC_H */