Skip to content

Commit

Permalink
common/features: add explicit bolt12 feature sets.
Browse files Browse the repository at this point in the history
The spec only specifies the mpp bit for invoices, but in
general they are separate spaces.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell authored and cdecker committed Nov 9, 2022
1 parent 6e755d6 commit 9a0d204
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
7 changes: 5 additions & 2 deletions common/bolt12.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static char *check_features_and_chain(const tal_t *ctx,
const struct feature_set *our_features,
const struct chainparams *must_be_chain,
const u8 *features,
enum feature_place fplace,
const struct bitcoin_blkid *chains,
size_t num_chains)
{
Expand All @@ -62,8 +63,7 @@ static char *check_features_and_chain(const tal_t *ctx,
}

if (our_features) {
int badf = features_unsupported(our_features, features,
BOLT11_FEATURE);
int badf = features_unsupported(our_features, features, fplace);
if (badf != -1)
return tal_fmt(ctx, "unknown feature bit %i", badf);
}
Expand Down Expand Up @@ -182,6 +182,7 @@ struct tlv_offer *offer_decode(const tal_t *ctx,
*fail = check_features_and_chain(ctx,
our_features, must_be_chain,
offer->features,
BOLT12_OFFER_FEATURE,
offer->chains,
tal_count(offer->chains));
if (*fail)
Expand Down Expand Up @@ -236,6 +237,7 @@ struct tlv_invoice_request *invrequest_decode(const tal_t *ctx,
*fail = check_features_and_chain(ctx,
our_features, must_be_chain,
invrequest->features,
BOLT12_INVREQ_FEATURE,
invrequest->chain, 1);
if (*fail)
return tal_free(invrequest);
Expand Down Expand Up @@ -276,6 +278,7 @@ struct tlv_invoice *invoice_decode_nosig(const tal_t *ctx,
*fail = check_features_and_chain(ctx,
our_features, must_be_chain,
invoice->features,
BOLT12_INVOICE_FEATURE,
invoice->chain, 1);
if (*fail)
return tal_free(invoice);
Expand Down
3 changes: 2 additions & 1 deletion common/features.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ static const struct feature_style feature_styles[] = {
{ OPT_BASIC_MPP,
.copy_style = { [INIT_FEATURE] = FEATURE_REPRESENT,
[NODE_ANNOUNCE_FEATURE] = FEATURE_REPRESENT,
[BOLT11_FEATURE] = FEATURE_REPRESENT } },
[BOLT11_FEATURE] = FEATURE_REPRESENT,
[BOLT12_INVOICE_FEATURE] = FEATURE_REPRESENT } },
/* BOLT #9:
* | 18/19 | `option_support_large_channel` |... IN ...
*/
Expand Down
5 changes: 4 additions & 1 deletion common/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ enum feature_place {
NODE_ANNOUNCE_FEATURE,
CHANNEL_FEATURE,
BOLT11_FEATURE,
BOLT12_OFFER_FEATURE,
BOLT12_INVREQ_FEATURE,
BOLT12_INVOICE_FEATURE,
};
#define NUM_FEATURE_PLACE (BOLT11_FEATURE+1)
#define NUM_FEATURE_PLACE (BOLT12_INVOICE_FEATURE+1)

extern const char *feature_place_names[NUM_FEATURE_PLACE];

Expand Down
4 changes: 2 additions & 2 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,8 @@ static char *opt_force_featureset(const char *optarg,
char **parts = tal_strsplit(tmpctx, optarg, "/", STR_EMPTY_OK);
if (tal_count(parts) != NUM_FEATURE_PLACE + 1) {
if (!strstarts(optarg, "-") && !strstarts(optarg, "+"))
return "Expected 5 feature sets (init/globalinit/"
" node_announce/channel/bolt11) each terminated by /"
return "Expected 8 feature sets (init/globalinit/"
" node_announce/channel/bolt11/b12offer/b12invreq/b12inv) each terminated by /"
" OR +/-<single_bit_num>";

char *endp;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3510,7 +3510,7 @@ def test_nonstatic_channel(node_factory, bitcoind):
opts=[{},
# needs at least 15 to connect
# (and 9 is a dependent)
{'dev-force-features': '9,15/////'}])
{'dev-force-features': '9,15////////'}])
chan = only_one(only_one(l1.rpc.listpeers()['peers'])['channels'])
assert 'option_static_remotekey' not in chan['features']
assert 'option_anchor_outputs' not in chan['features']
Expand Down

0 comments on commit 9a0d204

Please sign in to comment.