mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
lightningd: use channel_type, pass to-and-from channeld.
Instead of explicit option_static_remotekey and option_anchor_outputs flags. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
740afb822c
commit
183fe107e8
@@ -75,8 +75,9 @@ LIGHTNINGD_COMMON_OBJS := \
|
||||
common/bolt11_json.o \
|
||||
common/bolt12.o \
|
||||
common/bolt12_merkle.o \
|
||||
common/channel_id.o \
|
||||
common/channel_config.o \
|
||||
common/channel_id.o \
|
||||
common/channel_type.o \
|
||||
common/coin_mvt.o \
|
||||
common/configdir.o \
|
||||
common/crypto_state.o \
|
||||
|
||||
@@ -284,7 +284,7 @@ struct channel *new_unsaved_channel(struct peer *peer,
|
||||
* | `option_anchor_outputs` */
|
||||
channel->static_remotekey_start[LOCAL]
|
||||
= channel->static_remotekey_start[REMOTE] = 0;
|
||||
channel->option_anchor_outputs = true;
|
||||
channel->type = channel_type_anchor_outputs(channel);
|
||||
channel->future_per_commitment_point = NULL;
|
||||
|
||||
channel->lease_commit_sig = NULL;
|
||||
@@ -358,7 +358,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||
const u8 *remote_upfront_shutdown_script,
|
||||
u64 local_static_remotekey_start,
|
||||
u64 remote_static_remotekey_start,
|
||||
bool option_anchor_outputs,
|
||||
const struct channel_type *type STEALS,
|
||||
enum side closer,
|
||||
enum state_change reason,
|
||||
/* NULL or stolen */
|
||||
@@ -454,7 +454,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||
= tal_steal(channel, remote_upfront_shutdown_script);
|
||||
channel->static_remotekey_start[LOCAL] = local_static_remotekey_start;
|
||||
channel->static_remotekey_start[REMOTE] = remote_static_remotekey_start;
|
||||
channel->option_anchor_outputs = option_anchor_outputs;
|
||||
channel->type = tal_steal(channel, type);
|
||||
channel->forgets = tal_arr(channel, struct command *, 0);
|
||||
|
||||
channel->lease_expiry = lease_expiry;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "config.h"
|
||||
#include <ccan/list/list.h>
|
||||
#include <common/channel_id.h>
|
||||
#include <common/channel_type.h>
|
||||
#include <common/per_peer_state.h>
|
||||
#include <common/tx_roles.h>
|
||||
#include <lightningd/channel_state.h>
|
||||
@@ -204,8 +205,8 @@ struct channel {
|
||||
/* At what commit numbers does `option_static_remotekey` apply? */
|
||||
u64 static_remotekey_start[NUM_SIDES];
|
||||
|
||||
/* Was this negotiated with `option_anchor_outputs? */
|
||||
bool option_anchor_outputs;
|
||||
/* What features apply to this channel? */
|
||||
const struct channel_type *type;
|
||||
|
||||
/* Any commands trying to forget us. */
|
||||
struct command **forgets;
|
||||
@@ -294,7 +295,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||
const u8 *remote_upfront_shutdown_script STEALS,
|
||||
u64 local_static_remotekey_start,
|
||||
u64 remote_static_remotekey_start,
|
||||
bool option_anchor_outputs,
|
||||
const struct channel_type *type STEALS,
|
||||
enum side closer,
|
||||
enum state_change reason,
|
||||
/* NULL or stolen */
|
||||
@@ -451,6 +452,11 @@ static inline bool channel_closed(const struct channel *channel)
|
||||
|| channel->state == CLOSED;
|
||||
}
|
||||
|
||||
static inline bool channel_has(const struct channel *channel, int f)
|
||||
{
|
||||
return channel_type_has(channel->type, f);
|
||||
}
|
||||
|
||||
void get_channel_basepoints(struct lightningd *ld,
|
||||
const struct node_id *peer_id,
|
||||
const u64 dbid,
|
||||
|
||||
@@ -431,14 +431,32 @@ void forget_channel(struct channel *channel, const char *why)
|
||||
static void handle_channel_upgrade(struct channel *channel,
|
||||
const u8 *msg)
|
||||
{
|
||||
bool option_static_remotekey;
|
||||
struct channel_type *newtype;
|
||||
|
||||
if (!fromwire_channeld_upgraded(msg, &option_static_remotekey)) {
|
||||
if (!fromwire_channeld_upgraded(msg, msg, &newtype)) {
|
||||
channel_internal_error(channel, "bad handle_channel_upgrade: %s",
|
||||
tal_hex(tmpctx, msg));
|
||||
return;
|
||||
}
|
||||
|
||||
/* You can currently only upgrade to turn on option_static_remotekey:
|
||||
* if they somehow thought anything else we need to close channel! */
|
||||
if (channel->static_remotekey_start[LOCAL] != 0x7FFFFFFFFFFFFFFFULL) {
|
||||
channel_internal_error(channel,
|
||||
"channel_upgrade already static_remotekey? %s",
|
||||
tal_hex(tmpctx, msg));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!channel_type_eq(newtype, channel_type_static_remotekey(tmpctx))) {
|
||||
channel_internal_error(channel,
|
||||
"channel_upgrade must be static_remotekey, not %s",
|
||||
fmt_featurebits(tmpctx, newtype->features));
|
||||
return;
|
||||
}
|
||||
|
||||
tal_free(channel->type);
|
||||
channel->type = channel_type_dup(channel, newtype);
|
||||
channel->static_remotekey_start[LOCAL] = channel->next_index[LOCAL];
|
||||
channel->static_remotekey_start[REMOTE] = channel->next_index[REMOTE];
|
||||
log_debug(channel->log,
|
||||
@@ -692,10 +710,7 @@ void peer_start_channeld(struct channel *channel,
|
||||
channel->remote_upfront_shutdown_script,
|
||||
remote_ann_node_sig,
|
||||
remote_ann_bitcoin_sig,
|
||||
/* Set at channel open, even if not
|
||||
* negotiated now! */
|
||||
channel->next_index[LOCAL] >= channel->static_remotekey_start[LOCAL],
|
||||
channel->option_anchor_outputs,
|
||||
channel->type,
|
||||
IFDEV(ld->dev_fast_gossip, false),
|
||||
IFDEV(dev_fail_process_onionpacket, false),
|
||||
pbases,
|
||||
|
||||
@@ -199,6 +199,7 @@ void peer_start_closingd(struct channel *channel,
|
||||
int hsmfd;
|
||||
struct lightningd *ld = channel->peer->ld;
|
||||
u32 final_commit_feerate;
|
||||
bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS);
|
||||
|
||||
if (!channel->shutdown_scriptpubkey[REMOTE]) {
|
||||
channel_internal_error(channel,
|
||||
@@ -243,7 +244,7 @@ void peer_start_closingd(struct channel *channel,
|
||||
final_commit_feerate = get_feerate(channel->fee_states,
|
||||
channel->opener, LOCAL);
|
||||
feelimit = commit_tx_base_fee(final_commit_feerate, 0,
|
||||
channel->option_anchor_outputs);
|
||||
option_anchor_outputs);
|
||||
|
||||
/* If we can't determine feerate, start at half unilateral feerate. */
|
||||
feerate = mutual_close_feerate(ld->topology);
|
||||
@@ -255,7 +256,7 @@ void peer_start_closingd(struct channel *channel,
|
||||
|
||||
/* We use a feerate if anchor_outputs, otherwise max fee is set by
|
||||
* the final unilateral. */
|
||||
if (channel->option_anchor_outputs) {
|
||||
if (option_anchor_outputs) {
|
||||
max_feerate = tal(tmpctx, u32);
|
||||
/* Aim for reasonable max, but use final if we don't know. */
|
||||
*max_feerate = unilateral_feerate(ld->topology);
|
||||
@@ -316,7 +317,7 @@ void peer_start_closingd(struct channel *channel,
|
||||
(channel->closing_fee_negotiation_step == 50
|
||||
&& channel->closing_fee_negotiation_step_unit == CLOSING_FEE_NEGOTIATION_STEP_UNIT_PERCENTAGE)
|
||||
/* Always use quickclose with anchors */
|
||||
|| channel->option_anchor_outputs,
|
||||
|| option_anchor_outputs,
|
||||
IFDEV(ld->dev_fast_gossip, false),
|
||||
channel->shutdown_wrong_funding);
|
||||
|
||||
|
||||
@@ -705,7 +705,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
|
||||
&channel->channel_info.remote_fundingkey,
|
||||
channel->static_remotekey_start[LOCAL],
|
||||
channel->static_remotekey_start[REMOTE],
|
||||
channel->option_anchor_outputs,
|
||||
channel_has(channel, OPT_ANCHOR_OUTPUTS),
|
||||
is_replay,
|
||||
feerate_min(ld, NULL));
|
||||
subd_send_msg(channel->owner, take(msg));
|
||||
|
||||
@@ -105,7 +105,7 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
struct amount_sat local_funding;
|
||||
s64 final_key_idx;
|
||||
u64 static_remotekey_start;
|
||||
bool option_anchor_outputs;
|
||||
struct channel_type *type;
|
||||
u32 lease_start_blockheight = 0; /* No leases on v1 */
|
||||
|
||||
/* We cannot both be the fundee *and* have a `fundchannel_start`
|
||||
@@ -161,18 +161,13 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
* - MUST use that `channel_type` for all commitment transactions.
|
||||
*/
|
||||
/* i.e. We set it now for the channel permanently. */
|
||||
if (feature_negotiated(ld->our_features,
|
||||
uc->peer->their_features,
|
||||
OPT_STATIC_REMOTEKEY))
|
||||
type = default_channel_type(NULL,
|
||||
ld->our_features, uc->peer->their_features);
|
||||
if (channel_type_has(type, OPT_STATIC_REMOTEKEY))
|
||||
static_remotekey_start = 0;
|
||||
else
|
||||
static_remotekey_start = 0x7FFFFFFFFFFFFFFF;
|
||||
|
||||
option_anchor_outputs
|
||||
= feature_negotiated(ld->our_features,
|
||||
uc->peer->their_features,
|
||||
OPT_ANCHOR_OUTPUTS);
|
||||
|
||||
channel = new_channel(uc->peer, uc->dbid,
|
||||
NULL, /* No shachain yet */
|
||||
CHANNELD_AWAITING_LOCKIN,
|
||||
@@ -221,7 +216,7 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
ld->config.fee_per_satoshi,
|
||||
remote_upfront_shutdown_script,
|
||||
static_remotekey_start, static_remotekey_start,
|
||||
option_anchor_outputs,
|
||||
type,
|
||||
NUM_SIDES, /* closer not yet known */
|
||||
uc->fc ? REASON_USER : REASON_REMOTE,
|
||||
NULL,
|
||||
|
||||
@@ -504,7 +504,7 @@ static void json_add_htlcs(struct lightningd *ld,
|
||||
htlc_state_name(hin->hstate));
|
||||
if (htlc_is_trimmed(REMOTE, hin->msat, local_feerate,
|
||||
channel->our_config.dust_limit, LOCAL,
|
||||
channel->option_anchor_outputs))
|
||||
channel_has(channel, OPT_ANCHOR_OUTPUTS)))
|
||||
json_add_bool(response, "local_trimmed", true);
|
||||
if (hin->status != NULL)
|
||||
json_add_string(response, "status", hin->status);
|
||||
@@ -528,7 +528,7 @@ static void json_add_htlcs(struct lightningd *ld,
|
||||
htlc_state_name(hout->hstate));
|
||||
if (htlc_is_trimmed(LOCAL, hout->msat, local_feerate,
|
||||
channel->our_config.dust_limit, LOCAL,
|
||||
channel->option_anchor_outputs))
|
||||
channel_has(channel, OPT_ANCHOR_OUTPUTS)))
|
||||
json_add_bool(response, "local_trimmed", true);
|
||||
json_object_end(response);
|
||||
}
|
||||
@@ -563,6 +563,7 @@ static struct amount_sat commit_txfee(const struct channel *channel,
|
||||
channel->opener, side);
|
||||
struct amount_sat dust_limit;
|
||||
struct amount_sat fee;
|
||||
bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS);
|
||||
|
||||
if (side == LOCAL)
|
||||
dust_limit = channel->our_config.dust_limit;
|
||||
@@ -571,7 +572,7 @@ static struct amount_sat commit_txfee(const struct channel *channel,
|
||||
|
||||
/* Assume we tried to add "amount" */
|
||||
if (!htlc_is_trimmed(side, amount, feerate, dust_limit, side,
|
||||
channel->option_anchor_outputs))
|
||||
option_anchor_outputs))
|
||||
num_untrimmed_htlcs++;
|
||||
|
||||
for (hin = htlc_in_map_first(&ld->htlcs_in, &ini);
|
||||
@@ -580,8 +581,7 @@ static struct amount_sat commit_txfee(const struct channel *channel,
|
||||
if (hin->key.channel != channel)
|
||||
continue;
|
||||
if (!htlc_is_trimmed(!side, hin->msat, feerate, dust_limit,
|
||||
side,
|
||||
channel->option_anchor_outputs))
|
||||
side, option_anchor_outputs))
|
||||
num_untrimmed_htlcs++;
|
||||
}
|
||||
for (hout = htlc_out_map_first(&ld->htlcs_out, &outi);
|
||||
@@ -590,8 +590,7 @@ static struct amount_sat commit_txfee(const struct channel *channel,
|
||||
if (hout->key.channel != channel)
|
||||
continue;
|
||||
if (!htlc_is_trimmed(side, hout->msat, feerate, dust_limit,
|
||||
side,
|
||||
channel->option_anchor_outputs))
|
||||
side, option_anchor_outputs))
|
||||
num_untrimmed_htlcs++;
|
||||
}
|
||||
|
||||
@@ -608,9 +607,9 @@ static struct amount_sat commit_txfee(const struct channel *channel,
|
||||
* predictability between implementations.
|
||||
*/
|
||||
fee = commit_tx_base_fee(2 * feerate, num_untrimmed_htlcs + 1,
|
||||
channel->option_anchor_outputs);
|
||||
option_anchor_outputs);
|
||||
|
||||
if (channel->option_anchor_outputs) {
|
||||
if (option_anchor_outputs) {
|
||||
/* BOLT #3:
|
||||
* If `option_anchors` applies to the commitment
|
||||
* transaction, also subtract two times the fixed anchor size
|
||||
@@ -854,9 +853,9 @@ static void json_add_channel(struct lightningd *ld,
|
||||
json_add_null(response, "closer");
|
||||
|
||||
json_array_start(response, "features");
|
||||
if (channel->static_remotekey_start[LOCAL] != 0x7FFFFFFFFFFFFFFF)
|
||||
if (channel_has(channel, OPT_STATIC_REMOTEKEY))
|
||||
json_add_string(response, NULL, "option_static_remotekey");
|
||||
if (channel->option_anchor_outputs)
|
||||
if (channel_has(channel, OPT_ANCHOR_OUTPUTS))
|
||||
json_add_string(response, NULL, "option_anchor_outputs");
|
||||
json_array_end(response);
|
||||
|
||||
|
||||
@@ -1127,7 +1127,6 @@ static bool ecdh_maybe_blinding(const struct pubkey *ephemeral_key,
|
||||
return true;
|
||||
}
|
||||
|
||||
/* AUTODATA wants a different line number */
|
||||
REGISTER_PLUGIN_HOOK(htlc_accepted,
|
||||
htlc_accepted_hook_deserialize,
|
||||
htlc_accepted_hook_final,
|
||||
|
||||
@@ -121,6 +121,9 @@ bool channel_tell_depth(struct lightningd *ld UNNEEDED,
|
||||
const struct bitcoin_txid *txid UNNEEDED,
|
||||
u32 depth UNNEEDED)
|
||||
{ fprintf(stderr, "channel_tell_depth called!\n"); abort(); }
|
||||
/* Generated stub for channel_type_has */
|
||||
bool channel_type_has(const struct channel_type *type UNNEEDED, int feature UNNEEDED)
|
||||
{ fprintf(stderr, "channel_type_has called!\n"); abort(); }
|
||||
/* Generated stub for channel_unsaved_close_conn */
|
||||
void channel_unsaved_close_conn(struct channel *channel UNNEEDED, const char *why UNNEEDED)
|
||||
{ fprintf(stderr, "channel_unsaved_close_conn called!\n"); abort(); }
|
||||
|
||||
Reference in New Issue
Block a user