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

Function test_sendpay_onion_overflow

tests/test_pay.py:694–718  ·  view source on GitHub ↗

A route whose per-hop payloads exceed the 1300-byte onion must fail cleanly: create_onionpacket returns NULL and send_payment used it unchecked, crashing lightningd (SIGSEGV in serialize_onionpacket).

(node_factory)

Source from the content-addressed store, hash-verified

692
693
694def test_sendpay_onion_overflow(node_factory):
695 """A route whose per-hop payloads exceed the 1300-byte onion must
696 fail cleanly: create_onionpacket returns NULL and send_payment
697 used it unchecked, crashing lightningd (SIGSEGV in
698 serialize_onionpacket)."""
699 l1, l2 = node_factory.line_graph(2, fundamount=10**6)
700
701 amt = 1000
702 inv = l2.rpc.invoice(amt, 'onionoverflow', 'desc')
703
704 # Each TLV hop costs ~50 onion bytes at these amounts; 30 hops
705 # cannot fit in the 1300-byte onion no matter how small the
706 # encodings. Only the first hop must be a live channel: the
707 # onion is built before anything is sent.
708 hop = {
709 'amount_msat': amt,
710 'id': l2.info['id'],
711 'delay': 5,
712 'channel': first_scid(l1, l2)
713 }
714 route = [copy.deepcopy(hop) for _ in range(30)]
715
716 with pytest.raises(RpcError, match='Could not create onion packet'):
717 l1.rpc.sendpay(route, inv['payment_hash'],
718 payment_secret=inv['payment_secret'])
719
720
721@unittest.skipIf(TEST_NETWORK != 'regtest', "The reserve computation is bitcoin specific")

Callers

nothing calls this directly

Calls 4

first_scidFunction · 0.90
line_graphMethod · 0.80
sendpayMethod · 0.80
invoiceMethod · 0.45

Tested by

no test coverage detected