diff --git a/lightningd/channel.c b/lightningd/channel.c index edc4b81f6..561af5222 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -173,7 +173,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid, const struct pubkey *local_funding_pubkey, const struct pubkey *future_per_commitment_point, u32 feerate_base, - u32 feerate_ppm) + u32 feerate_ppm, + const u8 *remote_upfront_shutdown_script) { struct channel *channel = tal(peer->ld, struct channel); @@ -240,6 +241,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid, = tal_steal(channel, future_per_commitment_point); channel->feerate_base = feerate_base; channel->feerate_ppm = feerate_ppm; + channel->remote_upfront_shutdown_script + = tal_steal(channel, remote_upfront_shutdown_script); list_add_tail(&peer->channels, &channel->list); tal_add_destructor(channel, destroy_channel); diff --git a/lightningd/channel.h b/lightningd/channel.h index a6938185c..6afd80a99 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -113,6 +113,9 @@ struct channel { /* Feerate per channel */ u32 feerate_base, feerate_ppm; + + /* If they used option_upfront_shutdown_script. */ + const u8 *remote_upfront_shutdown_script; }; struct channel *new_channel(struct peer *peer, u64 dbid, @@ -159,7 +162,9 @@ struct channel *new_channel(struct peer *peer, u64 dbid, const struct pubkey *local_funding_pubkey, const struct pubkey *future_per_commitment_point, u32 feerate_base, - u32 feerate_ppm); + u32 feerate_ppm, + /* NULL or stolen */ + const u8 *remote_upfront_shutdown_script); void delete_channel(struct channel *channel); diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 2368c472f..c7f3d9429 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -225,7 +225,8 @@ wallet_commit_channel(struct lightningd *ld, &uc->local_funding_pubkey, NULL, ld->config.fee_base, - ld->config.fee_per_satoshi); + ld->config.fee_per_satoshi, + NULL); /* Now we finally put it in the database. */ wallet_channel_insert(ld->wallet, channel); diff --git a/wallet/db.c b/wallet/db.c index 7a100a417..130a42d14 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -379,6 +379,7 @@ static struct migration dbmigrations[] = { { "ALTER TABLE channel_htlcs ADD received_time INTEGER", NULL }, { "ALTER TABLE forwarded_payments ADD received_time INTEGER", NULL }, { "ALTER TABLE forwarded_payments ADD resolved_time INTEGER", NULL }, + { "ALTER TABLE channels ADD remote_upfront_shutdown_script BLOB;", NULL }, }; /* Leak tracking. */ diff --git a/wallet/wallet.c b/wallet/wallet.c index 2739cab3d..93a148738 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -685,6 +685,7 @@ static struct channel *wallet_stmt2channel(const tal_t *ctx, struct wallet *w, s ok &= sqlite3_column_pubkey(stmt, 24, &channel_info.old_remote_per_commit); channel_info.feerate_per_kw[LOCAL] = sqlite3_column_int(stmt, 25); channel_info.feerate_per_kw[REMOTE] = sqlite3_column_int(stmt, 26); + wallet_channel_config_load(w, sqlite3_column_int64(stmt, 4), &channel_info.their_config); @@ -738,8 +739,8 @@ static struct channel *wallet_stmt2channel(const tal_t *ctx, struct wallet *w, s &local_basepoints, &local_funding_pubkey, future_per_commitment_point, sqlite3_column_int(stmt, 42), - sqlite3_column_int(stmt, 43)); - + sqlite3_column_int(stmt, 43), + sqlite3_column_arr(tmpctx, stmt, 44, u8)); return chan; } @@ -764,7 +765,7 @@ static const char *channel_fields = /*36*/ "min_possible_feerate, max_possible_feerate, " /*38*/ "msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, " /*41*/ "last_sent_commit, " - /*42*/ "feerate_base, feerate_ppm"; + /*42*/ "feerate_base, feerate_ppm, remote_upfront_shutdown_script"; bool wallet_channels_load_active(const tal_t *ctx, struct wallet *w) { @@ -984,7 +985,8 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) " msatoshi_to_us_min=?," " msatoshi_to_us_max=?," " feerate_base=?," - " feerate_ppm=?" + " feerate_ppm=?," + " remote_upfront_shutdown_script=?" " WHERE id=?"); sqlite3_bind_int64(stmt, 1, chan->their_shachain.id); if (chan->scid) @@ -1026,7 +1028,13 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) sqlite3_bind_amount_msat(stmt, 25, chan->msat_to_us_max); sqlite3_bind_int(stmt, 26, chan->feerate_base); sqlite3_bind_int(stmt, 27, chan->feerate_ppm); - sqlite3_bind_int64(stmt, 28, chan->dbid); + if (chan->remote_upfront_shutdown_script) + sqlite3_bind_blob(stmt, 28, chan->remote_upfront_shutdown_script, + tal_count(chan->remote_upfront_shutdown_script), + SQLITE_TRANSIENT); + else + sqlite3_bind_null(stmt, 28); + sqlite3_bind_int64(stmt, 29, chan->dbid); db_exec_prepared(w->db, stmt); wallet_channel_config_save(w, &chan->channel_info.their_config);