Repository navigation
pyln-proto: keep every route hint when decoding an invoice - #9780
takinanton wants to merge 1 commit into
Conversation
| if inv.route_hints is None: | ||
| inv.route_hints = hints | ||
| else: | ||
| inv.route_hints.route_hints.extend(hints.route_hints) |
There was a problem hiding this comment.
Flattening multiple r fields into a single RouteHintSet loses the BOLT #11 distinction between hops along one route (entries inside a single r field) and alternative routes (separate r fields). With this change, a single 2-hop r field (like the invoice in test_decode) and two 1-hop r fields decode to the exact same flat list, and multiple multi-hop r fields lose their route boundaries altogether.
There was a problem hiding this comment.
You're right, merging them was wrong. In a049c26 inv.route_hints is a list with one RouteHintSet per r field and encode() writes one r field per list item. That breaks a reader of inv.route_hints.route_hints which now needs inv.route_hints[0].route_hints. A bare RouteHintSet still encodes like before with one r field per hint.
| inv.route_hints.add(rh) | ||
|
|
||
| privkey = 'c28a9f80738f770d527803a566cf6fc3edf6cea586c4fc4a5223a5ad797e1ac3' | ||
| decoded = Invoice.decode(inv.encode(privkey)) |
There was a problem hiding this comment.
Should assert that .encode() emits two r tags first.
There was a problem hiding this comment.
Added. The test now parses the encoded string and checks it has two r fields before it decodes. There's also a new test that one 2-hop r field and two 1-hop r fields decode differently and both encode back to the same string.
|
Does this fix an issue for you? Because i don't think we even use this in-repo? |
|
No production issue. I decoded an invoice with two |
|
lgtm, but please squash the commits first |
Invoice.decode() replaced route_hints on each `r` field so an invoice with several of them came back with only the last one. encode() writes one `r` field per hint so even its own output did not round trip. Entries inside one `r` field are hops along one route and separate `r` fields are alternative routes. Invoice.route_hints is now a list with one RouteHintSet per `r` field and encode() writes one `r` field per list item. A bare RouteHintSet is still encoded like before, one `r` field per hint. Changelog-Changed: pyln-proto: `Invoice.route_hints` is now a list with one `RouteHintSet` per `r` field instead of a single `RouteHintSet`, so `Invoice.decode()` no longer drops all but the last `r` field.
a049c26 to
9c20863
Compare
|
Squashed into one commit 9c20863. Same tree as before. |
Invoice.decode()in pyln-proto assignedroute_hintsagain on everyrfield so a BOLT11 invoice with more than one came back with only the last one. Decode now keeps everyrfield as its ownRouteHintSetsoroute_hintsis a list with one set perrfield.encode()writes onerfield per list item and still takes a bareRouteHintSetlike before.This changes the type a reader sees.
inv.route_hints.route_hintsbecomesinv.route_hints[0].route_hints.Tests cover two
rfields in the encoded string and one 2-hop field against two 1-hop fields. Ran the pyln-proto tests only which gives 47 passed and 1 skipped. I did not build lightningd or run the integration tests.Checklist
Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:
tools/lightning-downgrade🤖 Generated with Claude Code