Browse Source

db: store option_static_remotekey for each channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
Rusty Russell 5 years ago
committed by neil saitug
parent
commit
11ee089d4b
  1. 4
      lightningd/channel.c
  2. 6
      lightningd/channel.h
  3. 3
      lightningd/opening_control.c
  4. 3
      wallet/db.c
  5. 10
      wallet/wallet.c

4
lightningd/channel.c

@ -177,7 +177,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
const struct pubkey *future_per_commitment_point, const struct pubkey *future_per_commitment_point,
u32 feerate_base, u32 feerate_base,
u32 feerate_ppm, 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); 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->feerate_ppm = feerate_ppm;
channel->remote_upfront_shutdown_script channel->remote_upfront_shutdown_script
= tal_steal(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); list_add_tail(&peer->channels, &channel->list);
tal_add_destructor(channel, destroy_channel); tal_add_destructor(channel, destroy_channel);

6
lightningd/channel.h

@ -117,6 +117,9 @@ struct channel {
/* If they used option_upfront_shutdown_script. */ /* If they used option_upfront_shutdown_script. */
const u8 *remote_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, 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_base,
u32 feerate_ppm, u32 feerate_ppm,
/* NULL or stolen */ /* 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); void delete_channel(struct channel *channel);

3
lightningd/opening_control.c

@ -237,7 +237,8 @@ wallet_commit_channel(struct lightningd *ld,
NULL, NULL,
ld->config.fee_base, ld->config.fee_base,
ld->config.fee_per_satoshi, ld->config.fee_per_satoshi,
remote_upfront_shutdown_script); remote_upfront_shutdown_script,
false);
/* Now we finally put it in the database. */ /* Now we finally put it in the database. */
wallet_channel_insert(ld->wallet, channel); wallet_channel_insert(ld->wallet, channel);

3
wallet/db.c

@ -457,6 +457,9 @@ static struct migration dbmigrations[] = {
" WHERE short_channel_id IS NOT NULL;"), NULL }, " WHERE short_channel_id IS NOT NULL;"), NULL },
{SQL("UPDATE payments SET failchannel = REPLACE(failchannel, ':', 'x')" {SQL("UPDATE payments SET failchannel = REPLACE(failchannel, ':', 'x')"
" WHERE failchannel IS NOT NULL;"), NULL }, " 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. */ /* Leak tracking. */

10
wallet/wallet.c

@ -909,7 +909,8 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
future_per_commitment_point, future_per_commitment_point,
db_column_int(stmt, 42), db_column_int(stmt, 42),
db_column_int(stmt, 43), 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; return chan;
} }
@ -980,6 +981,7 @@ static bool wallet_channels_load_active(struct wallet *w)
", feerate_base" ", feerate_base"
", feerate_ppm" ", feerate_ppm"
", remote_upfront_shutdown_script" ", remote_upfront_shutdown_script"
", option_static_remotekey"
" FROM channels WHERE state < ?;")); " FROM channels WHERE state < ?;"));
db_bind_int(stmt, 0, CLOSED); db_bind_int(stmt, 0, CLOSED);
db_query_prepared(stmt); db_query_prepared(stmt);
@ -1241,7 +1243,8 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
" msatoshi_to_us_max=?," " msatoshi_to_us_max=?,"
" feerate_base=?," " feerate_base=?,"
" feerate_ppm=?," " feerate_ppm=?,"
" remote_upfront_shutdown_script=?" " remote_upfront_shutdown_script=?,"
" option_static_remotekey=?"
" WHERE id=?")); " WHERE id=?"));
db_bind_u64(stmt, 0, chan->their_shachain.id); db_bind_u64(stmt, 0, chan->their_shachain.id);
if (chan->scid) if (chan->scid)
@ -1288,7 +1291,8 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
tal_count(chan->remote_upfront_shutdown_script)); tal_count(chan->remote_upfront_shutdown_script));
else else
db_bind_null(stmt, 27); 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)); db_exec_prepared_v2(take(stmt));
wallet_channel_config_save(w, &chan->channel_info.their_config); wallet_channel_config_save(w, &chan->channel_info.their_config);

Loading…
Cancel
Save