Don't allow downgrade if they've *used* the withheld column. */
| 18 | |
| 19 | /* Don't allow downgrade if they've *used* the withheld column. */ |
| 20 | static const char *revert_withheld_column(const tal_t *ctx, struct db *db) |
| 21 | { |
| 22 | struct db_stmt *stmt; |
| 23 | struct channel_id *cid; |
| 24 | struct short_channel_id *scid; |
| 25 | |
| 26 | stmt = db_prepare_v2(db, SQL("SELECT full_channel_id, scid FROM channels WHERE withheld != 0")); |
| 27 | db_query_prepared(stmt); |
| 28 | if (db_step(stmt)) { |
| 29 | cid = tal(tmpctx, struct channel_id); |
| 30 | db_col_channel_id(stmt, "full_channel_id", cid); |
| 31 | if (db_col_is_null(stmt, "scid")) |
| 32 | scid = NULL; |
| 33 | else { |
| 34 | scid = tal(tmpctx, struct short_channel_id); |
| 35 | *scid = db_col_short_channel_id(stmt, "scid"); |
| 36 | } |
| 37 | } else { |
| 38 | cid = NULL; |
| 39 | scid = NULL; |
| 40 | } |
| 41 | tal_free(stmt); |
| 42 | |
| 43 | if (cid) { |
| 44 | return tal_fmt(tmpctx, "Channel %s (%s) used v25.12's withheld flag", |
| 45 | fmt_channel_id(tmpctx, cid), |
| 46 | scid ? fmt_short_channel_id(tmpctx, *scid) : "no short channel id"); |
| 47 | } |
| 48 | |
| 49 | /* For sqlite3 needs "2021-03-12 (3.35.0)" or above */ |
| 50 | stmt = db_prepare_v2(db, SQL("ALTER TABLE channels DROP COLUMN withheld")); |
| 51 | db_exec_prepared_v2(take(stmt)); |
| 52 | return NULL; |
| 53 | } |
| 54 | |
| 55 | /* Do not reorder or remove elements from this array, it is used to |
| 56 | * migrate existing databases from a previous state, based on the |
nothing calls this directly
no test coverage detected