Skip to content

Commit 001b5d6

Browse files
rustyrussellcdecker
authored andcommitted
offers: make it a runtime option.
The fetchinvoice and offers plugins disable themselves if the option isn't enabled (it's enabled by default on EXPERIMENTAL_FEATURES). Signed-off-by: Rusty Russell <[email protected]> Changelog-Added: `experimental-offers` enables fetch, payment and creation of (early draft) offers.
1 parent a4bc3e5 commit 001b5d6

31 files changed

+1998
-133
lines changed

common/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ COMMON_SRC_NOGEN := \
99
common/billboard.c \
1010
common/bip32.c \
1111
common/blinding.c \
12+
common/blindedpath.c \
1213
common/bolt11.c \
1314
common/bolt11_json.c \
1415
common/bolt12.c \
@@ -87,7 +88,6 @@ COMMON_SRC_NOGEN := \
8788

8889
ifeq ($(EXPERIMENTAL_FEATURES),1)
8990
COMMON_SRC_NOGEN += common/psbt_internal.c
90-
COMMON_SRC_NOGEN += common/blindedpath.c
9191
endif
9292

9393
COMMON_SRC_GEN := common/status_wiregen.c common/peer_status_wiregen.c

common/blindedpath.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "config.h"
44
#include <ccan/tal/tal.h>
55

6-
#if EXPERIMENTAL_FEATURES
76
struct route_info;
87
struct pubkey;
98

@@ -13,5 +12,4 @@ struct onionmsg_path **make_blindedpath(const tal_t *ctx,
1312
const struct pubkey *route,
1413
struct pubkey *initial_blinding,
1514
struct pubkey *final_blinding);
16-
#endif /* EXPERIMENTAL_FEATURES */
1715
#endif /* LIGHTNING_COMMON_BLINDEDPATH_H */

common/json.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,10 +1198,8 @@ void json_add_errcode(struct json_stream *result, const char *fieldname,
11981198

11991199
void json_add_invstring(struct json_stream *result, const char *invstring)
12001200
{
1201-
#if EXPERIMENTAL_FEATURES
12021201
if (strstarts(invstring, "lni"))
12031202
json_add_string(result, "bolt12", invstring);
12041203
else
1205-
#endif
12061204
json_add_string(result, "bolt11", invstring);
12071205
}

common/utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ STRUCTEQ_DEF(ripemd160, 0, u);
118118
#define IFDEV(dev, nondev) (nondev)
119119
#endif
120120

121+
#if EXPERIMENTAL_FEATURES
122+
/* Make sure that nondev is evaluated, and valid, but is a constant */
123+
#define IFEXPERIMENTAL(exp, nonexp) (0 ? (nonexp) : (exp))
124+
#else
125+
#define IFEXPERIMENTAL(exp, nonexp) (nonexp)
126+
#endif
127+
121128
/* Context which all wally allocations use (see common/setup.c) */
122129
extern const tal_t *wally_tal_ctx;
123130

devtools/Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
DEVTOOLS := devtools/bolt11-cli devtools/decodemsg devtools/onion devtools/dump-gossipstore devtools/gossipwith devtools/create-gossipstore devtools/mkcommit devtools/mkfunding devtools/mkclose devtools/mkgossip devtools/mkencoded devtools/mkquery devtools/lightning-checkmessage devtools/topology devtools/route
1+
DEVTOOLS := devtools/bolt11-cli devtools/decodemsg devtools/onion devtools/dump-gossipstore devtools/gossipwith devtools/create-gossipstore devtools/mkcommit devtools/mkfunding devtools/mkclose devtools/mkgossip devtools/mkencoded devtools/mkquery devtools/lightning-checkmessage devtools/topology devtools/route devtools/blindedpath devtools/bolt12-cli
22
ifeq ($(HAVE_SQLITE3),1)
33
DEVTOOLS += devtools/checkchannels
44
endif
5-
ifeq ($(EXPERIMENTAL_FEATURES),1)
6-
DEVTOOLS += devtools/blindedpath devtools/bolt12-cli
7-
endif
85

96
DEVTOOLS_TOOL_SRC := $(DEVTOOLS:=.c) devtools/print_wire.c devtools/clean_topo.c
107
DEVTOOLS_TOOL_OBJS := $(DEVTOOLS_TOOL_SRC:.c=.o)

hsmd/Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ HSMD_COMMON_OBJS := \
2020
common/amount.o \
2121
common/bigsize.o \
2222
common/bip32.o \
23+
common/bolt12_merkle.o \
2324
common/channel_id.o \
2425
common/daemon.o \
2526
common/daemon_conn.o \
@@ -43,10 +44,6 @@ HSMD_COMMON_OBJS := \
4344
common/utxo.o \
4445
common/version.o
4546

46-
ifeq ($(EXPERIMENTAL_FEATURES),1)
47-
HSMD_COMMON_OBJS += common/bolt12_merkle.o
48-
endif
49-
5047
lightningd/lightning_hsmd: $(HSMD_OBJS) $(HSMD_COMMON_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS)
5148

5249
-include hsmd/test/Makefile

hsmd/hsmd.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
#include <ccan/read_write_all/read_write_all.h>
2626
#include <ccan/take/take.h>
2727
#include <ccan/tal/str/str.h>
28-
#if EXPERIMENTAL_FEATURES
2928
#include <common/bolt12_merkle.h>
30-
#endif
3129
#include <common/daemon_conn.h>
3230
#include <common/derive_basepoints.h>
3331
#include <common/hash_u5.h>
@@ -349,7 +347,6 @@ static void node_key(struct privkey *node_privkey, struct pubkey *node_id)
349347
#endif
350348
}
351349

352-
#if EXPERIMENTAL_FEATURES
353350
/*~ This returns the secret and/or public x-only key for this node. */
354351
static void node_schnorrkey(secp256k1_keypair *node_keypair,
355352
struct pubkey32 *node_id32)
@@ -374,7 +371,6 @@ static void node_schnorrkey(secp256k1_keypair *node_keypair,
374371
"Failed to derive xonly pub");
375372
}
376373
}
377-
#endif
378374

379375
/*~ This secret is the basis for all per-channel secrets: the per-channel seeds
380376
* will be generated by mixing in the dbid and the peer node_id. */
@@ -1842,7 +1838,6 @@ static struct io_plan *handle_sign_message(struct io_conn *conn,
18421838
take(towire_hsmd_sign_message_reply(NULL, &rsig)));
18431839
}
18441840

1845-
#if EXPERIMENTAL_FEATURES
18461841
/*~ lightningd asks us to sign a bolt12 (e.g. offer). */
18471842
static struct io_plan *handle_sign_bolt12(struct io_conn *conn,
18481843
struct client *c,
@@ -1896,7 +1891,6 @@ static struct io_plan *handle_sign_bolt12(struct io_conn *conn,
18961891
return req_reply(conn, c,
18971892
take(towire_hsmd_sign_bolt12_reply(NULL, &sig)));
18981893
}
1899-
#endif
19001894

19011895
#if DEVELOPER
19021896
static struct io_plan *handle_memleak(struct io_conn *conn,
@@ -2087,11 +2081,7 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
20872081
return handle_sign_message(conn, c, c->msg_in);
20882082

20892083
case WIRE_HSMD_SIGN_BOLT12:
2090-
#if EXPERIMENTAL_FEATURES
20912084
return handle_sign_bolt12(conn, c, c->msg_in);
2092-
#else
2093-
break;
2094-
#endif
20952085
#if DEVELOPER
20962086
case WIRE_HSMD_DEV_MEMLEAK:
20972087
return handle_memleak(conn, c, c->msg_in);

lightningd/Makefile

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,9 @@ LIGHTNINGD_SRC += lightningd/dual_open_control.c
4545
endif
4646

4747
LIGHTNINGD_SRC_NOHDR := \
48+
lightningd/offer.c \
4849
lightningd/signmessage.c
4950

50-
ifeq ($(EXPERIMENTAL_FEATURES),1)
51-
LIGHTNINGD_SRC_NOHDR += lightningd/offer.c
52-
endif
53-
5451
LIGHTNINGD_HEADERS := \
5552
$(LIGHTNINGD_SRC:.c=.h) \
5653
lightningd/channel_state.h \
@@ -81,6 +78,8 @@ LIGHTNINGD_COMMON_OBJS := \
8178
common/blinding.o \
8279
common/bolt11.o \
8380
common/bolt11_json.o \
81+
common/bolt12.o \
82+
common/bolt12_merkle.o \
8483
common/channel_id.o \
8584
common/channel_config.o \
8685
common/coin_mvt.o \
@@ -132,10 +131,6 @@ LIGHTNINGD_COMMON_OBJS := \
132131
common/wire_error.o \
133132
common/wireaddr.o \
134133

135-
ifeq ($(EXPERIMENTAL_FEATURES),1)
136-
LIGHTNINGD_COMMON_OBJS += common/bolt12.o common/bolt12_merkle.o
137-
endif
138-
139134
include wallet/Makefile
140135

141136
# All together in one convenient var

lightningd/invoice.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
#include <common/bech32.h>
99
#include <common/bolt11.h>
1010
#include <common/bolt11_json.h>
11-
#if EXPERIMENTAL_FEATURES
1211
#include <common/bolt12.h>
1312
#include <common/bolt12_merkle.h>
14-
#endif
1513
#include <common/configdir.h>
1614
#include <common/features.h>
1715
#include <common/json_command.h>
@@ -133,7 +131,6 @@ static void invoice_secret(const struct preimage *payment_preimage,
133131
memcpy(payment_secret->data, secret.u.u8, sizeof(secret.u.u8));
134132
}
135133

136-
#if EXPERIMENTAL_FEATURES
137134
/* FIXME: This is a hack. The real secret should be a signature of some
138135
* onion key, using the payer_id */
139136
static void invoice_secret_bolt12(struct lightningd *ld,
@@ -156,7 +153,6 @@ static void invoice_secret_bolt12(struct lightningd *ld,
156153
BUILD_ASSERT(sizeof(*payment_secret) == sizeof(merkle));
157154
memcpy(payment_secret, &merkle, sizeof(merkle));
158155
}
159-
#endif /* EXPERIMENTAL_FEATURES */
160156

161157
struct invoice_payment_hook_payload {
162158
struct lightningd *ld;
@@ -371,12 +367,10 @@ invoice_check_payment(const tal_t *ctx,
371367
if (payment_secret) {
372368
struct secret expected;
373369

374-
#if EXPERIMENTAL_FEATURES
375370
if (details->invstring && strstarts(details->invstring, "lni1"))
376371
invoice_secret_bolt12(ld, details->invstring, &expected);
377372
else
378-
#endif /* EXPERIMENTAL_FEATURES */
379-
invoice_secret(&details->r, &expected);
373+
invoice_secret(&details->r, &expected);
380374
if (!secret_eq_consttime(payment_secret, &expected)) {
381375
log_debug(ld->log, "Attept to pay %s with wrong secret",
382376
type_to_string(tmpctx, struct sha256,
@@ -460,7 +454,6 @@ static bool hsm_sign_b11(const u5 *u5bytes,
460454
return true;
461455
}
462456

463-
#if EXPERIMENTAL_FEATURES
464457
static void hsm_sign_b12_invoice(struct lightningd *ld,
465458
struct tlv_invoice *invoice)
466459
{
@@ -481,7 +474,6 @@ static void hsm_sign_b12_invoice(struct lightningd *ld,
481474
fatal("HSM gave bad sign_invoice_reply %s",
482475
tal_hex(msg, msg));
483476
}
484-
#endif /* EXPERIMENTAL_FEATURES */
485477

486478
static struct command_result *parse_fallback(struct command *cmd,
487479
const char *buffer,
@@ -1505,7 +1497,6 @@ static struct command_result *json_createinvoice(struct command *cmd,
15051497

15061498
notify_invoice_creation(cmd->ld, b11->msat, *preimage, label);
15071499
} else {
1508-
#if EXPERIMENTAL_FEATURES
15091500
struct tlv_invoice *inv;
15101501
struct sha256 *local_offer_id;
15111502

@@ -1574,7 +1565,6 @@ static struct command_result *json_createinvoice(struct command *cmd,
15741565
inv->amount ? &msat : NULL,
15751566
*preimage, label);
15761567
} else
1577-
#endif /* EXPERIMENTAL_FEATURES */
15781568
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
15791569
"Unparsable invoice '%s': %s",
15801570
invstring, fail);

lightningd/lightningd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ struct config {
6666

6767
/* How long before we give up waiting for INIT msg */
6868
u32 connection_timeout_secs;
69+
70+
/* EXPERIMENTAL: offers support */
71+
bool exp_offers;
6972
};
7073

7174
typedef STRMAP(const char *) alt_subdaemon_map;

0 commit comments

Comments
 (0)