db: convert pre-Adelaide short_channel_ids.

We're about to remove them.

Includes fix to sqlite3_bind_short_channel_id to not assume `id` is a
tal object.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-09-06 16:10:22 +09:30 committed by Christian Decker
parent a134062f98
commit 91dcd1d55a
2 changed files with 10 additions and 2 deletions

View File

@ -18,7 +18,7 @@ struct migration {
void (*func)(struct lightningd *ld, struct db *db);
};
void migrate_pr2342_feerate_per_channel(struct lightningd *ld, struct db *db);
static void migrate_pr2342_feerate_per_channel(struct lightningd *ld, struct db *db);
/* Do not reorder or remove elements from this array, it is used to
* migrate existing databases from a previous state, based on the
@ -451,6 +451,12 @@ static struct migration dbmigrations[] = {
* in the list view anyway, e.g., show all close and htlc transactions
* as a single bundle. */
{SQL("ALTER TABLE transactions ADD channel_id INTEGER;"), NULL},
/* Convert pre-Adelaide short_channel_ids */
{SQL("UPDATE channels"
" SET short_channel_id = REPLACE(short_channel_id, ':', 'x')"
" WHERE short_channel_id IS NOT NULL;"), NULL },
{SQL("UPDATE payments SET failchannel = REPLACE(failchannel, ':', 'x')"
" WHERE failchannel IS NOT NULL;"), NULL },
};
/* Leak tracking. */
@ -825,7 +831,7 @@ void db_set_intvar(struct db *db, char *varname, s64 val)
}
/* Will apply the current config fee settings to all channels */
void migrate_pr2342_feerate_per_channel(struct lightningd *ld, struct db *db)
static void migrate_pr2342_feerate_per_channel(struct lightningd *ld, struct db *db)
{
struct db_stmt *stmt = db_prepare_v2(
db, SQL("UPDATE channels SET feerate_base = ?, feerate_ppm = ?;"));

View File

@ -133,6 +133,7 @@ static bool test_vars(struct lightningd *ld)
int main(void)
{
setup_locale();
setup_tmpctx();
bool ok = true;
/* Dummy for migration hooks */
@ -144,5 +145,6 @@ int main(void)
ok &= test_primitives();
tal_free(ld);
tal_free(tmpctx);
return !ok;
}