From 2d9bc723d40c770dc5a6223bdc71746b37e39caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Tue, 1 Apr 2025 11:21:25 +0200 Subject: [PATCH 1/2] fix: bug where short_channel_id in routehints is to big route hints should be packed with unsigned integers --- tests/test_route_hints.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_route_hints.py b/tests/test_route_hints.py index e0929d4..e7b31ff 100644 --- a/tests/test_route_hints.py +++ b/tests/test_route_hints.py @@ -100,3 +100,23 @@ def test_route_hint_unordered(self): check_decoded_routes(decoded.route_hints, ex["route_hints"]) re_encoded = encode(decoded) assert re_encoded == ex["payment_request"] + + +class TestRouteHintsSize: + def test_channel_id_size(self): + big_channel_id = "16774490x12969991x22027" + hints = RouteHint.from_list( + [ + { + "public_key": ( + "029e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c77255" + ), + "short_channel_id": big_channel_id, + "base_fee": 1, + "ppm_fee": 20, + "cltv_expiry_delta": 3, + } + ] + ) + + assert hints.data From 8c001c0a8a02b2da5392cb5df2d24070dd0ffdb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Tue, 1 Apr 2025 11:22:25 +0200 Subject: [PATCH 2/2] fix unsigned packing --- bolt11/models/routehint.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bolt11/models/routehint.py b/bolt11/models/routehint.py index 766e498..9fea1db 100644 --- a/bolt11/models/routehint.py +++ b/bolt11/models/routehint.py @@ -41,10 +41,10 @@ def data(self) -> Bits: for route in self.routes: route_hints.append( BitArray(hex=route.public_key) - + pack("intbe:64", scid_to_int(route.short_channel_id)) - + pack("intbe:32", route.base_fee) - + pack("intbe:32", route.ppm_fee) - + pack("intbe:16", route.cltv_expiry_delta) + + pack("uintbe:64", scid_to_int(route.short_channel_id)) + + pack("uintbe:32", route.base_fee) + + pack("uintbe:32", route.ppm_fee) + + pack("uintbe:16", route.cltv_expiry_delta) ) return route_hints