mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
lightningd: separate fee_states out of struct channel_info.
It was always kind of weird in there anyway. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
cf2a807d3c
commit
58f6e316cc
@ -174,6 +174,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
|||||||
/* NULL or stolen */
|
/* NULL or stolen */
|
||||||
const struct bitcoin_signature *last_htlc_sigs,
|
const struct bitcoin_signature *last_htlc_sigs,
|
||||||
const struct channel_info *channel_info,
|
const struct channel_info *channel_info,
|
||||||
|
const struct fee_states *fee_states TAKES,
|
||||||
/* NULL or stolen */
|
/* NULL or stolen */
|
||||||
u8 *remote_shutdown_scriptpubkey,
|
u8 *remote_shutdown_scriptpubkey,
|
||||||
const u8 *local_shutdown_scriptpubkey,
|
const u8 *local_shutdown_scriptpubkey,
|
||||||
@ -244,8 +245,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
|||||||
channel->last_sig = *last_sig;
|
channel->last_sig = *last_sig;
|
||||||
channel->last_htlc_sigs = tal_steal(channel, last_htlc_sigs);
|
channel->last_htlc_sigs = tal_steal(channel, last_htlc_sigs);
|
||||||
channel->channel_info = *channel_info;
|
channel->channel_info = *channel_info;
|
||||||
channel->channel_info.fee_states
|
channel->fee_states = dup_fee_states(channel, fee_states);
|
||||||
= dup_fee_states(channel, channel_info->fee_states);
|
|
||||||
channel->shutdown_scriptpubkey[REMOTE]
|
channel->shutdown_scriptpubkey[REMOTE]
|
||||||
= tal_steal(channel, remote_shutdown_scriptpubkey);
|
= tal_steal(channel, remote_shutdown_scriptpubkey);
|
||||||
channel->final_key_idx = final_key_idx;
|
channel->final_key_idx = final_key_idx;
|
||||||
|
@ -91,6 +91,9 @@ struct channel {
|
|||||||
/* Keys for channel */
|
/* Keys for channel */
|
||||||
struct channel_info channel_info;
|
struct channel_info channel_info;
|
||||||
|
|
||||||
|
/* Fee status */
|
||||||
|
const struct fee_states *fee_states;
|
||||||
|
|
||||||
/* Our local basepoints */
|
/* Our local basepoints */
|
||||||
struct basepoints local_basepoints;
|
struct basepoints local_basepoints;
|
||||||
|
|
||||||
@ -176,6 +179,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
|||||||
/* NULL or stolen */
|
/* NULL or stolen */
|
||||||
const struct bitcoin_signature *last_htlc_sigs STEALS,
|
const struct bitcoin_signature *last_htlc_sigs STEALS,
|
||||||
const struct channel_info *channel_info,
|
const struct channel_info *channel_info,
|
||||||
|
const struct fee_states *fee_states TAKES,
|
||||||
/* NULL or stolen */
|
/* NULL or stolen */
|
||||||
u8 *remote_shutdown_scriptpubkey STEALS,
|
u8 *remote_shutdown_scriptpubkey STEALS,
|
||||||
const u8 *local_shutdown_scriptpubkey,
|
const u8 *local_shutdown_scriptpubkey,
|
||||||
|
@ -522,7 +522,7 @@ void peer_start_channeld(struct channel *channel,
|
|||||||
channel->minimum_depth,
|
channel->minimum_depth,
|
||||||
&channel->our_config,
|
&channel->our_config,
|
||||||
&channel->channel_info.their_config,
|
&channel->channel_info.their_config,
|
||||||
channel->channel_info.fee_states,
|
channel->fee_states,
|
||||||
feerate_min(ld, NULL),
|
feerate_min(ld, NULL),
|
||||||
feerate_max(ld, NULL),
|
feerate_max(ld, NULL),
|
||||||
try_get_feerate(ld->topology, FEERATE_PENALTY),
|
try_get_feerate(ld->topology, FEERATE_PENALTY),
|
||||||
|
@ -216,7 +216,7 @@ void peer_start_closingd(struct channel *channel,
|
|||||||
* fee of the final commitment transaction, as calculated in
|
* fee of the final commitment transaction, as calculated in
|
||||||
* [BOLT #3](03-transactions.md#fee-calculation).
|
* [BOLT #3](03-transactions.md#fee-calculation).
|
||||||
*/
|
*/
|
||||||
final_commit_feerate = get_feerate(channel->channel_info.fee_states,
|
final_commit_feerate = get_feerate(channel->fee_states,
|
||||||
channel->opener, LOCAL);
|
channel->opener, LOCAL);
|
||||||
feelimit = commit_tx_base_fee(final_commit_feerate, 0,
|
feelimit = commit_tx_base_fee(final_commit_feerate, 0,
|
||||||
channel->option_anchor_outputs);
|
channel->option_anchor_outputs);
|
||||||
|
@ -678,12 +678,6 @@ wallet_commit_channel(struct lightningd *ld,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is actually correct, it's stolen onto
|
|
||||||
* channel in `new_channel` */
|
|
||||||
channel_info->fee_states = take(new_fee_states(NULL,
|
|
||||||
opener,
|
|
||||||
&feerate));
|
|
||||||
|
|
||||||
/* old_remote_per_commit not valid yet, copy valid one. */
|
/* old_remote_per_commit not valid yet, copy valid one. */
|
||||||
channel_info->old_remote_per_commit = channel_info->remote_per_commit;
|
channel_info->old_remote_per_commit = channel_info->remote_per_commit;
|
||||||
|
|
||||||
@ -724,6 +718,7 @@ wallet_commit_channel(struct lightningd *ld,
|
|||||||
remote_commit_sig,
|
remote_commit_sig,
|
||||||
NULL, /* No HTLC sigs yet */
|
NULL, /* No HTLC sigs yet */
|
||||||
channel_info,
|
channel_info,
|
||||||
|
take(new_fee_states(NULL, opener, &feerate)),
|
||||||
NULL, /* No shutdown_scriptpubkey[REMOTE] yet */
|
NULL, /* No shutdown_scriptpubkey[REMOTE] yet */
|
||||||
our_upfront_shutdown_script,
|
our_upfront_shutdown_script,
|
||||||
final_key_idx, false,
|
final_key_idx, false,
|
||||||
|
@ -126,9 +126,6 @@ wallet_commit_channel(struct lightningd *ld,
|
|||||||
local_funding = AMOUNT_SAT(0);
|
local_funding = AMOUNT_SAT(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
channel_info->fee_states = new_fee_states(uc, uc->fc ? LOCAL : REMOTE,
|
|
||||||
&feerate);
|
|
||||||
|
|
||||||
/* old_remote_per_commit not valid yet, copy valid one. */
|
/* old_remote_per_commit not valid yet, copy valid one. */
|
||||||
channel_info->old_remote_per_commit = channel_info->remote_per_commit;
|
channel_info->old_remote_per_commit = channel_info->remote_per_commit;
|
||||||
|
|
||||||
@ -187,6 +184,8 @@ wallet_commit_channel(struct lightningd *ld,
|
|||||||
remote_commit_sig,
|
remote_commit_sig,
|
||||||
NULL, /* No HTLC sigs yet */
|
NULL, /* No HTLC sigs yet */
|
||||||
channel_info,
|
channel_info,
|
||||||
|
take(new_fee_states(NULL, uc->fc ? LOCAL : REMOTE,
|
||||||
|
&feerate)),
|
||||||
NULL, /* No shutdown_scriptpubkey[REMOTE] yet */
|
NULL, /* No shutdown_scriptpubkey[REMOTE] yet */
|
||||||
our_upfront_shutdown_script,
|
our_upfront_shutdown_script,
|
||||||
final_key_idx, false,
|
final_key_idx, false,
|
||||||
|
@ -452,7 +452,7 @@ static void json_add_htlcs(struct lightningd *ld,
|
|||||||
struct htlc_in_map_iter ini;
|
struct htlc_in_map_iter ini;
|
||||||
const struct htlc_out *hout;
|
const struct htlc_out *hout;
|
||||||
struct htlc_out_map_iter outi;
|
struct htlc_out_map_iter outi;
|
||||||
u32 local_feerate = get_feerate(channel->channel_info.fee_states,
|
u32 local_feerate = get_feerate(channel->fee_states,
|
||||||
channel->opener, LOCAL);
|
channel->opener, LOCAL);
|
||||||
|
|
||||||
/* FIXME: Add more fields. */
|
/* FIXME: Add more fields. */
|
||||||
@ -527,7 +527,7 @@ static struct amount_sat commit_txfee(const struct channel *channel,
|
|||||||
struct htlc_out_map_iter outi;
|
struct htlc_out_map_iter outi;
|
||||||
struct lightningd *ld = channel->peer->ld;
|
struct lightningd *ld = channel->peer->ld;
|
||||||
size_t num_untrimmed_htlcs = 0;
|
size_t num_untrimmed_htlcs = 0;
|
||||||
u32 feerate = get_feerate(channel->channel_info.fee_states,
|
u32 feerate = get_feerate(channel->fee_states,
|
||||||
channel->opener, side);
|
channel->opener, side);
|
||||||
struct amount_sat dust_limit;
|
struct amount_sat dust_limit;
|
||||||
struct amount_sat fee;
|
struct amount_sat fee;
|
||||||
|
@ -1735,8 +1735,8 @@ void peer_sending_commitsig(struct channel *channel, const u8 *msg)
|
|||||||
|
|
||||||
/* FIXME: We could detect if this changed, and adjust bounds and write
|
/* FIXME: We could detect if this changed, and adjust bounds and write
|
||||||
* it to db iff it has. */
|
* it to db iff it has. */
|
||||||
tal_free(channel->channel_info.fee_states);
|
tal_free(channel->fee_states);
|
||||||
channel->channel_info.fee_states = tal_steal(channel, fee_states);
|
channel->fee_states = tal_steal(channel, fee_states);
|
||||||
adjust_channel_feerate_bounds(channel,
|
adjust_channel_feerate_bounds(channel,
|
||||||
get_feerate(fee_states,
|
get_feerate(fee_states,
|
||||||
channel->opener,
|
channel->opener,
|
||||||
@ -1955,8 +1955,8 @@ void peer_got_commitsig(struct channel *channel, const u8 *msg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tal_free(channel->channel_info.fee_states);
|
tal_free(channel->fee_states);
|
||||||
channel->channel_info.fee_states = tal_steal(channel, fee_states);
|
channel->fee_states = tal_steal(channel, fee_states);
|
||||||
adjust_channel_feerate_bounds(channel,
|
adjust_channel_feerate_bounds(channel,
|
||||||
get_feerate(fee_states,
|
get_feerate(fee_states,
|
||||||
channel->opener,
|
channel->opener,
|
||||||
@ -2106,8 +2106,8 @@ void peer_got_revoke(struct channel *channel, const u8 *msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tal_free(channel->channel_info.fee_states);
|
tal_free(channel->fee_states);
|
||||||
channel->channel_info.fee_states = tal_steal(channel, fee_states);
|
channel->fee_states = tal_steal(channel, fee_states);
|
||||||
|
|
||||||
/* FIXME: Check per_commitment_secret -> per_commit_point */
|
/* FIXME: Check per_commitment_secret -> per_commit_point */
|
||||||
update_per_commit_point(channel, &next_per_commitment_point);
|
update_per_commit_point(channel, &next_per_commitment_point);
|
||||||
|
@ -25,7 +25,6 @@ struct channel_info {
|
|||||||
/* The old_remote_per_commit is for the locked-in remote commit_tx,
|
/* The old_remote_per_commit is for the locked-in remote commit_tx,
|
||||||
* and the remote_per_commit is for the commit_tx we're modifying now. */
|
* and the remote_per_commit is for the commit_tx we're modifying now. */
|
||||||
struct pubkey remote_per_commit, old_remote_per_commit;
|
struct pubkey remote_per_commit, old_remote_per_commit;
|
||||||
struct fee_states *fee_states;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Get all HTLCs for a peer, to send in init message. */
|
/* Get all HTLCs for a peer, to send in init message. */
|
||||||
|
2
wallet/db_postgres_sqlgen.c
generated
2
wallet/db_postgres_sqlgen.c
generated
@ -1654,4 +1654,4 @@ struct db_query db_postgres_queries[] = {
|
|||||||
|
|
||||||
#endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */
|
#endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */
|
||||||
|
|
||||||
// SHA256STAMP:f87b55286c80cc692daa892dd21fe22e3a754c87a6f93bd05e22a443e93b2a61
|
// SHA256STAMP:fa191e6b54c56b2d4e85a24ca83bc0d41dddec5dbde948e2bc5d627426089ade
|
||||||
|
2
wallet/db_sqlite3_sqlgen.c
generated
2
wallet/db_sqlite3_sqlgen.c
generated
@ -1654,4 +1654,4 @@ struct db_query db_sqlite3_queries[] = {
|
|||||||
|
|
||||||
#endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */
|
#endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */
|
||||||
|
|
||||||
// SHA256STAMP:f87b55286c80cc692daa892dd21fe22e3a754c87a6f93bd05e22a443e93b2a61
|
// SHA256STAMP:fa191e6b54c56b2d4e85a24ca83bc0d41dddec5dbde948e2bc5d627426089ade
|
||||||
|
2
wallet/statements_gettextgen.po
generated
2
wallet/statements_gettextgen.po
generated
@ -1089,4 +1089,4 @@ msgstr ""
|
|||||||
#: wallet/test/run-wallet.c:1359
|
#: wallet/test/run-wallet.c:1359
|
||||||
msgid "INSERT INTO channels (id) VALUES (1);"
|
msgid "INSERT INTO channels (id) VALUES (1);"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
# SHA256STAMP:b86ada480023c65c47b0b8b795e706125134521e717c731e2af2fbe4a5877db5
|
# SHA256STAMP:fb0b381451867f44c3f35f2202e741a06ff9f531329facf6e9df302036eff4e4
|
||||||
|
@ -1115,15 +1115,15 @@ static bool channelseq(struct channel *c1, struct channel *c2)
|
|||||||
CHECK(pubkey_eq(&ci1->remote_per_commit, &ci2->remote_per_commit));
|
CHECK(pubkey_eq(&ci1->remote_per_commit, &ci2->remote_per_commit));
|
||||||
CHECK(pubkey_eq(&ci1->old_remote_per_commit, &ci2->old_remote_per_commit));
|
CHECK(pubkey_eq(&ci1->old_remote_per_commit, &ci2->old_remote_per_commit));
|
||||||
CHECK(ci1->their_config.id != 0 && ci1->their_config.id == ci2->their_config.id);
|
CHECK(ci1->their_config.id != 0 && ci1->their_config.id == ci2->their_config.id);
|
||||||
CHECK(fee_states_valid(ci1->fee_states, c1->opener));
|
CHECK(fee_states_valid(c1->fee_states, c1->opener));
|
||||||
CHECK(fee_states_valid(ci2->fee_states, c2->opener));
|
CHECK(fee_states_valid(c2->fee_states, c2->opener));
|
||||||
for (enum htlc_state i = 0; i < ARRAY_SIZE(ci1->fee_states->feerate);
|
for (enum htlc_state i = 0; i < ARRAY_SIZE(c1->fee_states->feerate);
|
||||||
i++) {
|
i++) {
|
||||||
if (ci1->fee_states->feerate[i] == NULL) {
|
if (c1->fee_states->feerate[i] == NULL) {
|
||||||
CHECK(ci2->fee_states->feerate[i] == NULL);
|
CHECK(c2->fee_states->feerate[i] == NULL);
|
||||||
} else {
|
} else {
|
||||||
CHECK(*ci1->fee_states->feerate[i]
|
CHECK(*c1->fee_states->feerate[i]
|
||||||
== *ci2->fee_states->feerate[i]);
|
== *c2->fee_states->feerate[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1201,7 +1201,7 @@ static bool test_channel_crud(struct lightningd *ld, const tal_t *ctx)
|
|||||||
pubkey_from_der(tal_hexdata(w, "02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66), 33, &pk);
|
pubkey_from_der(tal_hexdata(w, "02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66), 33, &pk);
|
||||||
node_id_from_pubkey(&id, &pk);
|
node_id_from_pubkey(&id, &pk);
|
||||||
feerate = 31337;
|
feerate = 31337;
|
||||||
ci->fee_states = new_fee_states(w, c1.opener, &feerate);
|
c1.fee_states = new_fee_states(w, c1.opener, &feerate);
|
||||||
mempat(scriptpubkey, tal_count(scriptpubkey));
|
mempat(scriptpubkey, tal_count(scriptpubkey));
|
||||||
c1.first_blocknum = 1;
|
c1.first_blocknum = 1;
|
||||||
parse_wireaddr_internal("localhost:1234", &addr, 0, false, false, false,
|
parse_wireaddr_internal("localhost:1234", &addr, 0, false, false, false,
|
||||||
|
@ -936,6 +936,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
|
|||||||
{
|
{
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
struct channel_info channel_info;
|
struct channel_info channel_info;
|
||||||
|
struct fee_states *fee_states;
|
||||||
struct short_channel_id *scid;
|
struct short_channel_id *scid;
|
||||||
struct channel_id cid;
|
struct channel_id cid;
|
||||||
struct channel *chan;
|
struct channel *chan;
|
||||||
@ -1024,15 +1025,15 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
|
|||||||
wallet_channel_config_load(w, db_column_u64(stmt, 5),
|
wallet_channel_config_load(w, db_column_u64(stmt, 5),
|
||||||
&channel_info.their_config);
|
&channel_info.their_config);
|
||||||
|
|
||||||
channel_info.fee_states
|
fee_states
|
||||||
= wallet_channel_fee_states_load(w,
|
= wallet_channel_fee_states_load(w,
|
||||||
db_column_u64(stmt, 0),
|
db_column_u64(stmt, 0),
|
||||||
db_column_int(stmt, 7));
|
db_column_int(stmt, 7));
|
||||||
if (!channel_info.fee_states)
|
if (!fee_states)
|
||||||
ok = false;
|
ok = false;
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
tal_free(channel_info.fee_states);
|
tal_free(fee_states);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1052,8 +1053,6 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
|
|||||||
db_column_amount_msat(stmt, 40, &msat_to_us_min);
|
db_column_amount_msat(stmt, 40, &msat_to_us_min);
|
||||||
db_column_amount_msat(stmt, 41, &msat_to_us_max);
|
db_column_amount_msat(stmt, 41, &msat_to_us_max);
|
||||||
|
|
||||||
/* We want it to take this, rather than copy. */
|
|
||||||
take(channel_info.fee_states);
|
|
||||||
chan = new_channel(peer, db_column_u64(stmt, 0),
|
chan = new_channel(peer, db_column_u64(stmt, 0),
|
||||||
&wshachain,
|
&wshachain,
|
||||||
db_column_int(stmt, 6),
|
db_column_int(stmt, 6),
|
||||||
@ -1083,6 +1082,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
|
|||||||
db_column_u64(stmt, 0),
|
db_column_u64(stmt, 0),
|
||||||
db_column_int(stmt, 48)),
|
db_column_int(stmt, 48)),
|
||||||
&channel_info,
|
&channel_info,
|
||||||
|
take(fee_states),
|
||||||
remote_shutdown_scriptpubkey,
|
remote_shutdown_scriptpubkey,
|
||||||
local_shutdown_scriptpubkey,
|
local_shutdown_scriptpubkey,
|
||||||
final_key_idx,
|
final_key_idx,
|
||||||
@ -1522,15 +1522,15 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
|
|||||||
db_exec_prepared_v2(take(stmt));
|
db_exec_prepared_v2(take(stmt));
|
||||||
|
|
||||||
for (enum htlc_state i = 0;
|
for (enum htlc_state i = 0;
|
||||||
i < ARRAY_SIZE(chan->channel_info.fee_states->feerate);
|
i < ARRAY_SIZE(chan->fee_states->feerate);
|
||||||
i++) {
|
i++) {
|
||||||
if (!chan->channel_info.fee_states->feerate[i])
|
if (!chan->fee_states->feerate[i])
|
||||||
continue;
|
continue;
|
||||||
stmt = db_prepare_v2(w->db, SQL("INSERT INTO channel_feerates "
|
stmt = db_prepare_v2(w->db, SQL("INSERT INTO channel_feerates "
|
||||||
" VALUES(?, ?, ?)"));
|
" VALUES(?, ?, ?)"));
|
||||||
db_bind_u64(stmt, 0, chan->dbid);
|
db_bind_u64(stmt, 0, chan->dbid);
|
||||||
db_bind_int(stmt, 1, i);
|
db_bind_int(stmt, 1, i);
|
||||||
db_bind_int(stmt, 2, *chan->channel_info.fee_states->feerate[i]);
|
db_bind_int(stmt, 2, *chan->fee_states->feerate[i]);
|
||||||
db_exec_prepared_v2(take(stmt));
|
db_exec_prepared_v2(take(stmt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user