Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

channel type support #4616

Merged
merged 14 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions channeld/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ CHANNELD_COMMON_OBJS := \
common/blockheight_states.o \
common/channel_config.o \
common/channel_id.o \
common/channel_type.o \
common/crypto_state.o \
common/crypto_sync.o \
common/cryptomsg.o \
Expand Down
60 changes: 27 additions & 33 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
#include <common/billboard.h>
#include <common/blinding.h>
#include <common/bolt12.h>
#include <common/channel_type.h>
#include <common/coin_mvt.h>
#include <common/crypto_sync.h>
#include <common/dev_disconnect.h>
#include <common/ecdh_hsmd.h>
#include <common/features.h>
#include <common/gossip_constants.h>
#include <common/gossip_store.h>
#include <common/htlc_tx.h>
Expand Down Expand Up @@ -360,12 +360,6 @@ static bool handle_master_request_later(struct peer *peer, const u8 *msg)
return false;
}

static bool channel_type_eq(const struct channel_type *a,
const struct channel_type *b)
{
return featurebits_eq(a->features, b->features);
}

static bool match_type(const struct channel_type *desired,
const struct channel_type *current,
struct channel_type **upgradable)
Expand All @@ -377,31 +371,28 @@ static bool match_type(const struct channel_type *desired,
if (channel_type_eq(desired, current))
return true;

for (size_t i = 0; i < tal_count(upgradable); i++) {
if (channel_type_eq(desired, upgradable[i]))
return true;
}

return false;
return channel_type_eq_any(desired, upgradable);
}

static void set_channel_type(struct channel *channel,
const struct channel_type *type)
{
const struct channel_type *cur = channel_type(tmpctx, channel);
const struct channel_type *cur = channel->type;

if (channel_type_eq(cur, type))
return;

/* 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));

/* 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]",
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, channel->type)));
}
#else /* !EXPERIMENTAL_FEATURES */
static bool handle_master_request_later(struct peer *peer, const u8 *msg)
Expand Down Expand Up @@ -1064,7 +1055,8 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
msg = towire_hsmd_sign_remote_commitment_tx(NULL, txs[0],
&peer->channel->funding_pubkey[REMOTE],
&peer->remote_per_commit,
peer->channel->option_static_remotekey);
channel_has(peer->channel,
OPT_STATIC_REMOTEKEY));

msg = hsm_req(tmpctx, take(msg));
if (!fromwire_hsmd_sign_tx_reply(msg, commit_sig))
Expand Down Expand Up @@ -1104,7 +1096,8 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
txs[i+1]->wtx->inputs[0].index);
msg = towire_hsmd_sign_remote_htlc_tx(NULL, txs[i + 1], wscript,
&peer->remote_per_commit,
peer->channel->option_anchor_outputs);
channel_has(peer->channel,
OPT_ANCHOR_OUTPUTS));

msg = hsm_req(tmpctx, take(msg));
if (!fromwire_hsmd_sign_tx_reply(msg, &htlc_sigs[i]))
Expand Down Expand Up @@ -1632,7 +1625,7 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
/* SIGHASH_ALL is implied. */
commit_sig.sighash_type = SIGHASH_ALL;
htlc_sigs = unraw_sigs(tmpctx, raw_sigs,
peer->channel->option_anchor_outputs);
channel_has(peer->channel, OPT_ANCHOR_OUTPUTS));

txs =
channel_txs(tmpctx, &htlc_map, NULL,
Expand Down Expand Up @@ -2710,7 +2703,7 @@ static void peer_reconnect(struct peer *peer,

/* Both these options give us extra fields to check. */
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
* received signed commitment */
Expand Down Expand Up @@ -2744,7 +2737,8 @@ static void peer_reconnect(struct peer *peer,
* to.
* - MAY not set `upgradable` if it would be empty.
*/
send_tlvs->current_type = channel_type(send_tlvs, peer->channel);
send_tlvs->current_type = tal_dup(send_tlvs, struct channel_type,
peer->channel->type);
send_tlvs->upgradable = channel_upgradable_types(send_tlvs,
peer->channel);
}
Expand Down Expand Up @@ -2780,7 +2774,7 @@ static void peer_reconnect(struct peer *peer,
* - MUST set `your_last_per_commitment_secret` to the last
* `per_commitment_secret` it received
*/
if (peer->channel->option_static_remotekey) {
if (channel_has(peer->channel, OPT_STATIC_REMOTEKEY)) {
msg = towire_channel_reestablish
(NULL, &peer->channel_id,
peer->next_index[LOCAL],
Expand Down Expand Up @@ -2943,7 +2937,9 @@ static void peer_reconnect(struct peer *peer,
check_future_dataloss_fields(peer,
next_revocation_number,
&last_local_per_commitment_secret,
peer->channel->option_static_remotekey ? NULL :
channel_has(peer->channel,
OPT_STATIC_REMOTEKEY)
? NULL :
&remote_current_per_commitment_point);
} else
retransmit_revoke_and_ack = false;
Expand Down Expand Up @@ -2991,7 +2987,8 @@ static void peer_reconnect(struct peer *peer,
next_revocation_number,
next_commitment_number,
&last_local_per_commitment_secret,
peer->channel->option_static_remotekey
channel_has(peer->channel,
OPT_STATIC_REMOTEKEY)
? NULL
: &remote_current_per_commitment_point);

Expand Down Expand Up @@ -3648,9 +3645,9 @@ static void init_channel(struct peer *peer)
struct secret last_remote_per_commit_secret;
secp256k1_ecdsa_signature *remote_ann_node_sig;
secp256k1_ecdsa_signature *remote_ann_bitcoin_sig;
bool option_static_remotekey, option_anchor_outputs;
struct penalty_base *pbases;
u8 *reestablish_only;
struct channel_type *channel_type;
#if !DEVELOPER
bool dev_fail_process_onionpacket; /* Ignored */
#endif
Expand Down Expand Up @@ -3711,8 +3708,7 @@ static void init_channel(struct peer *peer)
&peer->remote_upfront_shutdown_script,
&remote_ann_node_sig,
&remote_ann_bitcoin_sig,
&option_static_remotekey,
&option_anchor_outputs,
&channel_type,
&dev_fast_gossip,
&dev_fail_process_onionpacket,
&pbases,
Expand All @@ -3721,7 +3717,8 @@ static void init_channel(struct peer *peer)
}

status_debug("option_static_remotekey = %u, option_anchor_outputs = %u",
option_static_remotekey, option_anchor_outputs);
channel_type_has(channel_type, OPT_STATIC_REMOTEKEY),
channel_type_has(channel_type, OPT_ANCHOR_OUTPUTS));

/* Keeping an array of pointers is better since it allows us to avoid
* extra allocations later. */
Expand Down Expand Up @@ -3752,8 +3749,6 @@ static void init_channel(struct peer *peer)
type_to_string(tmpctx, struct height_states, blockheight_states),
peer->our_blockheight);

status_debug("option_static_remotekey = %u", option_static_remotekey);

if (remote_ann_node_sig && remote_ann_bitcoin_sig) {
peer->announcement_node_sigs[REMOTE] = *remote_ann_node_sig;
peer->announcement_bitcoin_sigs[REMOTE] = *remote_ann_bitcoin_sig;
Expand Down Expand Up @@ -3789,8 +3784,7 @@ static void init_channel(struct peer *peer)
&points[LOCAL], &points[REMOTE],
&funding_pubkey[LOCAL],
&funding_pubkey[REMOTE],
option_static_remotekey,
option_anchor_outputs,
take(channel_type),
feature_offered(peer->their_features,
OPT_LARGE_CHANNELS),
opener);
Expand Down
6 changes: 3 additions & 3 deletions channeld/channeld_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <common/cryptomsg.h>
#include <common/channel_config.h>
#include <common/channel_id.h>
#include <common/channel_type.h>
#include <common/derive_basepoints.h>
#include <common/features.h>
#include <common/fee_states.h>
Expand Down Expand Up @@ -71,8 +72,7 @@ msgdata,channeld_init,upfront_shutdown_script_len,u16,
msgdata,channeld_init,upfront_shutdown_script,u8,upfront_shutdown_script_len
msgdata,channeld_init,remote_ann_node_sig,?secp256k1_ecdsa_signature,
msgdata,channeld_init,remote_ann_bitcoin_sig,?secp256k1_ecdsa_signature,
msgdata,channeld_init,option_static_remotekey,bool,
msgdata,channeld_init,option_anchor_outputs,bool,
msgdata,channeld_init,desired_type,channel_type,
msgdata,channeld_init,dev_fast_gossip,bool,
msgdata,channeld_init,dev_fail_process_onionpacket,bool,
msgdata,channeld_init,num_penalty_bases,u32,
Expand Down Expand Up @@ -233,7 +233,7 @@ msgtype,channeld_dev_quiesce_reply,1109

# Tell master we're upgrading the commitment tx.
msgtype,channeld_upgraded,1011
msgdata,channeld_upgraded,option_static_remotekey,bool,
msgdata,channeld_upgraded,new_type,channel_type,

# Tell peer about our latest and greatest blockheight.
msgtype,channeld_blockheight,1012
Expand Down
20 changes: 9 additions & 11 deletions channeld/channeld_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading