MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_injectpaymentonion_blindedpath

Function test_injectpaymentonion_blindedpath

tests/test_pay.py:6610–6786  ·  view source on GitHub ↗
(node_factory, executor)

Source from the content-addressed store, hash-verified

6608
6609
6610def test_injectpaymentonion_blindedpath(node_factory, executor):
6611 l1, l2 = node_factory.line_graph(2,
6612 wait_for_announce=True,
6613 # avoids trying to create a blinded path to next node
6614 opts=[{}, {'dev-allow-localhost': None}])
6615 blockheight = l1.rpc.getinfo()['blockheight']
6616 # Test bolt12, with stub blinded path.
6617 offer = l2.rpc.offer('any')
6618 inv7 = l1.rpc.fetchinvoice(offer['bolt12'], '1000msat')
6619
6620 decoded = l1.rpc.decode(inv7['invoice'])
6621 assert len(decoded['invoice_paths']) == 1
6622 path_key = decoded['invoice_paths'][0]['first_path_key']
6623 assert decoded['invoice_paths'][0]['first_node_id'] == l2.info['id']
6624 path = decoded['invoice_paths'][0]['path']
6625 assert len(path) == 1
6626
6627 # Manually encode the onion payload to include blinded info
6628 # BOLT #4:
6629 # - For every node inside a blinded route:
6630 # - MUST include the `encrypted_recipient_data` provided by the recipient
6631 # - For the first node in the blinded route:
6632 # - MUST include the `path_key` provided by the recipient in `current_path_key`
6633 # - If it is the final node:
6634 # - MUST include `amt_to_forward`, `outgoing_cltv_value` and `total_amount_msat`.
6635 # - The value set for `outgoing_cltv_value`:
6636 # - MUST use the current block height as a baseline value.
6637 # - if a [random offset](07-routing-gossip.md#recommendations-for-routing) was added to improve privacy:
6638 # - SHOULD add the offset to the baseline value.
6639 # - MUST NOT include any other tlv field.
6640 final_tlvs = TlvPayload()
6641
6642 # BOLT #4:
6643 # 1. type: 2 (`amt_to_forward`)
6644 # 2. data:
6645 # * [`tu64`:`amt_to_forward`]
6646 # 1. type: 4 (`outgoing_cltv_value`)
6647 # 2. data:
6648 # * [`tu32`:`outgoing_cltv_value`]
6649 # ...
6650 # 1. type: 10 (`encrypted_recipient_data`)
6651 # 2. data:
6652 # * [`...*byte`:`encrypted_recipient_data`]
6653 # 1. type: 12 (`current_path_key`)
6654 # 2. data:
6655 # * [`point`:`path_key`]
6656 # ...
6657 # 1. type: 18 (`total_amount_msat`)
6658 # 2. data:
6659 # * [`tu64`:`total_msat`]
6660 final_tlvs.add_field(2, tu64_encode(1000))
6661 final_tlvs.add_field(4, tu64_encode(blockheight + 18))
6662 final_tlvs.add_field(10, bytes.fromhex(path[0]['encrypted_recipient_data']))
6663 final_tlvs.add_field(12, bytes.fromhex(path_key))
6664 final_tlvs.add_field(18, tu64_encode(1000))
6665
6666 hops = [{'pubkey': l1.info['id'],
6667 'payload': serialize_payload_tlv(1000, 18 + 6, first_scid(l1, l2), blockheight).hex()},

Callers

nothing calls this directly

Calls 15

add_fieldMethod · 0.95
to_bytesMethod · 0.95
TlvPayloadClass · 0.90
tu64_encodeFunction · 0.90
serialize_payload_tlvFunction · 0.90
first_scidFunction · 0.90
only_oneFunction · 0.90
wait_forFunction · 0.90
line_graphMethod · 0.80
fetchinvoiceMethod · 0.80
listsendpaysMethod · 0.80
join_nodesMethod · 0.80

Tested by

no test coverage detected