fetchinvoice: allow amounts to be specified.

As per lastest revision of the spec, we can specify amounts in invoice
requests even if the offer already specifies it, as long as we exceed
the amount given.  This allows for tipping, and amount obfuscation.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-01-09 14:55:46 +10:30
committed by Christian Decker
parent 4bb05e46e9
commit af46a4f57d
3 changed files with 59 additions and 16 deletions

View File

@@ -3859,7 +3859,7 @@ def test_fetchinvoice(node_factory, bitcoind):
{'allow_broken_log': True}])
# Simple offer first.
offer1 = l3.rpc.call('offer', {'amount': '1msat',
offer1 = l3.rpc.call('offer', {'amount': '2msat',
'description': 'simple test'})['bolt12']
inv1 = l1.rpc.call('fetchinvoice', {'offer': offer1})
@@ -3870,6 +3870,20 @@ def test_fetchinvoice(node_factory, bitcoind):
l1.rpc.pay(inv1['invoice'])
l1.rpc.pay(inv2['invoice'])
# We can also set the amount explicitly, to tip.
inv1 = l1.rpc.call('fetchinvoice', {'offer': offer1, 'msatoshi': 3})
assert l1.rpc.call('decode', [inv1['invoice']])['amount_msat'] == 3
l1.rpc.pay(inv1['invoice'])
# More than ~5x expected is rejected as absurd (it's actually a divide test,
# which means we need 15 here, not 11).
with pytest.raises(RpcError, match="Remote node sent failure message.*Amount vastly exceeds 2msat"):
l1.rpc.call('fetchinvoice', {'offer': offer1, 'msatoshi': 15})
# Underpay is rejected.
with pytest.raises(RpcError, match="Remote node sent failure message.*Amount must be at least 2msat"):
l1.rpc.call('fetchinvoice', {'offer': offer1, 'msatoshi': 1})
# Single-use invoice can be fetched multiple times, only paid once.
offer2 = l3.rpc.call('offer', {'amount': '1msat',
'description': 'single-use test',