mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
common/initial_channel: use channel_type instead of individual option bools.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
cb22015b2a
commit
740afb822c
@@ -377,17 +377,18 @@ static bool match_type(const struct channel_type *desired,
|
|||||||
static void set_channel_type(struct channel *channel,
|
static void set_channel_type(struct channel *channel,
|
||||||
const struct channel_type *type)
|
const struct channel_type *type)
|
||||||
{
|
{
|
||||||
const struct channel_type *cur = current_channel_type(tmpctx, channel);
|
const struct channel_type *cur = channel->type;
|
||||||
|
|
||||||
if (channel_type_eq(cur, type))
|
if (channel_type_eq(cur, type))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* We only allow one upgrade at the moment, so that's it. */
|
/* We only allow one upgrade at the moment, so that's it. */
|
||||||
assert(!channel->option_static_remotekey);
|
assert(!channel_has(channel, OPT_STATIC_REMOTEKEY));
|
||||||
assert(feature_offered(type->features, OPT_STATIC_REMOTEKEY));
|
assert(feature_offered(type->features, OPT_STATIC_REMOTEKEY));
|
||||||
|
|
||||||
/* Do upgrade, tell master. */
|
/* Do upgrade, tell master. */
|
||||||
channel->option_static_remotekey = true;
|
tal_free(channel->type);
|
||||||
|
channel->type = channel_type_dup(channel, type);
|
||||||
status_unusual("Upgraded channel to [%s]",
|
status_unusual("Upgraded channel to [%s]",
|
||||||
fmt_featurebits(tmpctx, type->features));
|
fmt_featurebits(tmpctx, type->features));
|
||||||
wire_sync_write(MASTER_FD, take(towire_channeld_upgraded(NULL, true)));
|
wire_sync_write(MASTER_FD, take(towire_channeld_upgraded(NULL, true)));
|
||||||
@@ -1053,7 +1054,8 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
|
|||||||
msg = towire_hsmd_sign_remote_commitment_tx(NULL, txs[0],
|
msg = towire_hsmd_sign_remote_commitment_tx(NULL, txs[0],
|
||||||
&peer->channel->funding_pubkey[REMOTE],
|
&peer->channel->funding_pubkey[REMOTE],
|
||||||
&peer->remote_per_commit,
|
&peer->remote_per_commit,
|
||||||
peer->channel->option_static_remotekey);
|
channel_has(peer->channel,
|
||||||
|
OPT_STATIC_REMOTEKEY));
|
||||||
|
|
||||||
msg = hsm_req(tmpctx, take(msg));
|
msg = hsm_req(tmpctx, take(msg));
|
||||||
if (!fromwire_hsmd_sign_tx_reply(msg, commit_sig))
|
if (!fromwire_hsmd_sign_tx_reply(msg, commit_sig))
|
||||||
@@ -1093,7 +1095,8 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
|
|||||||
txs[i+1]->wtx->inputs[0].index);
|
txs[i+1]->wtx->inputs[0].index);
|
||||||
msg = towire_hsmd_sign_remote_htlc_tx(NULL, txs[i + 1], wscript,
|
msg = towire_hsmd_sign_remote_htlc_tx(NULL, txs[i + 1], wscript,
|
||||||
&peer->remote_per_commit,
|
&peer->remote_per_commit,
|
||||||
peer->channel->option_anchor_outputs);
|
channel_has(peer->channel,
|
||||||
|
OPT_ANCHOR_OUTPUTS));
|
||||||
|
|
||||||
msg = hsm_req(tmpctx, take(msg));
|
msg = hsm_req(tmpctx, take(msg));
|
||||||
if (!fromwire_hsmd_sign_tx_reply(msg, &htlc_sigs[i]))
|
if (!fromwire_hsmd_sign_tx_reply(msg, &htlc_sigs[i]))
|
||||||
@@ -1621,7 +1624,7 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
|
|||||||
/* SIGHASH_ALL is implied. */
|
/* SIGHASH_ALL is implied. */
|
||||||
commit_sig.sighash_type = SIGHASH_ALL;
|
commit_sig.sighash_type = SIGHASH_ALL;
|
||||||
htlc_sigs = unraw_sigs(tmpctx, raw_sigs,
|
htlc_sigs = unraw_sigs(tmpctx, raw_sigs,
|
||||||
peer->channel->option_anchor_outputs);
|
channel_has(peer->channel, OPT_ANCHOR_OUTPUTS));
|
||||||
|
|
||||||
txs =
|
txs =
|
||||||
channel_txs(tmpctx, &htlc_map, NULL,
|
channel_txs(tmpctx, &htlc_map, NULL,
|
||||||
@@ -2699,7 +2702,7 @@ static void peer_reconnect(struct peer *peer,
|
|||||||
|
|
||||||
/* Both these options give us extra fields to check. */
|
/* Both these options give us extra fields to check. */
|
||||||
check_extra_fields
|
check_extra_fields
|
||||||
= dataloss_protect || peer->channel->option_static_remotekey;
|
= dataloss_protect || channel_has(peer->channel, OPT_STATIC_REMOTEKEY);
|
||||||
|
|
||||||
/* Our current per-commitment point is the commitment point in the last
|
/* Our current per-commitment point is the commitment point in the last
|
||||||
* received signed commitment */
|
* received signed commitment */
|
||||||
@@ -2733,8 +2736,8 @@ static void peer_reconnect(struct peer *peer,
|
|||||||
* to.
|
* to.
|
||||||
* - MAY not set `upgradable` if it would be empty.
|
* - MAY not set `upgradable` if it would be empty.
|
||||||
*/
|
*/
|
||||||
send_tlvs->current_type
|
send_tlvs->current_type = tal_dup(send_tlvs, struct channel_type,
|
||||||
= current_channel_type(send_tlvs, peer->channel);
|
peer->channel->type);
|
||||||
send_tlvs->upgradable = channel_upgradable_types(send_tlvs,
|
send_tlvs->upgradable = channel_upgradable_types(send_tlvs,
|
||||||
peer->channel);
|
peer->channel);
|
||||||
}
|
}
|
||||||
@@ -2770,7 +2773,7 @@ static void peer_reconnect(struct peer *peer,
|
|||||||
* - MUST set `your_last_per_commitment_secret` to the last
|
* - MUST set `your_last_per_commitment_secret` to the last
|
||||||
* `per_commitment_secret` it received
|
* `per_commitment_secret` it received
|
||||||
*/
|
*/
|
||||||
if (peer->channel->option_static_remotekey) {
|
if (channel_has(peer->channel, OPT_STATIC_REMOTEKEY)) {
|
||||||
msg = towire_channel_reestablish
|
msg = towire_channel_reestablish
|
||||||
(NULL, &peer->channel_id,
|
(NULL, &peer->channel_id,
|
||||||
peer->next_index[LOCAL],
|
peer->next_index[LOCAL],
|
||||||
@@ -2933,7 +2936,9 @@ got_reestablish:
|
|||||||
check_future_dataloss_fields(peer,
|
check_future_dataloss_fields(peer,
|
||||||
next_revocation_number,
|
next_revocation_number,
|
||||||
&last_local_per_commitment_secret,
|
&last_local_per_commitment_secret,
|
||||||
peer->channel->option_static_remotekey ? NULL :
|
channel_has(peer->channel,
|
||||||
|
OPT_STATIC_REMOTEKEY)
|
||||||
|
? NULL :
|
||||||
&remote_current_per_commitment_point);
|
&remote_current_per_commitment_point);
|
||||||
} else
|
} else
|
||||||
retransmit_revoke_and_ack = false;
|
retransmit_revoke_and_ack = false;
|
||||||
@@ -2981,7 +2986,8 @@ got_reestablish:
|
|||||||
next_revocation_number,
|
next_revocation_number,
|
||||||
next_commitment_number,
|
next_commitment_number,
|
||||||
&last_local_per_commitment_secret,
|
&last_local_per_commitment_secret,
|
||||||
peer->channel->option_static_remotekey
|
channel_has(peer->channel,
|
||||||
|
OPT_STATIC_REMOTEKEY)
|
||||||
? NULL
|
? NULL
|
||||||
: &remote_current_per_commitment_point);
|
: &remote_current_per_commitment_point);
|
||||||
|
|
||||||
@@ -3641,6 +3647,7 @@ static void init_channel(struct peer *peer)
|
|||||||
bool option_static_remotekey, option_anchor_outputs;
|
bool option_static_remotekey, option_anchor_outputs;
|
||||||
struct penalty_base *pbases;
|
struct penalty_base *pbases;
|
||||||
u8 *reestablish_only;
|
u8 *reestablish_only;
|
||||||
|
struct channel_type *channel_type;
|
||||||
#if !DEVELOPER
|
#if !DEVELOPER
|
||||||
bool dev_fail_process_onionpacket; /* Ignored */
|
bool dev_fail_process_onionpacket; /* Ignored */
|
||||||
#endif
|
#endif
|
||||||
@@ -3766,6 +3773,14 @@ static void init_channel(struct peer *peer)
|
|||||||
get_per_commitment_point(peer->next_index[LOCAL],
|
get_per_commitment_point(peer->next_index[LOCAL],
|
||||||
&peer->next_local_per_commit, NULL);
|
&peer->next_local_per_commit, NULL);
|
||||||
|
|
||||||
|
/* FIXME: hand type directly from lightningd! */
|
||||||
|
if (option_anchor_outputs)
|
||||||
|
channel_type = channel_type_anchor_outputs(NULL);
|
||||||
|
else if (option_static_remotekey)
|
||||||
|
channel_type = channel_type_static_remotekey(NULL);
|
||||||
|
else
|
||||||
|
channel_type = channel_type_none(NULL);
|
||||||
|
|
||||||
peer->channel = new_full_channel(peer, &peer->channel_id,
|
peer->channel = new_full_channel(peer, &peer->channel_id,
|
||||||
&funding_txid,
|
&funding_txid,
|
||||||
funding_txout,
|
funding_txout,
|
||||||
@@ -3779,8 +3794,7 @@ static void init_channel(struct peer *peer)
|
|||||||
&points[LOCAL], &points[REMOTE],
|
&points[LOCAL], &points[REMOTE],
|
||||||
&funding_pubkey[LOCAL],
|
&funding_pubkey[LOCAL],
|
||||||
&funding_pubkey[REMOTE],
|
&funding_pubkey[REMOTE],
|
||||||
option_static_remotekey,
|
take(channel_type),
|
||||||
option_anchor_outputs,
|
|
||||||
feature_offered(peer->their_features,
|
feature_offered(peer->their_features,
|
||||||
OPT_LARGE_CHANNELS),
|
OPT_LARGE_CHANNELS),
|
||||||
opener);
|
opener);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <channeld/full_channel.h>
|
#include <channeld/full_channel.h>
|
||||||
#include <common/blockheight_states.h>
|
#include <common/blockheight_states.h>
|
||||||
#include <common/channel_config.h>
|
#include <common/channel_config.h>
|
||||||
|
#include <common/features.h>
|
||||||
#include <common/fee_states.h>
|
#include <common/fee_states.h>
|
||||||
#include <common/htlc.h>
|
#include <common/htlc.h>
|
||||||
#include <common/htlc_trim.h>
|
#include <common/htlc_trim.h>
|
||||||
@@ -100,15 +101,14 @@ struct channel *new_full_channel(const tal_t *ctx,
|
|||||||
u32 lease_expiry,
|
u32 lease_expiry,
|
||||||
struct amount_sat funding,
|
struct amount_sat funding,
|
||||||
struct amount_msat local_msat,
|
struct amount_msat local_msat,
|
||||||
const struct fee_states *fee_states,
|
const struct fee_states *fee_states TAKES,
|
||||||
const struct channel_config *local,
|
const struct channel_config *local,
|
||||||
const struct channel_config *remote,
|
const struct channel_config *remote,
|
||||||
const struct basepoints *local_basepoints,
|
const struct basepoints *local_basepoints,
|
||||||
const struct basepoints *remote_basepoints,
|
const struct basepoints *remote_basepoints,
|
||||||
const struct pubkey *local_funding_pubkey,
|
const struct pubkey *local_funding_pubkey,
|
||||||
const struct pubkey *remote_funding_pubkey,
|
const struct pubkey *remote_funding_pubkey,
|
||||||
bool option_static_remotekey,
|
const struct channel_type *type TAKES,
|
||||||
bool option_anchor_outputs,
|
|
||||||
bool option_wumbo,
|
bool option_wumbo,
|
||||||
enum side opener)
|
enum side opener)
|
||||||
{
|
{
|
||||||
@@ -127,8 +127,7 @@ struct channel *new_full_channel(const tal_t *ctx,
|
|||||||
remote_basepoints,
|
remote_basepoints,
|
||||||
local_funding_pubkey,
|
local_funding_pubkey,
|
||||||
remote_funding_pubkey,
|
remote_funding_pubkey,
|
||||||
option_static_remotekey,
|
type,
|
||||||
option_anchor_outputs,
|
|
||||||
option_wumbo,
|
option_wumbo,
|
||||||
opener);
|
opener);
|
||||||
|
|
||||||
@@ -262,6 +261,7 @@ static void add_htlcs(struct bitcoin_tx ***txs,
|
|||||||
size_t i;
|
size_t i;
|
||||||
struct bitcoin_txid txid;
|
struct bitcoin_txid txid;
|
||||||
u32 feerate_per_kw = channel_feerate(channel, side);
|
u32 feerate_per_kw = channel_feerate(channel, side);
|
||||||
|
bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS);
|
||||||
|
|
||||||
/* Get txid of commitment transaction */
|
/* Get txid of commitment transaction */
|
||||||
bitcoin_txid((*txs)[0], &txid);
|
bitcoin_txid((*txs)[0], &txid);
|
||||||
@@ -278,7 +278,7 @@ static void add_htlcs(struct bitcoin_tx ***txs,
|
|||||||
if (htlc_owner(htlc) == side) {
|
if (htlc_owner(htlc) == side) {
|
||||||
ripemd160(&ripemd, htlc->rhash.u.u8, sizeof(htlc->rhash.u.u8));
|
ripemd160(&ripemd, htlc->rhash.u.u8, sizeof(htlc->rhash.u.u8));
|
||||||
wscript = htlc_offered_wscript(tmpctx, &ripemd, keyset,
|
wscript = htlc_offered_wscript(tmpctx, &ripemd, keyset,
|
||||||
channel->option_anchor_outputs);
|
option_anchor_outputs);
|
||||||
tx = htlc_timeout_tx(*txs, chainparams, &txid, i,
|
tx = htlc_timeout_tx(*txs, chainparams, &txid, i,
|
||||||
wscript,
|
wscript,
|
||||||
htlc->amount,
|
htlc->amount,
|
||||||
@@ -286,19 +286,19 @@ static void add_htlcs(struct bitcoin_tx ***txs,
|
|||||||
channel->config[!side].to_self_delay,
|
channel->config[!side].to_self_delay,
|
||||||
feerate_per_kw,
|
feerate_per_kw,
|
||||||
keyset,
|
keyset,
|
||||||
channel->option_anchor_outputs);
|
option_anchor_outputs);
|
||||||
} else {
|
} else {
|
||||||
ripemd160(&ripemd, htlc->rhash.u.u8, sizeof(htlc->rhash.u.u8));
|
ripemd160(&ripemd, htlc->rhash.u.u8, sizeof(htlc->rhash.u.u8));
|
||||||
wscript = htlc_received_wscript(tmpctx, &ripemd,
|
wscript = htlc_received_wscript(tmpctx, &ripemd,
|
||||||
&htlc->expiry, keyset,
|
&htlc->expiry, keyset,
|
||||||
channel->option_anchor_outputs);
|
option_anchor_outputs);
|
||||||
tx = htlc_success_tx(*txs, chainparams, &txid, i,
|
tx = htlc_success_tx(*txs, chainparams, &txid, i,
|
||||||
wscript,
|
wscript,
|
||||||
htlc->amount,
|
htlc->amount,
|
||||||
channel->config[!side].to_self_delay,
|
channel->config[!side].to_self_delay,
|
||||||
feerate_per_kw,
|
feerate_per_kw,
|
||||||
keyset,
|
keyset,
|
||||||
channel->option_anchor_outputs);
|
option_anchor_outputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Append to array. */
|
/* Append to array. */
|
||||||
@@ -323,7 +323,7 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
|
|||||||
if (!derive_keyset(per_commitment_point,
|
if (!derive_keyset(per_commitment_point,
|
||||||
&channel->basepoints[side],
|
&channel->basepoints[side],
|
||||||
&channel->basepoints[!side],
|
&channel->basepoints[!side],
|
||||||
channel->option_static_remotekey,
|
channel_has(channel, OPT_STATIC_REMOTEKEY),
|
||||||
&keyset))
|
&keyset))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -350,7 +350,7 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
|
|||||||
channel->config[side].dust_limit, channel->view[side].owed[side],
|
channel->config[side].dust_limit, channel->view[side].owed[side],
|
||||||
channel->view[side].owed[!side], committed, htlcmap, direct_outputs,
|
channel->view[side].owed[!side], committed, htlcmap, direct_outputs,
|
||||||
commitment_number ^ channel->commitment_number_obscurer,
|
commitment_number ^ channel->commitment_number_obscurer,
|
||||||
channel->option_anchor_outputs,
|
channel_has(channel, OPT_ANCHOR_OUTPUTS),
|
||||||
side);
|
side);
|
||||||
|
|
||||||
/* Set the remote/local pubkeys on the commitment tx psbt */
|
/* Set the remote/local pubkeys on the commitment tx psbt */
|
||||||
@@ -431,13 +431,13 @@ static struct amount_sat fee_for_htlcs(const struct channel *channel,
|
|||||||
u32 feerate = channel_feerate(channel, side);
|
u32 feerate = channel_feerate(channel, side);
|
||||||
struct amount_sat dust_limit = channel->config[side].dust_limit;
|
struct amount_sat dust_limit = channel->config[side].dust_limit;
|
||||||
size_t untrimmed;
|
size_t untrimmed;
|
||||||
|
bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS);
|
||||||
|
|
||||||
untrimmed = num_untrimmed_htlcs(side, dust_limit, feerate,
|
untrimmed = num_untrimmed_htlcs(side, dust_limit, feerate,
|
||||||
channel->option_anchor_outputs,
|
option_anchor_outputs,
|
||||||
committed, adding, removing);
|
committed, adding, removing);
|
||||||
|
|
||||||
return commit_tx_base_fee(feerate, untrimmed,
|
return commit_tx_base_fee(feerate, untrimmed, option_anchor_outputs);
|
||||||
channel->option_anchor_outputs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -474,6 +474,7 @@ static bool local_opener_has_fee_headroom(const struct channel *channel,
|
|||||||
u32 feerate = channel_feerate(channel, LOCAL);
|
u32 feerate = channel_feerate(channel, LOCAL);
|
||||||
size_t untrimmed;
|
size_t untrimmed;
|
||||||
struct amount_sat fee;
|
struct amount_sat fee;
|
||||||
|
bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS);
|
||||||
|
|
||||||
assert(channel->opener == LOCAL);
|
assert(channel->opener == LOCAL);
|
||||||
|
|
||||||
@@ -481,13 +482,13 @@ static bool local_opener_has_fee_headroom(const struct channel *channel,
|
|||||||
* only *reduce* this number, so use current feerate here! */
|
* only *reduce* this number, so use current feerate here! */
|
||||||
untrimmed = num_untrimmed_htlcs(LOCAL, channel->config[LOCAL].dust_limit,
|
untrimmed = num_untrimmed_htlcs(LOCAL, channel->config[LOCAL].dust_limit,
|
||||||
feerate,
|
feerate,
|
||||||
channel->option_anchor_outputs,
|
option_anchor_outputs,
|
||||||
committed, adding, removing);
|
committed, adding, removing);
|
||||||
|
|
||||||
/* Now, how much would it cost us if feerate increases 100% and we added
|
/* Now, how much would it cost us if feerate increases 100% and we added
|
||||||
* another HTLC? */
|
* another HTLC? */
|
||||||
fee = commit_tx_base_fee(2 * feerate, untrimmed + 1,
|
fee = commit_tx_base_fee(2 * feerate, untrimmed + 1,
|
||||||
channel->option_anchor_outputs);
|
option_anchor_outputs);
|
||||||
if (amount_msat_greater_eq_sat(remainder, fee))
|
if (amount_msat_greater_eq_sat(remainder, fee))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -517,6 +518,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
|
|||||||
const struct htlc **committed, **adding, **removing;
|
const struct htlc **committed, **adding, **removing;
|
||||||
const struct channel_view *view;
|
const struct channel_view *view;
|
||||||
size_t htlc_count;
|
size_t htlc_count;
|
||||||
|
bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS);
|
||||||
|
|
||||||
htlc = tal(tmpctx, struct htlc);
|
htlc = tal(tmpctx, struct htlc);
|
||||||
|
|
||||||
@@ -685,7 +687,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
|
|||||||
* of 330 sats from the funder (either `to_local` or
|
* of 330 sats from the funder (either `to_local` or
|
||||||
* `to_remote`).
|
* `to_remote`).
|
||||||
*/
|
*/
|
||||||
if (channel->option_anchor_outputs
|
if (option_anchor_outputs
|
||||||
&& channel->opener == sender
|
&& channel->opener == sender
|
||||||
&& !amount_msat_sub_sat(&remainder, remainder, AMOUNT_SAT(660)))
|
&& !amount_msat_sub_sat(&remainder, remainder, AMOUNT_SAT(660)))
|
||||||
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
|
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
|
||||||
@@ -719,7 +721,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
|
|||||||
&remainder))
|
&remainder))
|
||||||
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
|
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
|
||||||
|
|
||||||
if (channel->option_anchor_outputs
|
if (option_anchor_outputs
|
||||||
&& channel->opener != sender
|
&& channel->opener != sender
|
||||||
&& !amount_msat_sub_sat(&remainder, remainder, AMOUNT_SAT(660)))
|
&& !amount_msat_sub_sat(&remainder, remainder, AMOUNT_SAT(660)))
|
||||||
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
|
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
|
||||||
@@ -1089,6 +1091,7 @@ u32 approx_max_feerate(const struct channel *channel)
|
|||||||
u64 weight;
|
u64 weight;
|
||||||
struct amount_sat avail;
|
struct amount_sat avail;
|
||||||
const struct htlc **committed, **adding, **removing;
|
const struct htlc **committed, **adding, **removing;
|
||||||
|
bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS);
|
||||||
|
|
||||||
gather_htlcs(tmpctx, channel, !channel->opener,
|
gather_htlcs(tmpctx, channel, !channel->opener,
|
||||||
&committed, &removing, &adding);
|
&committed, &removing, &adding);
|
||||||
@@ -1096,7 +1099,7 @@ u32 approx_max_feerate(const struct channel *channel)
|
|||||||
/* Assume none are trimmed; this gives lower bound on feerate. */
|
/* Assume none are trimmed; this gives lower bound on feerate. */
|
||||||
num = tal_count(committed) + tal_count(adding) - tal_count(removing);
|
num = tal_count(committed) + tal_count(adding) - tal_count(removing);
|
||||||
|
|
||||||
weight = commit_tx_base_weight(num, channel->option_anchor_outputs);
|
weight = commit_tx_base_weight(num, option_anchor_outputs);
|
||||||
|
|
||||||
/* Available is their view */
|
/* Available is their view */
|
||||||
avail = amount_msat_to_sat_round_down(channel->view[!channel->opener].owed[channel->opener]);
|
avail = amount_msat_to_sat_round_down(channel->view[!channel->opener].owed[channel->opener]);
|
||||||
@@ -1107,7 +1110,7 @@ u32 approx_max_feerate(const struct channel *channel)
|
|||||||
* of 330 sats from the funder (either `to_local` or
|
* of 330 sats from the funder (either `to_local` or
|
||||||
* `to_remote`).
|
* `to_remote`).
|
||||||
*/
|
*/
|
||||||
if (channel->option_anchor_outputs
|
if (option_anchor_outputs
|
||||||
&& !amount_sat_sub(&avail, avail, AMOUNT_SAT(660))) {
|
&& !amount_sat_sub(&avail, avail, AMOUNT_SAT(660))) {
|
||||||
avail = AMOUNT_SAT(0);
|
avail = AMOUNT_SAT(0);
|
||||||
} else {
|
} else {
|
||||||
@@ -1126,21 +1129,23 @@ bool can_opener_afford_feerate(const struct channel *channel, u32 feerate_per_kw
|
|||||||
struct amount_sat dust_limit = channel->config[!channel->opener].dust_limit;
|
struct amount_sat dust_limit = channel->config[!channel->opener].dust_limit;
|
||||||
size_t untrimmed;
|
size_t untrimmed;
|
||||||
const struct htlc **committed, **adding, **removing;
|
const struct htlc **committed, **adding, **removing;
|
||||||
|
bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS);
|
||||||
|
|
||||||
gather_htlcs(tmpctx, channel, !channel->opener,
|
gather_htlcs(tmpctx, channel, !channel->opener,
|
||||||
&committed, &removing, &adding);
|
&committed, &removing, &adding);
|
||||||
|
|
||||||
untrimmed = commit_tx_num_untrimmed(committed, feerate_per_kw, dust_limit,
|
untrimmed = commit_tx_num_untrimmed(committed, feerate_per_kw, dust_limit,
|
||||||
channel->option_anchor_outputs,
|
option_anchor_outputs,
|
||||||
!channel->opener)
|
!channel->opener)
|
||||||
+ commit_tx_num_untrimmed(adding, feerate_per_kw, dust_limit,
|
+ commit_tx_num_untrimmed(adding, feerate_per_kw, dust_limit,
|
||||||
channel->option_anchor_outputs,
|
option_anchor_outputs,
|
||||||
!channel->opener)
|
!channel->opener)
|
||||||
- commit_tx_num_untrimmed(removing, feerate_per_kw, dust_limit,
|
- commit_tx_num_untrimmed(removing, feerate_per_kw, dust_limit,
|
||||||
channel->option_anchor_outputs,
|
option_anchor_outputs,
|
||||||
!channel->opener);
|
!channel->opener);
|
||||||
|
|
||||||
fee = commit_tx_base_fee(feerate_per_kw, untrimmed,
|
fee = commit_tx_base_fee(feerate_per_kw, untrimmed,
|
||||||
channel->option_anchor_outputs);
|
option_anchor_outputs);
|
||||||
|
|
||||||
/* BOLT #3:
|
/* BOLT #3:
|
||||||
* If `option_anchors` applies to the commitment
|
* If `option_anchors` applies to the commitment
|
||||||
@@ -1148,7 +1153,7 @@ bool can_opener_afford_feerate(const struct channel *channel, u32 feerate_per_kw
|
|||||||
* of 330 sats from the funder (either `to_local` or
|
* of 330 sats from the funder (either `to_local` or
|
||||||
* `to_remote`).
|
* `to_remote`).
|
||||||
*/
|
*/
|
||||||
if (channel->option_anchor_outputs
|
if (option_anchor_outputs
|
||||||
&& !amount_sat_add(&fee, fee, AMOUNT_SAT(660)))
|
&& !amount_sat_add(&fee, fee, AMOUNT_SAT(660)))
|
||||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||||
"Cannot add 660 sats to %s for anchor",
|
"Cannot add 660 sats to %s for anchor",
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ struct existing_htlc;
|
|||||||
* @remote_basepoints: remote basepoints.
|
* @remote_basepoints: remote basepoints.
|
||||||
* @local_fundingkey: local funding key
|
* @local_fundingkey: local funding key
|
||||||
* @remote_fundingkey: remote funding key
|
* @remote_fundingkey: remote funding key
|
||||||
* @option_static_remotekey: use `option_static_remotekey`.
|
* @type: type for this channel
|
||||||
* @option_anchor_outputs: use `option_anchor_outputs`.
|
|
||||||
* @option_wumbo: large channel negotiated.
|
* @option_wumbo: large channel negotiated.
|
||||||
* @opener: which side initiated it.
|
* @opener: which side initiated it.
|
||||||
*
|
*
|
||||||
@@ -44,15 +43,14 @@ struct channel *new_full_channel(const tal_t *ctx,
|
|||||||
u32 lease_expiry,
|
u32 lease_expiry,
|
||||||
struct amount_sat funding,
|
struct amount_sat funding,
|
||||||
struct amount_msat local_msat,
|
struct amount_msat local_msat,
|
||||||
const struct fee_states *fee_states,
|
const struct fee_states *fee_states TAKES,
|
||||||
const struct channel_config *local,
|
const struct channel_config *local,
|
||||||
const struct channel_config *remote,
|
const struct channel_config *remote,
|
||||||
const struct basepoints *local_basepoints,
|
const struct basepoints *local_basepoints,
|
||||||
const struct basepoints *remote_basepoints,
|
const struct basepoints *remote_basepoints,
|
||||||
const struct pubkey *local_funding_pubkey,
|
const struct pubkey *local_funding_pubkey,
|
||||||
const struct pubkey *remote_funding_pubkey,
|
const struct pubkey *remote_funding_pubkey,
|
||||||
bool option_static_remotekey,
|
const struct channel_type *type TAKES,
|
||||||
bool option_anchor_outputs,
|
|
||||||
bool option_wumbo,
|
bool option_wumbo,
|
||||||
enum side opener);
|
enum side opener);
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ CHANNELD_TEST_COMMON_OBJS := \
|
|||||||
common/amount.o \
|
common/amount.o \
|
||||||
common/channel_type.o \
|
common/channel_type.o \
|
||||||
common/daemon_conn.o \
|
common/daemon_conn.o \
|
||||||
|
common/features.o \
|
||||||
common/htlc_state.o \
|
common/htlc_state.o \
|
||||||
common/htlc_trim.o \
|
common/htlc_trim.o \
|
||||||
common/htlc_tx.o \
|
common/htlc_tx.o \
|
||||||
|
|||||||
@@ -23,19 +23,6 @@ static bool print_superverbose;
|
|||||||
/*#define DEBUG */
|
/*#define DEBUG */
|
||||||
|
|
||||||
/* AUTOGENERATED MOCKS START */
|
/* AUTOGENERATED MOCKS START */
|
||||||
/* Generated stub for feature_is_set */
|
|
||||||
bool feature_is_set(const u8 *features UNNEEDED, size_t bit UNNEEDED)
|
|
||||||
{ fprintf(stderr, "feature_is_set called!\n"); abort(); }
|
|
||||||
/* Generated stub for feature_negotiated */
|
|
||||||
bool feature_negotiated(const struct feature_set *our_features UNNEEDED,
|
|
||||||
const u8 *their_features UNNEEDED, size_t f UNNEEDED)
|
|
||||||
{ fprintf(stderr, "feature_negotiated called!\n"); abort(); }
|
|
||||||
/* Generated stub for feature_offered */
|
|
||||||
bool feature_offered(const u8 *features UNNEEDED, size_t f UNNEEDED)
|
|
||||||
{ fprintf(stderr, "feature_offered called!\n"); abort(); }
|
|
||||||
/* Generated stub for featurebits_eq */
|
|
||||||
bool featurebits_eq(const u8 *f1 UNNEEDED, const u8 *f2 UNNEEDED)
|
|
||||||
{ fprintf(stderr, "featurebits_eq called!\n"); abort(); }
|
|
||||||
/* Generated stub for fromwire_bigsize */
|
/* Generated stub for fromwire_bigsize */
|
||||||
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
|
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
|
||||||
@@ -46,9 +33,6 @@ void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
|
|||||||
/* Generated stub for fromwire_node_id */
|
/* Generated stub for fromwire_node_id */
|
||||||
void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED)
|
void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire_node_id called!\n"); abort(); }
|
{ fprintf(stderr, "fromwire_node_id called!\n"); abort(); }
|
||||||
/* Generated stub for set_feature_bit */
|
|
||||||
void set_feature_bit(u8 **ptr UNNEEDED, u32 bit UNNEEDED)
|
|
||||||
{ fprintf(stderr, "set_feature_bit called!\n"); abort(); }
|
|
||||||
/* Generated stub for status_fmt */
|
/* Generated stub for status_fmt */
|
||||||
void status_fmt(enum log_level level UNNEEDED,
|
void status_fmt(enum log_level level UNNEEDED,
|
||||||
const struct node_id *peer UNNEEDED,
|
const struct node_id *peer UNNEEDED,
|
||||||
|
|||||||
@@ -18,19 +18,6 @@
|
|||||||
#include <wally_core.h>
|
#include <wally_core.h>
|
||||||
|
|
||||||
/* AUTOGENERATED MOCKS START */
|
/* AUTOGENERATED MOCKS START */
|
||||||
/* Generated stub for feature_is_set */
|
|
||||||
bool feature_is_set(const u8 *features UNNEEDED, size_t bit UNNEEDED)
|
|
||||||
{ fprintf(stderr, "feature_is_set called!\n"); abort(); }
|
|
||||||
/* Generated stub for feature_negotiated */
|
|
||||||
bool feature_negotiated(const struct feature_set *our_features UNNEEDED,
|
|
||||||
const u8 *their_features UNNEEDED, size_t f UNNEEDED)
|
|
||||||
{ fprintf(stderr, "feature_negotiated called!\n"); abort(); }
|
|
||||||
/* Generated stub for feature_offered */
|
|
||||||
bool feature_offered(const u8 *features UNNEEDED, size_t f UNNEEDED)
|
|
||||||
{ fprintf(stderr, "feature_offered called!\n"); abort(); }
|
|
||||||
/* Generated stub for featurebits_eq */
|
|
||||||
bool featurebits_eq(const u8 *f1 UNNEEDED, const u8 *f2 UNNEEDED)
|
|
||||||
{ fprintf(stderr, "featurebits_eq called!\n"); abort(); }
|
|
||||||
/* Generated stub for fromwire_bigsize */
|
/* Generated stub for fromwire_bigsize */
|
||||||
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
|
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
|
||||||
@@ -43,9 +30,6 @@ void memleak_add_helper_(const tal_t *p UNNEEDED, void (*cb)(struct htable *memt
|
|||||||
/* Generated stub for memleak_remove_htable */
|
/* Generated stub for memleak_remove_htable */
|
||||||
void memleak_remove_htable(struct htable *memtable UNNEEDED, const struct htable *ht UNNEEDED)
|
void memleak_remove_htable(struct htable *memtable UNNEEDED, const struct htable *ht UNNEEDED)
|
||||||
{ fprintf(stderr, "memleak_remove_htable called!\n"); abort(); }
|
{ fprintf(stderr, "memleak_remove_htable called!\n"); abort(); }
|
||||||
/* Generated stub for set_feature_bit */
|
|
||||||
void set_feature_bit(u8 **ptr UNNEEDED, u32 bit UNNEEDED)
|
|
||||||
{ fprintf(stderr, "set_feature_bit called!\n"); abort(); }
|
|
||||||
/* Generated stub for status_failed */
|
/* Generated stub for status_failed */
|
||||||
void status_failed(enum status_failreason code UNNEEDED,
|
void status_failed(enum status_failreason code UNNEEDED,
|
||||||
const char *fmt UNNEEDED, ...)
|
const char *fmt UNNEEDED, ...)
|
||||||
@@ -506,7 +490,7 @@ int main(int argc, const char *argv[])
|
|||||||
&localbase, &remotebase,
|
&localbase, &remotebase,
|
||||||
&local_funding_pubkey,
|
&local_funding_pubkey,
|
||||||
&remote_funding_pubkey,
|
&remote_funding_pubkey,
|
||||||
false, false, false, LOCAL);
|
take(channel_type_none(NULL)), false, LOCAL);
|
||||||
rchannel = new_full_channel(tmpctx, &cid,
|
rchannel = new_full_channel(tmpctx, &cid,
|
||||||
&funding_txid, funding_output_index, 0,
|
&funding_txid, funding_output_index, 0,
|
||||||
take(new_height_states(NULL, REMOTE, &blockheight)),
|
take(new_height_states(NULL, REMOTE, &blockheight)),
|
||||||
@@ -519,7 +503,7 @@ int main(int argc, const char *argv[])
|
|||||||
&remotebase, &localbase,
|
&remotebase, &localbase,
|
||||||
&remote_funding_pubkey,
|
&remote_funding_pubkey,
|
||||||
&local_funding_pubkey,
|
&local_funding_pubkey,
|
||||||
false, false, false, REMOTE);
|
take(channel_type_none(NULL)), false, REMOTE);
|
||||||
|
|
||||||
/* BOLT #3:
|
/* BOLT #3:
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <bitcoin/script.h>
|
#include <bitcoin/script.h>
|
||||||
#include <bitcoin/signature.h>
|
#include <bitcoin/signature.h>
|
||||||
#include <bitcoin/tx.h>
|
#include <bitcoin/tx.h>
|
||||||
|
#include <common/features.h>
|
||||||
#include <common/htlc_tx.h>
|
#include <common/htlc_tx.h>
|
||||||
#include <common/key_derive.h>
|
#include <common/key_derive.h>
|
||||||
#include <common/keyset.h>
|
#include <common/keyset.h>
|
||||||
@@ -32,7 +33,7 @@ penalty_tx_create(const tal_t *ctx,
|
|||||||
struct amount_sat fee, min_out, amt;
|
struct amount_sat fee, min_out, amt;
|
||||||
struct bitcoin_signature sig;
|
struct bitcoin_signature sig;
|
||||||
u32 locktime = 0;
|
u32 locktime = 0;
|
||||||
bool option_static_remotekey = channel->option_static_remotekey;
|
bool option_static_remotekey = channel_has(channel, OPT_STATIC_REMOTEKEY);
|
||||||
u8 **witness;
|
u8 **witness;
|
||||||
u32 remote_to_self_delay = channel->config[REMOTE].to_self_delay;
|
u32 remote_to_self_delay = channel->config[REMOTE].to_self_delay;
|
||||||
const struct amount_sat dust_limit = channel->config[LOCAL].dust_limit;
|
const struct amount_sat dust_limit = channel->config[LOCAL].dust_limit;
|
||||||
|
|||||||
@@ -33,8 +33,7 @@ struct channel *new_initial_channel(const tal_t *ctx,
|
|||||||
const struct basepoints *remote_basepoints,
|
const struct basepoints *remote_basepoints,
|
||||||
const struct pubkey *local_funding_pubkey,
|
const struct pubkey *local_funding_pubkey,
|
||||||
const struct pubkey *remote_funding_pubkey,
|
const struct pubkey *remote_funding_pubkey,
|
||||||
bool option_static_remotekey,
|
const struct channel_type *type TAKES,
|
||||||
bool option_anchor_outputs,
|
|
||||||
bool option_wumbo,
|
bool option_wumbo,
|
||||||
enum side opener)
|
enum side opener)
|
||||||
{
|
{
|
||||||
@@ -82,11 +81,10 @@ struct channel *new_initial_channel(const tal_t *ctx,
|
|||||||
= commit_number_obscurer(&channel->basepoints[opener].payment,
|
= commit_number_obscurer(&channel->basepoints[opener].payment,
|
||||||
&channel->basepoints[!opener].payment);
|
&channel->basepoints[!opener].payment);
|
||||||
|
|
||||||
channel->option_static_remotekey = option_static_remotekey;
|
|
||||||
channel->option_anchor_outputs = option_anchor_outputs;
|
|
||||||
channel->option_wumbo = option_wumbo;
|
channel->option_wumbo = option_wumbo;
|
||||||
if (option_anchor_outputs)
|
/* takes() if necessary */
|
||||||
assert(option_static_remotekey);
|
channel->type = tal_dup(channel, struct channel_type, type);
|
||||||
|
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +107,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
|
|||||||
if (!derive_keyset(per_commitment_point,
|
if (!derive_keyset(per_commitment_point,
|
||||||
&channel->basepoints[side],
|
&channel->basepoints[side],
|
||||||
&channel->basepoints[!side],
|
&channel->basepoints[!side],
|
||||||
channel->option_static_remotekey,
|
channel_has(channel, OPT_STATIC_REMOTEKEY),
|
||||||
&keyset)) {
|
&keyset)) {
|
||||||
*err_reason = "Cannot derive keyset";
|
*err_reason = "Cannot derive keyset";
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -145,7 +143,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
|
|||||||
0 ^ channel->commitment_number_obscurer,
|
0 ^ channel->commitment_number_obscurer,
|
||||||
direct_outputs,
|
direct_outputs,
|
||||||
side, csv_lock,
|
side, csv_lock,
|
||||||
channel->option_anchor_outputs,
|
channel_has(channel, OPT_ANCHOR_OUTPUTS),
|
||||||
err_reason);
|
err_reason);
|
||||||
|
|
||||||
if (init_tx) {
|
if (init_tx) {
|
||||||
@@ -169,23 +167,12 @@ u32 channel_blockheight(const struct channel *channel, enum side side)
|
|||||||
channel->opener, side);
|
channel->opener, side);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct channel_type *current_channel_type(const tal_t *ctx,
|
|
||||||
const struct channel *channel)
|
|
||||||
{
|
|
||||||
if (channel->option_anchor_outputs)
|
|
||||||
return channel_type_anchor_outputs(ctx);
|
|
||||||
if (channel->option_static_remotekey)
|
|
||||||
return channel_type_static_remotekey(ctx);
|
|
||||||
|
|
||||||
return channel_type_none(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct channel_type **channel_upgradable_types(const tal_t *ctx,
|
struct channel_type **channel_upgradable_types(const tal_t *ctx,
|
||||||
const struct channel *channel)
|
const struct channel *channel)
|
||||||
{
|
{
|
||||||
struct channel_type **arr = tal_arr(ctx, struct channel_type *, 0);
|
struct channel_type **arr = tal_arr(ctx, struct channel_type *, 0);
|
||||||
|
|
||||||
if (!channel->option_static_remotekey)
|
if (!channel_has(channel, OPT_STATIC_REMOTEKEY))
|
||||||
tal_arr_expand(&arr, channel_type_static_remotekey(arr));
|
tal_arr_expand(&arr, channel_type_static_remotekey(arr));
|
||||||
|
|
||||||
return arr;
|
return arr;
|
||||||
@@ -195,13 +182,18 @@ struct channel_type *channel_desired_type(const tal_t *ctx,
|
|||||||
const struct channel *channel)
|
const struct channel *channel)
|
||||||
{
|
{
|
||||||
/* We don't actually want to downgrade anchors! */
|
/* We don't actually want to downgrade anchors! */
|
||||||
if (channel->option_anchor_outputs)
|
if (channel_has(channel, OPT_ANCHOR_OUTPUTS))
|
||||||
return channel_type_anchor_outputs(ctx);
|
return channel_type_anchor_outputs(ctx);
|
||||||
|
|
||||||
/* For now, we just want option_static_remotekey */
|
/* For now, we just want option_static_remotekey */
|
||||||
return channel_type_static_remotekey(ctx);
|
return channel_type_static_remotekey(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool channel_has(const struct channel *channel, int feature)
|
||||||
|
{
|
||||||
|
return channel_type_has(channel->type, feature);
|
||||||
|
}
|
||||||
|
|
||||||
static char *fmt_channel_view(const tal_t *ctx, const struct channel_view *view)
|
static char *fmt_channel_view(const tal_t *ctx, const struct channel_view *view)
|
||||||
{
|
{
|
||||||
return tal_fmt(ctx, "{ owed_local=%s,"
|
return tal_fmt(ctx, "{ owed_local=%s,"
|
||||||
|
|||||||
@@ -69,11 +69,8 @@ struct channel {
|
|||||||
/* What it looks like to each side. */
|
/* What it looks like to each side. */
|
||||||
struct channel_view view[NUM_SIDES];
|
struct channel_view view[NUM_SIDES];
|
||||||
|
|
||||||
/* Is this using option_static_remotekey? */
|
/* Features which apply to this channel. */
|
||||||
bool option_static_remotekey;
|
struct channel_type *type;
|
||||||
|
|
||||||
/* Is this using option_anchor_outputs? */
|
|
||||||
bool option_anchor_outputs;
|
|
||||||
|
|
||||||
/* Are we using big channels? */
|
/* Are we using big channels? */
|
||||||
bool option_wumbo;
|
bool option_wumbo;
|
||||||
@@ -100,8 +97,7 @@ struct channel {
|
|||||||
* @remote_basepoints: remote basepoints.
|
* @remote_basepoints: remote basepoints.
|
||||||
* @local_fundingkey: local funding key
|
* @local_fundingkey: local funding key
|
||||||
* @remote_fundingkey: remote funding key
|
* @remote_fundingkey: remote funding key
|
||||||
* @option_static_remotekey: was this created with option_static_remotekey?
|
* @type: type for this channel
|
||||||
* @option_anchor_outputs: was this created with option_anchor_outputs?
|
|
||||||
* @option_wumbo: has peer currently negotiated wumbo?
|
* @option_wumbo: has peer currently negotiated wumbo?
|
||||||
* @opener: which side initiated it.
|
* @opener: which side initiated it.
|
||||||
*
|
*
|
||||||
@@ -123,8 +119,7 @@ struct channel *new_initial_channel(const tal_t *ctx,
|
|||||||
const struct basepoints *remote_basepoints,
|
const struct basepoints *remote_basepoints,
|
||||||
const struct pubkey *local_funding_pubkey,
|
const struct pubkey *local_funding_pubkey,
|
||||||
const struct pubkey *remote_funding_pubkey,
|
const struct pubkey *remote_funding_pubkey,
|
||||||
bool option_static_remotekey,
|
const struct channel_type *type TAKES,
|
||||||
bool option_anchor_outputs,
|
|
||||||
bool option_wumbo,
|
bool option_wumbo,
|
||||||
enum side opener);
|
enum side opener);
|
||||||
|
|
||||||
@@ -167,9 +162,6 @@ u32 channel_blockheight(const struct channel *channel, enum side side);
|
|||||||
* Channel features are explicitly enumerated as `channel_type` bitfields,
|
* Channel features are explicitly enumerated as `channel_type` bitfields,
|
||||||
* using odd features bits.
|
* using odd features bits.
|
||||||
*/
|
*/
|
||||||
struct channel_type *current_channel_type(const tal_t *ctx,
|
|
||||||
const struct channel *channel);
|
|
||||||
|
|
||||||
/* What features can we upgrade? (Returns NULL if none). */
|
/* What features can we upgrade? (Returns NULL if none). */
|
||||||
struct channel_type **channel_upgradable_types(const tal_t *ctx,
|
struct channel_type **channel_upgradable_types(const tal_t *ctx,
|
||||||
const struct channel *channel);
|
const struct channel *channel);
|
||||||
@@ -178,4 +170,6 @@ struct channel_type **channel_upgradable_types(const tal_t *ctx,
|
|||||||
struct channel_type *channel_desired_type(const tal_t *ctx,
|
struct channel_type *channel_desired_type(const tal_t *ctx,
|
||||||
const struct channel *channel);
|
const struct channel *channel);
|
||||||
|
|
||||||
|
/* Convenience for querying channel->type */
|
||||||
|
bool channel_has(const struct channel *channel, int feature);
|
||||||
#endif /* LIGHTNING_COMMON_INITIAL_CHANNEL_H */
|
#endif /* LIGHTNING_COMMON_INITIAL_CHANNEL_H */
|
||||||
|
|||||||
@@ -272,6 +272,7 @@ int main(int argc, char *argv[])
|
|||||||
struct privkey local_htlc_privkey, remote_htlc_privkey;
|
struct privkey local_htlc_privkey, remote_htlc_privkey;
|
||||||
struct pubkey local_htlc_pubkey, remote_htlc_pubkey;
|
struct pubkey local_htlc_pubkey, remote_htlc_pubkey;
|
||||||
bool option_static_remotekey = false, option_anchor_outputs = false;
|
bool option_static_remotekey = false, option_anchor_outputs = false;
|
||||||
|
const struct channel_type *channel_type;
|
||||||
struct sha256_double hash;
|
struct sha256_double hash;
|
||||||
u32 blockheight = 0;
|
u32 blockheight = 0;
|
||||||
|
|
||||||
@@ -394,6 +395,13 @@ int main(int argc, char *argv[])
|
|||||||
/* FIXME: option for v2? */
|
/* FIXME: option for v2? */
|
||||||
derive_channel_id(&cid, &funding_txid, funding_outnum);
|
derive_channel_id(&cid, &funding_txid, funding_outnum);
|
||||||
|
|
||||||
|
if (option_anchor_outputs)
|
||||||
|
channel_type = channel_type_anchor_outputs(NULL);
|
||||||
|
else if (option_static_remotekey)
|
||||||
|
channel_type = channel_type_static_remotekey(NULL);
|
||||||
|
else
|
||||||
|
channel_type = channel_type_none(NULL);
|
||||||
|
|
||||||
channel = new_full_channel(NULL,
|
channel = new_full_channel(NULL,
|
||||||
&cid,
|
&cid,
|
||||||
&funding_txid, funding_outnum, 1,
|
&funding_txid, funding_outnum, 1,
|
||||||
@@ -407,8 +415,7 @@ int main(int argc, char *argv[])
|
|||||||
&localconfig, &remoteconfig,
|
&localconfig, &remoteconfig,
|
||||||
&localbase, &remotebase,
|
&localbase, &remotebase,
|
||||||
&funding_localkey, &funding_remotekey,
|
&funding_localkey, &funding_remotekey,
|
||||||
option_static_remotekey,
|
channel_type,
|
||||||
option_anchor_outputs,
|
|
||||||
false,
|
false,
|
||||||
fee_payer);
|
fee_payer);
|
||||||
|
|
||||||
|
|||||||
@@ -1692,6 +1692,7 @@ static void revert_channel_state(struct state *state)
|
|||||||
struct amount_sat total;
|
struct amount_sat total;
|
||||||
struct amount_msat our_msats;
|
struct amount_msat our_msats;
|
||||||
enum side opener = state->our_role == TX_INITIATOR ? LOCAL : REMOTE;
|
enum side opener = state->our_role == TX_INITIATOR ? LOCAL : REMOTE;
|
||||||
|
const struct channel_type *type;
|
||||||
|
|
||||||
/* We've already checked this */
|
/* We've already checked this */
|
||||||
if (!amount_sat_add(&total, tx_state->opener_funding,
|
if (!amount_sat_add(&total, tx_state->opener_funding,
|
||||||
@@ -1706,6 +1707,8 @@ static void revert_channel_state(struct state *state)
|
|||||||
abort();
|
abort();
|
||||||
|
|
||||||
tal_free(state->channel);
|
tal_free(state->channel);
|
||||||
|
type = default_channel_type(NULL,
|
||||||
|
state->our_features, state->their_features);
|
||||||
state->channel = new_initial_channel(state,
|
state->channel = new_initial_channel(state,
|
||||||
&state->channel_id,
|
&state->channel_id,
|
||||||
&tx_state->funding_txid,
|
&tx_state->funding_txid,
|
||||||
@@ -1725,7 +1728,7 @@ static void revert_channel_state(struct state *state)
|
|||||||
&state->their_points,
|
&state->their_points,
|
||||||
&state->our_funding_pubkey,
|
&state->our_funding_pubkey,
|
||||||
&state->their_funding_pubkey,
|
&state->their_funding_pubkey,
|
||||||
true, true,
|
take(type),
|
||||||
feature_offered(state->their_features,
|
feature_offered(state->their_features,
|
||||||
OPT_LARGE_CHANNELS),
|
OPT_LARGE_CHANNELS),
|
||||||
opener);
|
opener);
|
||||||
@@ -1749,6 +1752,7 @@ static u8 *accepter_commits(struct state *state,
|
|||||||
const u8 *wscript;
|
const u8 *wscript;
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
char *error;
|
char *error;
|
||||||
|
const struct channel_type *type;
|
||||||
|
|
||||||
/* Find the funding transaction txid */
|
/* Find the funding transaction txid */
|
||||||
psbt_txid(NULL, tx_state->psbt, &tx_state->funding_txid, NULL);
|
psbt_txid(NULL, tx_state->psbt, &tx_state->funding_txid, NULL);
|
||||||
@@ -1809,6 +1813,8 @@ static u8 *accepter_commits(struct state *state,
|
|||||||
if (state->channel)
|
if (state->channel)
|
||||||
state->channel = tal_free(state->channel);
|
state->channel = tal_free(state->channel);
|
||||||
|
|
||||||
|
type = default_channel_type(NULL,
|
||||||
|
state->our_features, state->their_features);
|
||||||
state->channel = new_initial_channel(state,
|
state->channel = new_initial_channel(state,
|
||||||
&state->channel_id,
|
&state->channel_id,
|
||||||
&tx_state->funding_txid,
|
&tx_state->funding_txid,
|
||||||
@@ -1829,7 +1835,7 @@ static u8 *accepter_commits(struct state *state,
|
|||||||
&state->their_points,
|
&state->their_points,
|
||||||
&state->our_funding_pubkey,
|
&state->our_funding_pubkey,
|
||||||
&state->their_funding_pubkey,
|
&state->their_funding_pubkey,
|
||||||
true, true,
|
take(type),
|
||||||
feature_offered(state->their_features,
|
feature_offered(state->their_features,
|
||||||
OPT_LARGE_CHANNELS),
|
OPT_LARGE_CHANNELS),
|
||||||
REMOTE);
|
REMOTE);
|
||||||
@@ -2379,6 +2385,7 @@ static u8 *opener_commits(struct state *state,
|
|||||||
const u8 *wscript;
|
const u8 *wscript;
|
||||||
u8 *msg;
|
u8 *msg;
|
||||||
char *error;
|
char *error;
|
||||||
|
const struct channel_type *type;
|
||||||
|
|
||||||
wscript = bitcoin_redeem_2of2(tmpctx, &state->our_funding_pubkey,
|
wscript = bitcoin_redeem_2of2(tmpctx, &state->our_funding_pubkey,
|
||||||
&state->their_funding_pubkey);
|
&state->their_funding_pubkey);
|
||||||
@@ -2421,6 +2428,8 @@ static u8 *opener_commits(struct state *state,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Ok, we're mostly good now? Let's do this */
|
/* Ok, we're mostly good now? Let's do this */
|
||||||
|
type = default_channel_type(NULL,
|
||||||
|
state->our_features, state->their_features);
|
||||||
state->channel = new_initial_channel(state,
|
state->channel = new_initial_channel(state,
|
||||||
&cid,
|
&cid,
|
||||||
&tx_state->funding_txid,
|
&tx_state->funding_txid,
|
||||||
@@ -2439,7 +2448,7 @@ static u8 *opener_commits(struct state *state,
|
|||||||
&state->their_points,
|
&state->their_points,
|
||||||
&state->our_funding_pubkey,
|
&state->our_funding_pubkey,
|
||||||
&state->their_funding_pubkey,
|
&state->their_funding_pubkey,
|
||||||
true, true,
|
take(type),
|
||||||
feature_offered(state->their_features,
|
feature_offered(state->their_features,
|
||||||
OPT_LARGE_CHANNELS),
|
OPT_LARGE_CHANNELS),
|
||||||
/* Opener is local */
|
/* Opener is local */
|
||||||
@@ -3765,6 +3774,7 @@ int main(int argc, char *argv[])
|
|||||||
u8 *msg;
|
u8 *msg;
|
||||||
struct amount_sat total_funding;
|
struct amount_sat total_funding;
|
||||||
struct amount_msat our_msat;
|
struct amount_msat our_msat;
|
||||||
|
const struct channel_type *type;
|
||||||
|
|
||||||
subdaemon_setup(argc, argv);
|
subdaemon_setup(argc, argv);
|
||||||
|
|
||||||
@@ -3847,6 +3857,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
/*~ We only reconnect on channels that the
|
/*~ We only reconnect on channels that the
|
||||||
* saved the the database (exchanged commitment sigs) */
|
* saved the the database (exchanged commitment sigs) */
|
||||||
|
type = default_channel_type(NULL,
|
||||||
|
state->our_features,
|
||||||
|
state->their_features);
|
||||||
state->channel = new_initial_channel(state,
|
state->channel = new_initial_channel(state,
|
||||||
&state->channel_id,
|
&state->channel_id,
|
||||||
&state->tx_state->funding_txid,
|
&state->tx_state->funding_txid,
|
||||||
@@ -3864,7 +3877,7 @@ int main(int argc, char *argv[])
|
|||||||
&state->their_points,
|
&state->their_points,
|
||||||
&state->our_funding_pubkey,
|
&state->our_funding_pubkey,
|
||||||
&state->their_funding_pubkey,
|
&state->their_funding_pubkey,
|
||||||
true, true,
|
take(type),
|
||||||
feature_offered(state->their_features,
|
feature_offered(state->their_features,
|
||||||
OPT_LARGE_CHANNELS),
|
OPT_LARGE_CHANNELS),
|
||||||
opener);
|
opener);
|
||||||
|
|||||||
@@ -502,6 +502,7 @@ static bool funder_finalize_channel_setup(struct state *state,
|
|||||||
struct channel_id cid;
|
struct channel_id cid;
|
||||||
char *err_reason;
|
char *err_reason;
|
||||||
struct wally_tx_output *direct_outputs[NUM_SIDES];
|
struct wally_tx_output *direct_outputs[NUM_SIDES];
|
||||||
|
struct channel_type *type;
|
||||||
|
|
||||||
/*~ Now we can initialize the `struct channel`. This represents
|
/*~ Now we can initialize the `struct channel`. This represents
|
||||||
* the current channel state and is how we can generate the current
|
* the current channel state and is how we can generate the current
|
||||||
@@ -514,6 +515,10 @@ static bool funder_finalize_channel_setup(struct state *state,
|
|||||||
derive_channel_id(&cid,
|
derive_channel_id(&cid,
|
||||||
&state->funding_txid, state->funding_txout);
|
&state->funding_txid, state->funding_txout);
|
||||||
|
|
||||||
|
type = default_channel_type(NULL,
|
||||||
|
state->our_features,
|
||||||
|
state->their_features);
|
||||||
|
|
||||||
state->channel = new_initial_channel(state,
|
state->channel = new_initial_channel(state,
|
||||||
&cid,
|
&cid,
|
||||||
&state->funding_txid,
|
&state->funding_txid,
|
||||||
@@ -530,12 +535,7 @@ static bool funder_finalize_channel_setup(struct state *state,
|
|||||||
&state->their_points,
|
&state->their_points,
|
||||||
&state->our_funding_pubkey,
|
&state->our_funding_pubkey,
|
||||||
&state->their_funding_pubkey,
|
&state->their_funding_pubkey,
|
||||||
feature_negotiated(state->our_features,
|
take(type),
|
||||||
state->their_features,
|
|
||||||
OPT_STATIC_REMOTEKEY),
|
|
||||||
feature_negotiated(state->our_features,
|
|
||||||
state->their_features,
|
|
||||||
OPT_ANCHOR_OUTPUTS),
|
|
||||||
feature_offered(state->their_features,
|
feature_offered(state->their_features,
|
||||||
OPT_LARGE_CHANNELS),
|
OPT_LARGE_CHANNELS),
|
||||||
/* Opener is local */
|
/* Opener is local */
|
||||||
@@ -582,7 +582,8 @@ static bool funder_finalize_channel_setup(struct state *state,
|
|||||||
*tx,
|
*tx,
|
||||||
&state->channel->funding_pubkey[REMOTE],
|
&state->channel->funding_pubkey[REMOTE],
|
||||||
&state->first_per_commitment_point[REMOTE],
|
&state->first_per_commitment_point[REMOTE],
|
||||||
state->channel->option_static_remotekey);
|
channel_has(state->channel,
|
||||||
|
OPT_STATIC_REMOTEKEY));
|
||||||
|
|
||||||
wire_sync_write(HSM_FD, take(msg));
|
wire_sync_write(HSM_FD, take(msg));
|
||||||
msg = wire_sync_read(tmpctx, HSM_FD);
|
msg = wire_sync_read(tmpctx, HSM_FD);
|
||||||
@@ -764,6 +765,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
|
|||||||
char* err_reason;
|
char* err_reason;
|
||||||
struct wally_tx_output *direct_outputs[NUM_SIDES];
|
struct wally_tx_output *direct_outputs[NUM_SIDES];
|
||||||
struct penalty_base *pbase;
|
struct penalty_base *pbase;
|
||||||
|
struct channel_type *type;
|
||||||
struct tlv_accept_channel_tlvs *accept_tlvs;
|
struct tlv_accept_channel_tlvs *accept_tlvs;
|
||||||
struct tlv_open_channel_tlvs *open_tlvs
|
struct tlv_open_channel_tlvs *open_tlvs
|
||||||
= tlv_open_channel_tlvs_new(tmpctx);
|
= tlv_open_channel_tlvs_new(tmpctx);
|
||||||
@@ -1012,6 +1014,9 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
|
|||||||
&state->channel_id),
|
&state->channel_id),
|
||||||
type_to_string(msg, struct channel_id, &id_in));
|
type_to_string(msg, struct channel_id, &id_in));
|
||||||
|
|
||||||
|
type = default_channel_type(NULL,
|
||||||
|
state->our_features, state->their_features);
|
||||||
|
|
||||||
/* Now we can create the channel structure. */
|
/* Now we can create the channel structure. */
|
||||||
state->channel = new_initial_channel(state,
|
state->channel = new_initial_channel(state,
|
||||||
&state->channel_id,
|
&state->channel_id,
|
||||||
@@ -1028,12 +1033,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
|
|||||||
&state->our_points, &theirs,
|
&state->our_points, &theirs,
|
||||||
&state->our_funding_pubkey,
|
&state->our_funding_pubkey,
|
||||||
&their_funding_pubkey,
|
&their_funding_pubkey,
|
||||||
feature_negotiated(state->our_features,
|
take(type),
|
||||||
state->their_features,
|
|
||||||
OPT_STATIC_REMOTEKEY),
|
|
||||||
feature_negotiated(state->our_features,
|
|
||||||
state->their_features,
|
|
||||||
OPT_ANCHOR_OUTPUTS),
|
|
||||||
feature_offered(state->their_features,
|
feature_offered(state->their_features,
|
||||||
OPT_LARGE_CHANNELS),
|
OPT_LARGE_CHANNELS),
|
||||||
REMOTE);
|
REMOTE);
|
||||||
@@ -1123,7 +1123,8 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
|
|||||||
remote_commit,
|
remote_commit,
|
||||||
&state->channel->funding_pubkey[REMOTE],
|
&state->channel->funding_pubkey[REMOTE],
|
||||||
&state->first_per_commitment_point[REMOTE],
|
&state->first_per_commitment_point[REMOTE],
|
||||||
state->channel->option_static_remotekey);
|
channel_has(state->channel,
|
||||||
|
OPT_STATIC_REMOTEKEY));
|
||||||
|
|
||||||
wire_sync_write(HSM_FD, take(msg));
|
wire_sync_write(HSM_FD, take(msg));
|
||||||
msg = wire_sync_read(tmpctx, HSM_FD);
|
msg = wire_sync_read(tmpctx, HSM_FD);
|
||||||
|
|||||||
Reference in New Issue
Block a user