forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
features.c
613 lines (547 loc) · 16.9 KB
/
features.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
#include "config.h"
#include <assert.h>
#include <ccan/array_size/array_size.h>
#include <ccan/tal/str/str.h>
#include <common/features.h>
#include <wire/peer_wire.h>
enum feature_copy_style {
/* Feature is not exposed (importantly, being 0, this is the default!). */
FEATURE_DONT_REPRESENT,
/* Feature is exposed. */
FEATURE_REPRESENT,
/* Feature is exposed, but always optional. */
FEATURE_REPRESENT_AS_OPTIONAL,
};
struct feature_style {
u32 bit;
enum feature_copy_style copy_style[NUM_FEATURE_PLACE];
};
const char *feature_place_names[] = {
"init",
NULL,
"node",
"channel",
"invoice"
};
static const struct feature_style feature_styles[] = {
{ OPT_DATA_LOSS_PROTECT,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT } },
{ OPT_UPFRONT_SHUTDOWN_SCRIPT,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT } },
{ OPT_GOSSIP_QUERIES,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT } },
{ OPT_GOSSIP_QUERIES_EX,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT } },
{ OPT_VAR_ONION,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[GLOBAL_INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[BOLT11_FEATURE] = FEATURE_REPRESENT } },
{ OPT_STATIC_REMOTEKEY,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[GLOBAL_INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT } },
{ OPT_PAYMENT_SECRET,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[BOLT11_FEATURE] = FEATURE_REPRESENT } },
{ OPT_BASIC_MPP,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[BOLT11_FEATURE] = FEATURE_REPRESENT,
[BOLT12_INVOICE_FEATURE] = FEATURE_REPRESENT } },
/* BOLT #9:
* | 18/19 | `option_support_large_channel` |... IN ...
*/
{ OPT_LARGE_CHANNELS,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT } },
{ OPT_ONION_MESSAGES,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[BOLT11_FEATURE] = FEATURE_DONT_REPRESENT,
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT} },
{ OPT_SHUTDOWN_WRONG_FUNDING,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT} },
{ OPT_ANCHORS_ZERO_FEE_HTLC_TX,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT } },
{ OPT_DUAL_FUND,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[BOLT11_FEATURE] = FEATURE_DONT_REPRESENT,
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT} },
/* FIXME: Currently not explicitly signalled, but we do
* support it for zeroconf */
{ OPT_SCID_ALIAS,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[BOLT11_FEATURE] = FEATURE_DONT_REPRESENT,
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT} },
/* Zeroconf is always signalled in `init`, but we still
* negotiate on a per-channel basis when calling `fundchannel`
* with the `mindepth` parameter, and accept a channel with
* the `open_channel` hook and its return value for
* `mindepth`.
*/
{ OPT_ZEROCONF,
.copy_style = {
[INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[BOLT11_FEATURE] = FEATURE_DONT_REPRESENT,
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT} },
{ OPT_ROUTE_BLINDING,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[BOLT11_FEATURE] = FEATURE_REPRESENT,
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT } },
{ OPT_SHUTDOWN_ANYSEGWIT,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT } },
{ OPT_QUIESCE,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT } },
{ OPT_PAYMENT_METADATA,
.copy_style = { [INIT_FEATURE] = FEATURE_DONT_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_DONT_REPRESENT,
/* Note: we don't actually set this in invoices, since
* we don't need to use it, but if we don't set it here
* we refuse to parse it. */
[BOLT11_FEATURE] = FEATURE_REPRESENT,
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT } },
{ OPT_CHANNEL_TYPE,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[BOLT11_FEATURE] = FEATURE_DONT_REPRESENT,
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT } },
{ OPT_WANT_PEER_BACKUP_STORAGE,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT } },
{ OPT_PROVIDE_PEER_BACKUP_STORAGE,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT } },
{ OPT_SPLICE,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT} },
{ OPT_EXPERIMENTAL_SPLICE,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[CHANNEL_FEATURE] = FEATURE_DONT_REPRESENT} },
};
struct dependency {
size_t depender;
size_t must_also_have;
};
static const struct dependency feature_deps[] = {
/* BOLT #9:
* Name | Description | Context | Dependencies |
*...
* `basic_mpp` | ... | ... | `payment_secret` |
*/
{ OPT_BASIC_MPP, OPT_PAYMENT_SECRET },
};
static void trim_features(u8 **features)
{
size_t trim, len = tal_bytelen(*features);
/* Don't try to tal_resize a NULL array */
if (len == 0)
return;
/* Big-endian bitfields are weird, but it means we trim
* from the front: */
for (trim = 0; trim < len && (*features)[trim] == 0; trim++);
memmove(*features, *features + trim, len - trim);
tal_resize(features, len - trim);
}
static void clear_feature_bit(u8 *features, u32 bit)
{
size_t bytenum = bit / 8, bitnum = bit % 8, len = tal_count(features);
if (bytenum >= len)
return;
features[len - 1 - bytenum] &= ~(1 << bitnum);
}
static enum feature_copy_style feature_copy_style(u32 f, enum feature_place p)
{
for (size_t i = 0; i < ARRAY_SIZE(feature_styles); i++) {
if (feature_styles[i].bit == COMPULSORY_FEATURE(f))
return feature_styles[i].copy_style[p];
}
abort();
}
struct feature_set *feature_set_for_feature(const tal_t *ctx, int feature)
{
struct feature_set *fs = tal(ctx, struct feature_set);
for (size_t i = 0; i < ARRAY_SIZE(fs->bits); i++) {
fs->bits[i] = tal_arr(fs, u8, 0);
switch (feature_copy_style(feature, i)) {
case FEATURE_DONT_REPRESENT:
continue;
case FEATURE_REPRESENT:
set_feature_bit(&fs->bits[i], feature);
continue;
case FEATURE_REPRESENT_AS_OPTIONAL:
set_feature_bit(&fs->bits[i], OPTIONAL_FEATURE(feature));
continue;
}
abort();
}
return fs;
}
bool feature_set_or(struct feature_set *a,
const struct feature_set *b TAKES)
{
/* Check first, before we change anything! */
for (size_t i = 0; i < ARRAY_SIZE(b->bits); i++) {
/* FIXME: We could allow a plugin to upgrade an optional feature
* to a compulsory one? */
for (size_t j = 0; j < tal_bytelen(b->bits[i])*8; j++) {
if (feature_is_set(b->bits[i], j)
&& feature_offered(a->bits[i], j)) {
if (taken(b))
tal_free(b);
return false;
}
}
}
for (size_t i = 0; i < ARRAY_SIZE(a->bits); i++) {
for (size_t j = 0; j < tal_bytelen(b->bits[i])*8; j++) {
if (feature_is_set(b->bits[i], j))
set_feature_bit(&a->bits[i], j);
}
}
if (taken(b))
tal_free(b);
return true;
}
bool feature_set_sub(struct feature_set *a,
const struct feature_set *b TAKES)
{
/* Check first, before we change anything! */
for (size_t i = 0; i < ARRAY_SIZE(b->bits); i++) {
for (size_t j = 0; j < tal_bytelen(b->bits[i])*8; j++) {
if (feature_is_set(b->bits[i], j)
&& !feature_offered(a->bits[i], j)) {
if (taken(b))
tal_free(b);
return false;
}
}
}
for (size_t i = 0; i < ARRAY_SIZE(a->bits); i++) {
for (size_t j = 0; j < tal_bytelen(b->bits[i])*8; j++) {
if (feature_is_set(b->bits[i], j))
clear_feature_bit(a->bits[i], j);
}
trim_features(&a->bits[i]);
}
if (taken(b))
tal_free(b);
return true;
}
/* BOLT #1:
*
* All data fields are unsigned big-endian unless otherwise specified.
*/
void set_feature_bit(u8 **ptr, u32 bit)
{
size_t len = tal_count(*ptr);
if (bit / 8 >= len) {
size_t newlen = (bit / 8) + 1;
u8 *newarr = tal_arrz(tal_parent(*ptr), u8, newlen);
memcpy(newarr + (newlen - len), *ptr, len);
tal_free(*ptr);
*ptr = newarr;
len = newlen;
}
(*ptr)[len - 1 - bit / 8] |= (1 << (bit % 8));
}
static bool test_bit(const u8 *features, size_t byte, unsigned int bit)
{
assert(byte < tal_count(features));
return features[tal_count(features) - 1 - byte] & (1 << (bit % 8));
}
/* BOLT #7:
*
* - MUST set `features` based on what features were negotiated for this channel, according to [BOLT #9](09-features.md#assigned-features-flags)
* - MUST set `len` to the minimum length required to hold the `features` bits
* it sets.
*/
u8 *get_agreed_channelfeatures(const tal_t *ctx,
const struct feature_set *our_features,
const u8 *their_features)
{
u8 *f = tal_dup_talarr(ctx, u8, our_features->bits[CHANNEL_FEATURE]);
size_t max_len = 0;
/* Clear any features which they didn't offer too */
for (size_t i = 0; i < 8 * tal_count(f); i += 2) {
if (!feature_offered(f, i))
continue;
if (!feature_offered(their_features, i)) {
clear_feature_bit(f, COMPULSORY_FEATURE(i));
clear_feature_bit(f, OPTIONAL_FEATURE(i));
trim_features(&f);
continue;
}
max_len = (i / 8) + 1;
}
/* Trim to length (unless it's already NULL). */
if (f)
tal_resize(&f, max_len);
return f;
}
bool feature_is_set(const u8 *features, size_t bit)
{
size_t bytenum = bit / 8;
if (bytenum >= tal_count(features))
return false;
return test_bit(features, bytenum, bit % 8);
}
bool feature_offered(const u8 *features, size_t f)
{
return feature_is_set(features, COMPULSORY_FEATURE(f))
|| feature_is_set(features, OPTIONAL_FEATURE(f));
}
bool feature_negotiated(const struct feature_set *our_features,
const u8 *their_features, size_t f)
{
return feature_offered(their_features, f)
&& feature_offered(our_features->bits[INIT_FEATURE], f);
}
bool feature_check_depends(const u8 *their_features,
size_t *depender, size_t *missing_dependency)
{
for (size_t i = 0; i < ARRAY_SIZE(feature_deps); i++) {
if (!feature_offered(their_features, feature_deps[i].depender))
continue;
if (feature_offered(their_features,
feature_deps[i].must_also_have))
continue;
*depender = feature_deps[i].depender;
*missing_dependency = feature_deps[i].must_also_have;
return false;
}
return true;
}
/**
* all_supported_features - Check if we support what's being asked
*
* Given the features vector that the remote connection is expecting
* from us, we check to see if we support all even bit features, i.e.,
* the required features.
*
* @bitmap: the features bitmap the peer is asking for
*
* Returns -1 on success, or first unsupported feature.
*/
static int all_supported_features(const struct feature_set *our_features,
const u8 *bitmap,
enum feature_place p)
{
size_t len = tal_count(bitmap) * 8;
/* It's OK to be odd: only check even bits. */
for (size_t bitnum = 0; bitnum < len; bitnum += 2) {
if (!test_bit(bitmap, bitnum/8, bitnum%8))
continue;
if (feature_offered(our_features->bits[p], bitnum))
continue;
return bitnum;
}
return -1;
}
int features_unsupported(const struct feature_set *our_features,
const u8 *their_features,
enum feature_place p)
{
return all_supported_features(our_features, their_features, p);
}
const char *feature_name(const tal_t *ctx, size_t f)
{
static const char *fnames[] = {
"option_data_loss_protect", /* 0/1 */
"option_initial_routing_sync",
"option_upfront_shutdown_script",
"option_gossip_queries",
"option_var_onion_optin",
"option_gossip_queries_ex", /* 10/11 */
"option_static_remotekey",
"option_payment_secret",
"option_basic_mpp",
"option_support_large_channel",
"option_anchor_outputs", /* 20/21 */
"option_anchors",
"option_route_blinding", /* https://github.com/lightning/bolts/pull/765 */
"option_shutdown_anysegwit",
"option_dual_fund",
"option_amp", /* 30/31 */ /* https://github.com/lightning/bolts/pull/658 */
NULL,
"option_quiesce", /* https://github.com/lightning/bolts/pull/869 */
NULL,
"option_onion_messages", /* https://github.com/lightning/bolts/pull/759 */
"option_want_peer_backup_storage", /* 40/41 */ /* https://github.com/lightning/bolts/pull/881/files */
"option_provide_peer_backup_storage", /* https://github.com/lightning/bolts/pull/881/files */
"option_channel_type",
"option_scid_alias", /* https://github.com/lightning/bolts/pull/910 */
"option_payment_metadata",
"option_zeroconf", /* 50/51, https://github.com/lightning/bolts/pull/910 */
NULL,
"option_keysend",
"option_trampoline_routing", /* https://github.com/lightning/bolts/pull/836 */
NULL,
NULL, /* 60/61 */
"option_splice",
NULL,
NULL,
NULL,
NULL, /* 70/71 */
NULL,
NULL,
NULL,
NULL,
NULL, /* 80/81 */
NULL,
NULL,
NULL,
NULL,
NULL, /* 90/91 */
NULL,
NULL,
NULL,
NULL,
NULL, /* 100/101 */
NULL,
NULL,
NULL,
NULL,
NULL, /* 110/111 */
NULL,
NULL,
NULL,
NULL,
NULL, /* 120/121 */
NULL,
NULL,
NULL,
NULL,
NULL, /* 130/131 */
NULL,
NULL,
NULL,
NULL,
NULL, /* 140/141 */
NULL,
NULL,
NULL,
NULL,
NULL, /* 150/151 */
NULL,
NULL,
NULL,
NULL,
NULL, /* 160/161 */
"option_experimental_splice", /* https://github.com/lightning/bolts/pull/863 */
NULL,
NULL,
NULL,
NULL, /* 170/171 */
};
if (f / 2 >= ARRAY_SIZE(fnames) || !fnames[f / 2])
return tal_fmt(ctx, "option_unknown_%zu/%s",
COMPULSORY_FEATURE(f), (f & 1) ? "odd" : "even");
return tal_fmt(ctx, "%s/%s",
fnames[f / 2], (f & 1) ? "odd" : "even");
}
const char **list_supported_features(const tal_t *ctx,
const struct feature_set *fset)
{
const char **list = tal_arr(ctx, const char *, 0);
for (size_t i = 0; i < tal_bytelen(fset->bits[INIT_FEATURE]) * 8; i++) {
if (test_bit(fset->bits[INIT_FEATURE], i / 8, i % 8))
tal_arr_expand(&list, feature_name(list, i));
}
return list;
}
u8 *featurebits_or(const tal_t *ctx, const u8 *f1 TAKES, const u8 *f2 TAKES)
{
size_t l1 = tal_bytelen(f1), l2 = tal_bytelen(f2);
u8 *result;
/* Easier if f2 is shorter. */
if (l1 < l2)
return featurebits_or(ctx, f2, f1);
assert(l2 <= l1);
result = tal_dup_arr(ctx, u8, f1, l1, 0);
/* Note: features are packed to the end of the bitmap */
for (size_t i = 0; i < l2; i++)
result[l1 - l2 + i] |= f2[i];
/* Cleanup the featurebits if we were told to do so. */
if (taken(f2))
tal_free(f2);
return result;
}
void featurebits_unset(u8 **ptr, size_t bit)
{
size_t len = tal_count(*ptr);
if (bit / 8 >= len)
return;
(*ptr)[len - 1 - bit / 8] &= (0 << (bit % 8));
trim_features(ptr);
}
bool featurebits_eq(const u8 *f1, const u8 *f2)
{
size_t len = tal_bytelen(f1);
if (tal_bytelen(f2) > len)
len = tal_bytelen(f2);
for (size_t i = 0; i < len * 8; i++) {
if (feature_is_set(f1, i) != feature_is_set(f2, i))
return false;
}
return true;
}
struct feature_set *fromwire_feature_set(const tal_t *ctx,
const u8 **cursor, size_t *max)
{
struct feature_set *fset = tal(ctx, struct feature_set);
for (size_t i = 0; i < ARRAY_SIZE(fset->bits); i++)
fset->bits[i] = fromwire_tal_arrn(fset, cursor, max,
fromwire_u16(cursor, max));
if (!*cursor)
return tal_free(fset);
return fset;
}
void towire_feature_set(u8 **pptr, const struct feature_set *fset)
{
for (size_t i = 0; i < ARRAY_SIZE(fset->bits); i++) {
towire_u16(pptr, tal_bytelen(fset->bits[i]));
towire_u8_array(pptr, fset->bits[i], tal_bytelen(fset->bits[i]));
}
}
const char *fmt_featurebits(const tal_t *ctx, const u8 *featurebits)
{
size_t size = tal_count(featurebits);
char *fmt = tal_strdup(ctx, "");
const char *prefix = "";
for (size_t i = 0; i < size * 8; i++) {
if (feature_is_set(featurebits, i)) {
tal_append_fmt(&fmt, "%s%zu", prefix, i);
prefix = ",";
}
}
return fmt;
}
struct feature_set *feature_set_dup(const tal_t *ctx,
const struct feature_set *other)
{
struct feature_set *res = tal(ctx, struct feature_set);
for (size_t i = 0; i < ARRAY_SIZE(res->bits); i++)
res->bits[i] = tal_dup_talarr(res, u8, other->bits[i]);
return res;
}