Skip to content

Commit 89f411c

Browse files
rustyrussellsangbida
authored andcommitted
doc: be explicit (with tests!) on when we don't know amount_msat for listsendpays.
Sangbida and I traced back through ancient history: when the pay plugin was introduced in 0.9.0 (2019!) it already used the amount_msat parameter (then called `msatoshi`), so this case effectively "never happens". But we added a test for it just in case. Signed-off-by: Rusty Russell <[email protected]>
1 parent bd743d7 commit 89f411c

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

contrib/msggen/msggen/schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21942,7 +21942,7 @@
2194221942
"amount_msat": {
2194321943
"type": "msat",
2194421944
"description": [
21945-
"The amount of millisatoshi we intended to send to the destination."
21945+
"The amount of millisatoshi we intended to send to the destination. This can only be missing in the case of someone manually calling sendonion without the `amount_msat` parameter (which no plugin currently does)."
2194621946
]
2194721947
},
2194821948
"amount_sent_msat": {
@@ -24449,7 +24449,7 @@
2444924449
"amount_msat": {
2445024450
"type": "msat",
2445124451
"description": [
24452-
"The amount delivered to destination (if known)."
24452+
"The amount delivered to destination (if known). This is not known in the case where sendonion(7) was used to manually initiate a payment without the `amount_msat` parameter."
2445324453
]
2445424454
},
2445524455
"destination": {

doc/schemas/listpays.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
"amount_msat": {
193193
"type": "msat",
194194
"description": [
195-
"The amount of millisatoshi we intended to send to the destination."
195+
"The amount of millisatoshi we intended to send to the destination. This can only be missing in the case of someone manually calling sendonion without the `amount_msat` parameter (which no plugin currently does)."
196196
]
197197
},
198198
"amount_sent_msat": {

doc/schemas/listsendpays.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
"amount_msat": {
145145
"type": "msat",
146146
"description": [
147-
"The amount delivered to destination (if known)."
147+
"The amount delivered to destination (if known). This is not known in the case where sendonion(7) was used to manually initiate a payment without the `amount_msat` parameter."
148148
]
149149
},
150150
"destination": {

tests/test_pay.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,16 +2995,20 @@ def test_sendonion_rpc(node_factory):
29952995
invs = l4.rpc.listinvoices(label="lbl")['invoices']
29962996
assert(len(invs) == 1 and invs[0]['status'] == 'paid')
29972997

2998-
pays = l1.rpc.listsendpays()['payments']
2999-
assert(len(pays) == 1 and pays[0]['status'] == 'complete'
3000-
and pays[0]['payment_hash'] == inv['payment_hash'])
2998+
pay = only_one(l1.rpc.listsendpays()['payments'])
2999+
assert (pay['status'] == 'complete'
3000+
and pay['payment_hash'] == inv['payment_hash'])
3001+
3002+
# listsendpays promised that amount would be missing if sendonion didn't
3003+
# specify
3004+
assert 'amount_msat' not in pay
30013005

30023006
# And now for a failing payment, using a payment_hash that doesn't match an
30033007
# invoice
30043008
payment_hash = "00" * 32
30053009
onion = l1.rpc.createonion(hops=hops, assocdata=payment_hash)
30063010
l1.rpc.sendonion(onion=onion['onion'], first_hop=first_hop,
3007-
payment_hash=payment_hash)
3011+
payment_hash=payment_hash, amount_msat=amt)
30083012

30093013
try:
30103014
l1.rpc.waitsendpay(payment_hash=payment_hash)
@@ -3013,13 +3017,16 @@ def test_sendonion_rpc(node_factory):
30133017
assert(e.error['code'] == 202)
30143018
assert(e.error['message'] == "Malformed error reply")
30153019

3016-
pays = l1.rpc.listsendpays(payment_hash=payment_hash)['payments']
3017-
assert(len(pays) == 1 and pays[0]['status'] == 'failed'
3018-
and pays[0]['payment_hash'] == payment_hash)
3019-
assert('erroronion' in pays[0])
3020+
pay = only_one(l1.rpc.listsendpays(payment_hash=payment_hash)['payments'])
3021+
assert(pay['status'] == 'failed'
3022+
and pay['payment_hash'] == payment_hash)
3023+
assert 'erroronion' in pay
3024+
3025+
# Since we told sendonion the destination amount, listsendpays will know:
3026+
assert pay['amount_msat'] == amt
30203027

30213028
# Fail onion is msg + padding = 256 + 2*2 byte lengths + 32 byte HMAC
3022-
assert(len(pays[0]['erroronion']) == (256 + 32 + 2 + 2) * 2)
3029+
assert(len(pay['erroronion']) == (256 + 32 + 2 + 2) * 2)
30233030

30243031
# Let's try that again, this time we give it the shared_secrets so it
30253032
# should be able to decode the error.

0 commit comments

Comments
 (0)