From e315f30728cbb1c259b27a943080f7c110366179 Mon Sep 17 00:00:00 2001 From: niftynei Date: Wed, 15 Feb 2023 16:21:44 -0600 Subject: [PATCH] db-fix: update NULL lease_satoshi fields to zero Missed a DEFAULT in the db clause. Feb 15 16:02:12 citrine lightningd[902093]: Accessing a null column lease_satoshi/15 in query SELECT funding_tx_id, funding_tx_outnum, funding_feerate, funding_satoshi, our_funding_satoshi, funding_psbt, last_tx, last_sig, funding_tx_remote_sigs_received, lease_expiry, lease_commit_sig, lease_chan_max_msat, lease_chan_max_ppt, lease_blockheight_start, lease_fee, lease_satoshi FROM channel_funding_inflights WHERE channel_id = ? ORDER BY funding_feerate Fixes #6016 --- wallet/db.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/wallet/db.c b/wallet/db.c index 5218a61323e1..5a5a1c78f1d9 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -67,6 +67,10 @@ static void migrate_payments_scids_as_integers(struct lightningd *ld, struct db *db, const struct migration_context *mc); +static void fillin_missing_lease_satoshi(struct lightningd *ld, + struct db *db, + const struct migration_context *mc); + /* Do not reorder or remove elements from this array, it is used to * migrate existing databases from a previous state, based on the * string indices */ @@ -948,6 +952,7 @@ static struct migration dbmigrations[] = { {SQL("ALTER TABLE channel_funding_inflights ADD COLUMN lease_satoshi BIGINT;"), NULL}, {SQL("ALTER TABLE channels ADD require_confirm_inputs_remote INTEGER DEFAULT 0;"), NULL}, {SQL("ALTER TABLE channels ADD require_confirm_inputs_local INTEGER DEFAULT 0;"), NULL}, + {NULL, fillin_missing_lease_satoshi}, }; /** @@ -1578,3 +1583,16 @@ static void migrate_payments_scids_as_integers(struct lightningd *ld, if (!db->config->delete_columns(db, "payments", colnames, ARRAY_SIZE(colnames))) db_fatal("Could not delete payments.failchannel"); } + +static void fillin_missing_lease_satoshi(struct lightningd *ld, + struct db *db, + const struct migration_context *mc) +{ + struct db_stmt *stmt; + + stmt = db_prepare_v2(db, SQL("UPDATE channel_funding_inflights" + " SET lease_satoshi = 0" + " WHERE lease_satoshi IS NULL;")); + db_exec_prepared_v2(stmt); + tal_free(stmt); +}