Skip to content

Commit

Permalink
db-fix: update NULL lease_satoshi fields to zero
Browse files Browse the repository at this point in the history
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
  • Loading branch information
niftynei authored and endothermicdev committed Feb 16, 2023
1 parent 7079fb5 commit e315f30
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions wallet/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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},
};

/**
Expand Down Expand Up @@ -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);
}

0 comments on commit e315f30

Please sign in to comment.