adds: new db fields and struct variables

- Intrduce DB update `channel` values: `feerate_base` and `feerate_ppm`
- Make fist use of now context realted DB migration
- Add `struct channel` members of the same name
- Use struct values instead of config when commiting new channels
This commit is contained in:
Michael Schmoock 2019-02-21 01:01:33 +01:00 committed by Rusty Russell
parent 1853b399b0
commit 1043df28be
6 changed files with 42 additions and 9 deletions

View File

@ -171,7 +171,9 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
bool connected,
const struct basepoints *local_basepoints,
const struct pubkey *local_funding_pubkey,
const struct pubkey *future_per_commitment_point)
const struct pubkey *future_per_commitment_point,
u32 feerate_base,
u32 feerate_ppm)
{
struct channel *channel = tal(peer->ld, struct channel);
@ -234,6 +236,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
channel->local_funding_pubkey = *local_funding_pubkey;
channel->future_per_commitment_point
= tal_steal(channel, future_per_commitment_point);
channel->feerate_base = feerate_base;
channel->feerate_ppm = feerate_ppm;
list_add_tail(&peer->channels, &channel->list);
tal_add_destructor(channel, destroy_channel);

View File

@ -110,6 +110,9 @@ struct channel {
/* Do we have an "impossible" future per_commitment_point from
* peer via option_data_loss_protect? */
const struct pubkey *future_per_commitment_point;
/* Feerate per channel */
u32 feerate_base, feerate_ppm;
};
struct channel *new_channel(struct peer *peer, u64 dbid,
@ -154,7 +157,9 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
bool connected,
const struct basepoints *local_basepoints,
const struct pubkey *local_funding_pubkey,
const struct pubkey *future_per_commitment_point);
const struct pubkey *future_per_commitment_point,
u32 feerate_base,
u32 feerate_ppm);
void delete_channel(struct channel *channel);

View File

@ -352,8 +352,8 @@ void peer_start_channeld(struct channel *channel,
&channel->channel_info.remote_per_commit,
&channel->channel_info.old_remote_per_commit,
channel->funder,
cfg->fee_base,
cfg->fee_per_satoshi,
channel->feerate_base,
channel->feerate_ppm,
channel->our_msat,
&channel->local_basepoints,
&channel->local_funding_pubkey,

View File

@ -223,7 +223,9 @@ wallet_commit_channel(struct lightningd *ld,
true,
&uc->local_basepoints,
&uc->local_funding_pubkey,
NULL);
NULL,
ld->config.fee_base,
ld->config.fee_per_satoshi);
/* Now we finally put it in the database. */
wallet_channel_insert(ld->wallet, channel);

View File

@ -20,6 +20,8 @@ struct migration {
void (*func)(struct lightningd *ld, struct db *db);
};
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
* string indices */
@ -367,6 +369,10 @@ static struct migration dbmigrations[] = {
{ "ALTER TABLE outputs ADD scriptpubkey BLOB;", NULL },
/* Keep bolt11 string for payments. */
{ "ALTER TABLE payments ADD bolt11 TEXT;", NULL },
/* PR #2342 feerate per channel */
{ "ALTER TABLE channels ADD feerate_base INTEGER;", NULL },
{ "ALTER TABLE channels ADD feerate_ppm INTEGER;", NULL },
{ NULL, migrate_pr2342_feerate_per_channel },
};
/* Leak tracking. */
@ -972,3 +978,12 @@ void sqlite3_bind_amount_sat(sqlite3_stmt *stmt, int col,
{
sqlite3_bind_int64(stmt, col, sat.satoshis); /* Raw: low level function */
}
/* Will apply the current config fee settings to all channels */
void migrate_pr2342_feerate_per_channel(struct lightningd *ld, struct db *db)
{
db_exec(__func__, db,
"UPDATE channels SET feerate_base = %u, feerate_ppm = %u;",
ld->config.fee_base,
ld->config.fee_per_satoshi);
}

View File

@ -740,7 +740,9 @@ static struct channel *wallet_stmt2channel(const tal_t *ctx, struct wallet *w, s
/* Not connected */
false,
&local_basepoints, &local_funding_pubkey,
future_per_commitment_point);
future_per_commitment_point,
sqlite3_column_int(stmt, 42),
sqlite3_column_int(stmt, 43));
return chan;
}
@ -765,7 +767,8 @@ static const char *channel_fields =
/*32*/ "last_tx, last_sig, last_was_revoke, first_blocknum, "
/*36*/ "min_possible_feerate, max_possible_feerate, "
/*38*/ "msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, "
/*41*/ "last_sent_commit";
/*41*/ "last_sent_commit, "
/*42*/ "feerate_base, feerate_ppm";
bool wallet_channels_load_active(const tal_t *ctx, struct wallet *w)
{
@ -983,7 +986,9 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
" min_possible_feerate=?,"
" max_possible_feerate=?,"
" msatoshi_to_us_min=?,"
" msatoshi_to_us_max=?"
" msatoshi_to_us_max=?,"
" feerate_base=?,"
" feerate_ppm=?"
" WHERE id=?");
sqlite3_bind_int64(stmt, 1, chan->their_shachain.id);
if (chan->scid)
@ -1023,7 +1028,9 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
sqlite3_bind_int(stmt, 23, chan->max_possible_feerate);
sqlite3_bind_amount_msat(stmt, 24, chan->msat_to_us_min);
sqlite3_bind_amount_msat(stmt, 25, chan->msat_to_us_max);
sqlite3_bind_int64(stmt, 26, chan->dbid);
sqlite3_bind_int(stmt, 26, chan->feerate_base);
sqlite3_bind_int(stmt, 27, chan->feerate_ppm);
sqlite3_bind_int64(stmt, 28, chan->dbid);
db_exec_prepared(w->db, stmt);
wallet_channel_config_save(w, &chan->channel_info.their_config);