From b093856d0c13070c116cd2e4b8bb423cdc8a12a0 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 14 Aug 2020 03:10:02 +0930 Subject: [PATCH] db: add option_anchor_outputs entry to channel table. This is the same way we handle option_static_remotekey, which is also sticky (if negotiated at opening time, it always applies). Signed-off-by: Rusty Russell --- wallet/db.c | 3 +++ wallet/wallet.c | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/wallet/db.c b/wallet/db.c index c04640b8e..893ea75b9 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -633,6 +633,9 @@ static struct migration dbmigrations[] = { {NULL, migrate_last_tx_to_psbt}, {SQL("ALTER TABLE outputs ADD reserved_til INTEGER DEFAULT NULL;"), NULL}, {NULL, fillin_missing_scriptpubkeys}, + /* option_anchor_outputs is nailed at creation time. */ + {SQL("ALTER TABLE channels ADD COLUMN option_anchor_outputs INTEGER" + " DEFAULT 0;"), NULL }, }; /* Leak tracking. */ diff --git a/wallet/wallet.c b/wallet/wallet.c index b2f2826a6..7578715dc 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1161,7 +1161,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm ok &= wallet_shachain_load(w, db_column_u64(stmt, 28), &wshachain); remote_shutdown_scriptpubkey = db_column_arr(tmpctx, stmt, 29, u8); - local_shutdown_scriptpubkey = db_column_arr(tmpctx, stmt, 47, u8); + local_shutdown_scriptpubkey = db_column_arr(tmpctx, stmt, 48, u8); /* Do we have a last_sent_commit, if yes, populate */ if (!db_column_is_null(stmt, 42)) { @@ -1356,6 +1356,7 @@ static bool wallet_channels_load_active(struct wallet *w) ", feerate_ppm" ", remote_upfront_shutdown_script" ", option_static_remotekey" + ", option_anchor_outputs" ", shutdown_scriptpubkey_local" " FROM channels WHERE state < ?;")); db_bind_int(stmt, 0, CLOSED); @@ -1621,6 +1622,7 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) " feerate_ppm=?," " remote_upfront_shutdown_script=?," " option_static_remotekey=?," + " option_anchor_outputs=?," " shutdown_scriptpubkey_local=?" " WHERE id=?")); db_bind_u64(stmt, 0, chan->their_shachain.id); @@ -1671,9 +1673,11 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) db_bind_null(stmt, 28); db_bind_int(stmt, 29, chan->option_static_remotekey); - db_bind_blob(stmt, 30, chan->shutdown_scriptpubkey[LOCAL], + /* FIXME: option_anchor_outputs */ + db_bind_int(stmt, 30, false); + db_bind_blob(stmt, 31, chan->shutdown_scriptpubkey[LOCAL], tal_count(chan->shutdown_scriptpubkey[LOCAL])); - db_bind_u64(stmt, 31, chan->dbid); + db_bind_u64(stmt, 32, chan->dbid); db_exec_prepared_v2(take(stmt)); wallet_channel_config_save(w, &chan->channel_info.their_config);