From 11ee089d4bfba311a00371702ae575128601e544 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 10 Sep 2019 11:52:27 +0930 Subject: [PATCH] db: store option_static_remotekey for each channel. Signed-off-by: Rusty Russell --- lightningd/channel.c | 4 +++- lightningd/channel.h | 6 +++++- lightningd/opening_control.c | 3 ++- wallet/db.c | 3 +++ wallet/wallet.c | 10 +++++++--- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lightningd/channel.c b/lightningd/channel.c index 98202459e..34c87779c 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -177,7 +177,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid, const struct pubkey *future_per_commitment_point, u32 feerate_base, u32 feerate_ppm, - const u8 *remote_upfront_shutdown_script) + const u8 *remote_upfront_shutdown_script, + bool option_static_remotekey) { struct channel *channel = tal(peer->ld, struct channel); @@ -248,6 +249,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid, channel->feerate_ppm = feerate_ppm; channel->remote_upfront_shutdown_script = tal_steal(channel, remote_upfront_shutdown_script); + channel->option_static_remotekey = option_static_remotekey; list_add_tail(&peer->channels, &channel->list); tal_add_destructor(channel, destroy_channel); diff --git a/lightningd/channel.h b/lightningd/channel.h index bb78abff3..f1dc8f6b7 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -117,6 +117,9 @@ struct channel { /* If they used option_upfront_shutdown_script. */ const u8 *remote_upfront_shutdown_script; + + /* Was this negotiated with `option_static_remotekey? */ + bool option_static_remotekey; }; struct channel *new_channel(struct peer *peer, u64 dbid, @@ -165,7 +168,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid, u32 feerate_base, u32 feerate_ppm, /* NULL or stolen */ - const u8 *remote_upfront_shutdown_script); + const u8 *remote_upfront_shutdown_script, + bool option_static_remotekey); void delete_channel(struct channel *channel); diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index ba59b2bac..34c3dd3e6 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -237,7 +237,8 @@ wallet_commit_channel(struct lightningd *ld, NULL, ld->config.fee_base, ld->config.fee_per_satoshi, - remote_upfront_shutdown_script); + remote_upfront_shutdown_script, + false); /* 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 dc4b9cd04..2e741ab1f 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -457,6 +457,9 @@ static struct migration dbmigrations[] = { " WHERE short_channel_id IS NOT NULL;"), NULL }, {SQL("UPDATE payments SET failchannel = REPLACE(failchannel, ':', 'x')" " WHERE failchannel IS NOT NULL;"), NULL }, + /* option_static_remotekey is nailed at creation time. */ + {SQL("ALTER TABLE channels ADD COLUMN option_static_remotekey" + " DEFAULT FALSE;"), NULL }, }; /* Leak tracking. */ diff --git a/wallet/wallet.c b/wallet/wallet.c index d775c9f61..855f121f3 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -909,7 +909,8 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm future_per_commitment_point, db_column_int(stmt, 42), db_column_int(stmt, 43), - db_column_arr(tmpctx, stmt, 44, u8)); + db_column_arr(tmpctx, stmt, 44, u8), + db_column_int(stmt, 45)); return chan; } @@ -980,6 +981,7 @@ static bool wallet_channels_load_active(struct wallet *w) ", feerate_base" ", feerate_ppm" ", remote_upfront_shutdown_script" + ", option_static_remotekey" " FROM channels WHERE state < ?;")); db_bind_int(stmt, 0, CLOSED); db_query_prepared(stmt); @@ -1241,7 +1243,8 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) " msatoshi_to_us_max=?," " feerate_base=?," " feerate_ppm=?," - " remote_upfront_shutdown_script=?" + " remote_upfront_shutdown_script=?," + " option_static_remotekey=?" " WHERE id=?")); db_bind_u64(stmt, 0, chan->their_shachain.id); if (chan->scid) @@ -1288,7 +1291,8 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) tal_count(chan->remote_upfront_shutdown_script)); else db_bind_null(stmt, 27); - db_bind_u64(stmt, 28, chan->dbid); + db_bind_int(stmt, 28, chan->option_static_remotekey); + db_bind_u64(stmt, 29, chan->dbid); db_exec_prepared_v2(take(stmt)); wallet_channel_config_save(w, &chan->channel_info.their_config);