Skip to content

Commit 293a65b

Browse files
committed
wallet: handle null currency fields, skip & warn on mismatch.
If they ran off master, currency can be null: ``` 2025-08-21T10:03:04.566Z **BROKEN** lightningd: bookkeper migration: Accessing a null column e.currency/7 in query SELECT e.id, e.account_id, a.name, e.tag, e.credit, e.debit, e.fees, e.currency, e.payment_id, e.part_id, e.timestamp, e.ev_desc, e.rebalance_id FROM channel_events e LEFT OUTER JOIN accounts a ON a.id = e.account_id ORDER BY e.timestamp, e.id; ``` So allow this, but *also* check if it's a different currency and skip. This won't happen: you had to manually inject events in a different currency. Signed-off-by: Rusty Russell <[email protected]>
1 parent 6ef668e commit 293a65b

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

wallet/account_migration.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static struct chain_event *stmt2chain_event(const tal_t *ctx, struct db_stmt *st
105105
e->debit = db_col_amount_msat(stmt, "e.debit");
106106
e->output_value = db_col_amount_msat(stmt, "e.output_value");
107107

108-
e->currency = db_col_strdup(e, stmt, "e.currency");
108+
e->currency = db_col_strdup_optional(e, stmt, "e.currency");
109109
e->timestamp = db_col_u64(stmt, "e.timestamp");
110110
e->blockheight = db_col_int(stmt, "e.blockheight");
111111

@@ -270,7 +270,7 @@ static struct channel_event *stmt2channel_event(const tal_t *ctx, struct db_stmt
270270
e->debit = db_col_amount_msat(stmt, "e.debit");
271271
e->fees = db_col_amount_msat(stmt, "e.fees");
272272

273-
e->currency = db_col_strdup(e, stmt, "e.currency");
273+
e->currency = db_col_strdup_optional(e, stmt, "e.currency");
274274
if (!db_col_is_null(stmt, "e.payment_id")) {
275275
e->payment_id = tal(e, struct sha256);
276276
db_col_sha256(stmt, "e.payment_id", e->payment_id);
@@ -404,6 +404,16 @@ void migrate_from_account_db(struct lightningd *ld, struct db *db)
404404
struct amount_sat output_sat;
405405
u64 id;
406406

407+
/* We removed currency support, because the only way you could
408+
* use it was to inject your own events, and nobody did that
409+
* and it would be a nightmare to support */
410+
if (ev->currency
411+
&& !streq(ev->currency, chainparams->lightning_hrp)) {
412+
log_broken(ld->log, "IGNORING foreign currency chain event (%s, currency %s)",
413+
ev->tag, ev->currency);
414+
continue;
415+
}
416+
407417
stmt = db_prepare_v2(db,
408418
SQL("INSERT INTO chain_moves ("
409419
" id,"
@@ -483,6 +493,16 @@ void migrate_from_account_db(struct lightningd *ld, struct db *db)
483493
enum mvt_tag tag;
484494
u64 id;
485495

496+
/* We removed currency support, because the only way you could
497+
* use it was to inject your own events, and nobody did that
498+
* and it would be a nightmare to support */
499+
if (ev->currency
500+
&& !streq(ev->currency, chainparams->lightning_hrp)) {
501+
log_broken(ld->log, "IGNORING foreign currency channel event (%s, currency %s)",
502+
ev->tag, ev->currency);
503+
continue;
504+
}
505+
486506
stmt = db_prepare_v2(db,
487507
SQL("INSERT INTO channel_moves ("
488508
" id,"

0 commit comments

Comments
 (0)