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

EXPERIMENTAL: channel upgrade support #4532

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
channeld: send current features (EXPERIMENTAL_FEATURES)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jun 4, 2021
commit 7136b25f484e7401802078d66ecc9556444fbc35
19 changes: 19 additions & 0 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -2506,6 +2506,25 @@ static void peer_reconnect(struct peer *peer,
* `commitment_signed` it expects to send.
*/
send_tlvs->next_to_send = tal_dup(send_tlvs, u64, &peer->next_index[REMOTE]);

/* BOLT-upgrade_protocol #2:
* - if it initiated the channel:
* - MUST set `desired_type` to the channel_type it wants for the
* channel.
*/
if (peer->channel->opener == LOCAL)
send_tlvs->desired_type = channel_type(send_tlvs, peer->channel);
else {
/* BOLT-upgrade_protocol #2:
* - otherwise:
* - MUST set `current_type` to the current channel_type of the
* channel.
* - MUST set `upgradable` to the channel types it could change
* to.
* - MAY not set `upgradable` if it would be empty.
*/
send_tlvs->current_type = channel_type(send_tlvs, peer->channel);
}
#endif

/* BOLT #2:
Expand Down
3 changes: 3 additions & 0 deletions channeld/test/run-full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ void memleak_add_helper_(const tal_t *p UNNEEDED, void (*cb)(struct htable *memt
/* Generated stub for memleak_remove_htable */
void memleak_remove_htable(struct htable *memtable UNNEEDED, const struct htable *ht UNNEEDED)
{ 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 */
void status_failed(enum status_failreason code UNNEEDED,
const char *fmt UNNEEDED, ...)
Expand Down
52 changes: 52 additions & 0 deletions common/initial_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
#include <ccan/array_size/array_size.h>
#include <ccan/cast/cast.h>
#include <ccan/tal/str/str.h>
#include <common/features.h>
#include <common/fee_states.h>
#include <common/initial_channel.h>
#include <common/initial_commit_tx.h>
#include <common/keyset.h>
#include <common/type_to_string.h>
#include <inttypes.h>
#include <wire/peer_wire.h>

struct channel *new_initial_channel(const tal_t *ctx,
const struct channel_id *cid,
Expand Down Expand Up @@ -136,6 +138,56 @@ u32 channel_feerate(const struct channel *channel, enum side side)
return get_feerate(channel->fee_states, channel->opener, side);
}

#if EXPERIMENTAL_FEATURES
/* BOLT-upgrade_protocol #2:
* Channel features are explicitly enumerated as `channel_type` bitfields,
* using odd features bits. The currently defined types are:
* - no features (no bits set)
* - `option_static_remotekey` (bit 13)
* - `option_anchor_outputs` and `option_static_remotekey` (bits 21 and 13)
* - `option_anchors_zero_fee_htlc_tx` and `option_static_remotekey` (bits 23
* and 13)
*/
static struct channel_type *new_channel_type(const tal_t *ctx)
{
struct channel_type *type = tal(ctx, struct channel_type);

type->features = tal_arr(type, u8, 0);
return type;
}

static struct channel_type *type_static_remotekey(const tal_t *ctx)
{
struct channel_type *type = new_channel_type(ctx);

set_feature_bit(&type->features,
OPTIONAL_FEATURE(OPT_STATIC_REMOTEKEY));
return type;
}

static struct channel_type *type_anchor_outputs(const tal_t *ctx)
{
struct channel_type *type = new_channel_type(ctx);

set_feature_bit(&type->features,
OPTIONAL_FEATURE(OPT_ANCHOR_OUTPUTS));
set_feature_bit(&type->features,
OPTIONAL_FEATURE(OPT_STATIC_REMOTEKEY));
return type;
}

struct channel_type *channel_type(const tal_t *ctx,
const struct channel *channel)
{
if (channel->option_anchor_outputs)
return type_anchor_outputs(ctx);
if (channel->option_static_remotekey)
return type_static_remotekey(ctx);

return new_channel_type(ctx);
}
#endif /* EXPERIMENTAL_FEATURES */

static char *fmt_channel_view(const tal_t *ctx, const struct channel_view *view)
{
return tal_fmt(ctx, "{ owed_local=%s,"
Expand Down
9 changes: 9 additions & 0 deletions common/initial_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,13 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
*/
u32 channel_feerate(const struct channel *channel, enum side side);

#if EXPERIMENTAL_FEATURES
/* BOLT-upgrade_protocol #2:
* Channel features are explicitly enumerated as `channel_type` bitfields,
* using odd features bits.
*/
struct channel_type *channel_type(const tal_t *ctx,
const struct channel *channel);
#endif /* EXPERIMENTAL_FEATURES */

#endif /* LIGHTNING_COMMON_INITIAL_CHANNEL_H */