lightningd: explicit db arg to wait_index_increase so we can use it in migrations.
What changed, and why it matters
This is a small internal code cleanup change. It changes a helper function so callers can pass in a database connection directly, rather than always using the one inside the main lightningd object. The commit message says this is needed because during database migrations the main wallet database pointer is not yet set. There is no indication this fixes a security bug or is itself a vulnerability.
No security action required. Treat as normal code maintenance. If reviewing related migrations, verify the new db argument is non-NULL when used in early-boot contexts.
Security signals we found
No security-relevant keywords in commit title or message
No bug, CVE, vulnerability, or exploit references present
Change is a pure API refactor with no behavioral change to existing callers
No validation, authorization, cryptographic, or network changes
Commit message frames change as infrastructure for migrations, not as a fix
Evidence from the diff
The patch modifies wait_index_increase() to take an explicit struct db *db argument instead of dereferencing ld->wallet->db internally. The only existing caller in peer_htlcs.c is updated to pass ld->wallet->db. The stated purpose is to allow future use of wait_index_increase() during database migrations, before ld->wallet->db is initialized. This is a defensive refactor to avoid NULL pointer dereferences in future code paths, not a patch for a reported security issue.
Changed components
lightningd/wait.clightningd/wait.hlightningd/peer_htlcs.cInspect captured patch +6 / −2
diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c
index 27c3a475..da93db88 100644
--- a/lightningd/peer_htlcs.c
+++ b/lightningd/peer_htlcs.c
@@ -3059,7 +3059,8 @@ void htlcs_index_deleted(struct lightningd *ld,
const struct channel *channel,
u64 num_deleted)
{
- wait_index_increase(ld, WAIT_SUBSYSTEM_HTLCS, WAIT_INDEX_DELETED,
+ wait_index_increase(ld, ld->wallet->db,
+ WAIT_SUBSYSTEM_HTLCS, WAIT_INDEX_DELETED,
num_deleted,
"short_channel_id", fmt_short_channel_id(tmpctx, channel_scid_or_local_alias(channel)),
NULL);
diff --git a/lightningd/wait.c b/lightningd/wait.c
index 4d9066f6..a2b25297 100644
--- a/lightningd/wait.c
+++ b/lightningd/wait.c
@@ -189,6 +189,7 @@ u64 wait_index_increment(struct lightningd *ld,
}
void wait_index_increase(struct lightningd *ld,
+ struct db *db,
enum wait_subsystem subsystem,
enum wait_index index,
u64 num,
@@ -200,7 +201,7 @@ void wait_index_increase(struct lightningd *ld,
return;
va_start(ap, num);
- wait_index_bump(ld, ld->wallet->db, subsystem, index, num, ap);
+ wait_index_bump(ld, db, subsystem, index, num, ap);
va_end(ap);
}
diff --git a/lightningd/wait.h b/lightningd/wait.h
index d60abfe2..da71b6c2 100644
--- a/lightningd/wait.h
+++ b/lightningd/wait.h
@@ -57,6 +57,7 @@ u64 LAST_ARG_NULL wait_index_increment(struct lightningd *ld,
/**
* wait_index_increase - increase an index, tell waiters.
* @ld: the lightningd
+ * @db: the database (usually ld->wallet->db, except really early)
* @subsystem: subsystem for index
* @index: which index
* @num: number to add (if > 0).
@@ -65,6 +66,7 @@ u64 LAST_ARG_NULL wait_index_increment(struct lightningd *ld,
* A more generic version if wait_index_increment: if num is 0 it's a noop.
*/
void LAST_ARG_NULL wait_index_increase(struct lightningd *ld,
+ struct db *db,
enum wait_subsystem subsystem,
enum wait_index index,
u64 num,
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.