Check that a payment initiated with sendpay can be completed by sendonion.
(node_factory, bitcoind)
| 7089 | |
| 7090 | |
| 7091 | def test_sendonion_sendpay(node_factory, bitcoind): |
| 7092 | """ |
| 7093 | Check that a payment initiated with sendpay can be completed by sendonion. |
| 7094 | """ |
| 7095 | opts = [ |
| 7096 | {"disable-mpp": None, "fee-base": 1000, "fee-per-satoshi": 1000}, |
| 7097 | ] |
| 7098 | l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True, opts=opts * 3) |
| 7099 | |
| 7100 | total_amount = "10000sat" |
| 7101 | # First case, do not overpay a pending MPP payment |
| 7102 | invstr = l3.rpc.invoice("10000sat", "inv", "description")["bolt11"] |
| 7103 | inv = l1.rpc.decode(invstr) |
| 7104 | route2 = l1.single_route(inv["payee"], "2000sat") |
| 7105 | route8 = l1.single_route(inv["payee"], "8000sat") |
| 7106 | |
| 7107 | def pay_with_sendpay(invoice, route, groupid, partid): |
| 7108 | l1.rpc.sendpay( |
| 7109 | route=route, |
| 7110 | payment_hash=invoice["payment_hash"], |
| 7111 | payment_secret=invoice["payment_secret"], |
| 7112 | amount_msat=invoice["amount_msat"], |
| 7113 | groupid=groupid, |
| 7114 | partid=partid, |
| 7115 | ) |
| 7116 | |
| 7117 | def pay_with_sendonion(invoice, route, groupid, partid): |
| 7118 | blockheight = l1.rpc.getinfo()["blockheight"] |
| 7119 | # Need to shift the parameters by one hop |
| 7120 | hops = [] |
| 7121 | for h, n in zip(route[:-1], route[1:]): |
| 7122 | # We tell the node h about the parameters to use for n (a.k.a. h + 1) |
| 7123 | hops.append( |
| 7124 | { |
| 7125 | "pubkey": h["node_id_out"], |
| 7126 | "payload": serialize_payload_tlv( |
| 7127 | n["amount_out_msat"], n["cltv_out"], n["short_channel_id_dir"].rsplit("/", 1)[0], blockheight |
| 7128 | ).hex(), |
| 7129 | } |
| 7130 | ) |
| 7131 | # The last hop has a special payload: |
| 7132 | hops.append( |
| 7133 | { |
| 7134 | "pubkey": route[-1]["node_id_out"], |
| 7135 | "payload": serialize_payload_final_tlv( |
| 7136 | route[-1]["amount_out_msat"], |
| 7137 | route[-1]["cltv_out"], |
| 7138 | invoice["amount_msat"], |
| 7139 | blockheight, |
| 7140 | invoice["payment_secret"], |
| 7141 | ).hex(), |
| 7142 | } |
| 7143 | ) |
| 7144 | onion = l1.rpc.createonion(hops=hops, assocdata=invoice["payment_hash"]) |
| 7145 | l1.rpc.call( |
| 7146 | "sendonion", |
| 7147 | { |
| 7148 | "onion": onion["onion"], |
nothing calls this directly
no test coverage detected