Skip to content

Commit 0e6f16e

Browse files
committed
pay: don't require description for hashdesc invoices (i.e. undeprecate).
Since we didn't hash the descriptions properly (see previous commit), we cannot immediately deprecate omitting the descriptions (since you'd have to omit them for backwards compat!). And move the "must have description or hash" test into bolt11.c core. Changelog-Deprecated: `pay` has *undeprecated* paying a description-hash invoice without providing the description. Signed-off-by: Rusty Russell <[email protected]>
1 parent 74cfd84 commit 0e6f16e

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

common/bolt11.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,17 @@ struct bolt11 *bolt11_decode_nosig(const tal_t *ctx, const char *str,
893893
"h: does not match description");
894894
}
895895

896+
/* BOLT #11:
897+
* A writer:
898+
*...
899+
* - MUST include either exactly one `d` or exactly one `h` field.
900+
*/
901+
/* FIXME: It doesn't actually say the reader must check though! */
902+
if (!have_field[bech32_charset_rev['d']]
903+
&& !have_field[bech32_charset_rev['h']])
904+
return decode_fail(b11, fail,
905+
"must have either 'd' or 'h' field");
906+
896907
hash_u5_done(&hu5, hash);
897908
*sig = tal_dup_arr(ctx, u5, data, data_len, 0);
898909

plugins/pay.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,24 +1051,6 @@ static struct command_result *json_pay(struct command *cmd,
10511051
cmd, JSONRPC2_INVALID_PARAMS,
10521052
"Invalid bolt11:"
10531053
" sets feature var_onion with no secret");
1054-
1055-
/* BOLT #11:
1056-
* A reader:
1057-
*...
1058-
* - MUST check that the SHA2 256-bit hash in the `h` field
1059-
* exactly matches the hashed description.
1060-
*/
1061-
if (!b11->description && !deprecated_apis) {
1062-
if (!b11->description_hash) {
1063-
return command_fail(cmd,
1064-
JSONRPC2_INVALID_PARAMS,
1065-
"Invalid bolt11: missing description");
1066-
}
1067-
if (!description)
1068-
return command_fail(cmd,
1069-
JSONRPC2_INVALID_PARAMS,
1070-
"bolt11 uses description_hash, but you did not provide description parameter");
1071-
}
10721054
} else {
10731055
b12 = invoice_decode(tmpctx, b11str, strlen(b11str),
10741056
plugin_feature_set(cmd->plugin),

tests/test_invoices.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -724,10 +724,6 @@ def test_invoice_deschash(node_factory, chainparams):
724724
listinv = only_one(l2.rpc.listinvoices()['invoices'])
725725
assert listinv['description'] == 'One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon'
726726

727-
# To pay it we need to provide the (correct!) description.
728-
with pytest.raises(RpcError, match=r'you did not provide description parameter'):
729-
l1.rpc.pay(inv['bolt11'])
730-
731727
with pytest.raises(RpcError, match=r'does not match description'):
732728
l1.rpc.pay(inv['bolt11'], description=listinv['description'][:-1])
733729

0 commit comments

Comments
 (0)