From 8393d21503186f92252b32b4eb40ee5cb9447422 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 23 Nov 2019 10:49:24 +1030 Subject: [PATCH] common/features: add `payment_secret` feature if EXPERIMENTAL. Signed-off-by: Rusty Russell --- common/features.c | 1 + lightningd/invoice.c | 1 + lightningd/test/run-invoice-select-inchan.c | 3 +++ tests/test_misc.py | 4 +++- tests/test_pay.py | 26 ++++++--------------- tests/utils.py | 4 ++-- 6 files changed, 17 insertions(+), 22 deletions(-) diff --git a/common/features.c b/common/features.c index 558b5dade..77f693501 100644 --- a/common/features.c +++ b/common/features.c @@ -10,6 +10,7 @@ static const u32 our_features[] = { OPTIONAL_FEATURE(OPT_GOSSIP_QUERIES), #if EXPERIMENTAL_FEATURES OPTIONAL_FEATURE(OPT_VAR_ONION), + OPTIONAL_FEATURE(OPT_PAYMENT_SECRET), #endif OPTIONAL_FEATURE(OPT_GOSSIP_QUERIES_EX), OPTIONAL_FEATURE(OPT_STATIC_REMOTEKEY), diff --git a/lightningd/invoice.c b/lightningd/invoice.c index e3c86cb50..0408b2045 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -827,6 +827,7 @@ static struct command_result *json_invoice(struct command *cmd, info->b11->description_hash = NULL; info->b11->payment_secret = tal_dup(info->b11, struct secret, &payment_secret); + info->b11->features = get_offered_bolt11features(info->b11); #if DEVELOPER diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index dbf10210f..ba0b9d5d9 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -123,6 +123,9 @@ void fulfill_htlc(struct htlc_in *hin UNNEEDED, const struct preimage *preimage /* Generated stub for get_block_height */ u32 get_block_height(const struct chain_topology *topo UNNEEDED) { fprintf(stderr, "get_block_height called!\n"); abort(); } +/* Generated stub for get_offered_bolt11features */ +u8 *get_offered_bolt11features(const tal_t *ctx UNNEEDED) +{ fprintf(stderr, "get_offered_bolt11features called!\n"); abort(); } /* Generated stub for htlc_is_trimmed */ bool htlc_is_trimmed(enum side htlc_owner UNNEEDED, struct amount_msat htlc_amount UNNEEDED, diff --git a/tests/test_misc.py b/tests/test_misc.py index 6703cd972..0c83111a5 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -1709,8 +1709,10 @@ def test_list_features_only(node_factory): 'option_upfront_shutdown_script/odd', 'option_gossip_queries/odd', 'option_var_onion_optin/odd', + 'option_payment_secret/odd', 'option_gossip_queries_ex/odd', - 'option_static_remotekey/odd'] + 'option_static_remotekey/odd', + ] else: expected = ['option_data_loss_protect/odd', 'option_upfront_shutdown_script/odd', diff --git a/tests/test_pay.py b/tests/test_pay.py index 59149c145..8a5517893 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -2371,9 +2371,12 @@ def test_tlv_or_legacy(node_factory, bitcoind): 'cltv_expiry_delta': 6}]]})['bolt11'] l1.rpc.pay(inv) - # Since L1 hasn't seen broadcast, it doesn't know they're TLV. + # Since L1 hasn't seen broadcast, it doesn't know L2 is TLV, but invoice tells it about L3 l2.daemon.wait_for_log("Got onion.*'type': 'legacy'") - l3.daemon.wait_for_log("Got onion.*'type': 'legacy'") + if EXPERIMENTAL_FEATURES: + l3.daemon.wait_for_log("Got onion.*'type': 'tlv'") + else: + l3.daemon.wait_for_log("Got onion.*'type': 'legacy'") # Turns out we only need 3 more blocks to announce l1->l2 channel. bitcoind.generate_block(3) @@ -2384,24 +2387,9 @@ def test_tlv_or_legacy(node_factory, bitcoind): # Make sure l3 knows about l1->l2, so it will add route hint now. wait_for(lambda: len(l3.rpc.listchannels(scid12)['channels']) > 0) - # Now it should send TLV to l2, but not l3. + # Now it should send TLV to l2. inv = l3.rpc.invoice(10000, "test_tlv2", "test_tlv2")['bolt11'] - l1.rpc.pay(inv) - if EXPERIMENTAL_FEATURES: - l2.daemon.wait_for_log("Got onion.*'type': 'tlv'") - else: - l2.daemon.wait_for_log("Got onion.*'type': 'legacy'") - l3.daemon.wait_for_log("Got onion.*'type': 'legacy'") - - # Now we finally announce l2->l3 channel, so l3 can announce tlv support. - bitcoind.generate_block(2) - - wait_for(lambda: len(l1.rpc.listnodes(l3.info['id'])['nodes']) > 0) - wait_for(lambda: 'alias' in l1.rpc.listnodes(l3.info['id'])['nodes'][0]) - - inv = l3.rpc.invoice(10000, "test_tlv3", "test_tlv3")['bolt11'] - l1.rpc.pay(inv) if EXPERIMENTAL_FEATURES: l2.daemon.wait_for_log("Got onion.*'type': 'tlv'") @@ -2414,7 +2402,7 @@ def test_tlv_or_legacy(node_factory, bitcoind): @unittest.skipIf(not EXPERIMENTAL_FEATURES, 'Needs invoice secret support') @unittest.skipIf(not DEVELOPER, 'Needs dev-routes') def test_pay_no_secret(node_factory, bitcoind): - l1, l2 = node_factory.line_graph(2, wait_for_announce=True) + l1, l2 = node_factory.line_graph(2, wait_for_announce=False) l2.rpc.invoice(100000, "test_pay_no_secret", "test_pay_no_secret", preimage='00' * 32, expiry=2000000000) diff --git a/tests/utils.py b/tests/utils.py index 08352b81f..3dbbe4e1a 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -9,8 +9,8 @@ COMPAT = env("COMPAT", "1") == "1" def expected_features(): """Return the expected features hexstring for this configuration""" if EXPERIMENTAL_FEATURES: - # features 1, 3, 7, 9, 11 and 13 (0x2aa2). - return "2aa2" + # features 1, 3, 7, 9, 11, 13 and 15 (0xaaa2). + return "aaa2" else: # features 1, 3, 7, 11 and 13 (0x28a2). return "28a2"