From a059a9a256af118c242b8b1b2e260600b22e36eb Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 18 Oct 2023 18:07:21 +0000 Subject: [PATCH] lnpeer.pay: also log hops_data for trampoline_onion We were already logging the outer-layer hops_data, now we also log the inner trampoline-onion hops_data. Example: ``` 1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | lnpeer.pay len(route)=1 1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | 0: edge=9926297x9781928x61754 hop_data= 1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | adding trampoline onion to final payload 1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | lnpeer.pay len(t_route)=3 1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | 0: t_node=02389c93b85ef8f7264c6fa3d3b239341c2631c2cab97e815b33453bd8d0254e77 hop_data=\x9a\xd9\xf0\x92<\xf8Q\xe4\xf4\xd8\x8cr{\x1e\xb1\xee\xb0\xd4R\xba\xe5\xfd\x83\xfc\xd7\xa7\x1dt'> 1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | 1: t_node=0306d92c9cab5265834d720b1428f581f9fb9bfe56c17185264cdaff73e5792881 hop_data= 1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | 2: t_node=038576ac3af8415557cf1d1265ccffb1ead601d51748583f12839c44beeb43826f hop_data= 1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | starting payment. len(route)=1. ``` --- electrum/lnonion.py | 3 +++ electrum/lnpeer.py | 10 ++++++++-- electrum/lnworker.py | 2 +- electrum/trampoline.py | 6 ++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/electrum/lnonion.py b/electrum/lnonion.py index 5e00c151c..d996ab521 100644 --- a/electrum/lnonion.py +++ b/electrum/lnonion.py @@ -117,6 +117,9 @@ class OnionPacket: self.hmac = hmac if not ecc.ECPubkey.is_pubkey_bytes(public_key): raise InvalidOnionPubkey() + # for debugging our own onions: + self._debug_hops_data = None # type: Optional[Sequence[OnionHopsDataSingle]] + self._debug_route = None # type: Optional[LNPaymentRoute] def to_bytes(self) -> bytes: ret = bytes([self.version]) diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py index 1d965fba4..6e249ad88 100644 --- a/electrum/lnpeer.py +++ b/electrum/lnpeer.py @@ -1478,7 +1478,7 @@ class Peer(Logger): payment_hash: bytes, min_final_cltv_expiry: int, payment_secret: bytes, - trampoline_onion=None, + trampoline_onion: Optional[OnionPacket] = None, ): # add features learned during "init" for direct neighbour: route[0].node_features |= self.features @@ -1506,6 +1506,12 @@ class Peer(Logger): "hops_data": trampoline_onion.hops_data, "hmac": trampoline_onion.hmac } + if t_hops_data := trampoline_onion._debug_hops_data: # None if trampoline-forwarding + t_route = trampoline_onion._debug_route + assert t_route is not None + self.logger.info(f"lnpeer.pay len(t_route)={len(t_route)}") + for i in range(len(t_route)): + self.logger.info(f" {i}: t_node={t_route[i].end_node.hex()} hop_data={t_hops_data[i]!r}") # create onion packet payment_path_pubkeys = [x.node_id for x in route] onion = new_onion_packet(payment_path_pubkeys, session_key, hops_data, associated_data=payment_hash) # must use another sessionkey @@ -1540,7 +1546,7 @@ class Peer(Logger): payment_hash: bytes, min_final_cltv_expiry: int, payment_secret: bytes, - trampoline_onion=None, + trampoline_onion: Optional[OnionPacket] = None, ) -> UpdateAddHtlc: assert amount_msat > 0, "amount_msat is not greater zero" diff --git a/electrum/lnworker.py b/electrum/lnworker.py index 19272eac2..2e9c9ba29 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -1560,7 +1560,7 @@ class LNWallet(LNWorker): paysession: PaySession, sent_htlc_info: SentHtlcInfo, min_cltv_expiry: int, - trampoline_onion: bytes = None, + trampoline_onion: Optional[OnionPacket] = None, ) -> None: """Sends a single HTLC.""" shi = sent_htlc_info diff --git a/electrum/trampoline.py b/electrum/trampoline.py index 9de6a5022..ceb564193 100644 --- a/electrum/trampoline.py +++ b/electrum/trampoline.py @@ -9,6 +9,10 @@ from .lnonion import calc_hops_data_for_payment, new_onion_packet from .lnrouter import RouteEdge, TrampolineEdge, LNPaymentRoute, is_route_sane_to_use from .lnutil import NoPathFound, LNPeerAddr from . import constants +from .logging import get_logger + + +_logger = get_logger(__name__) # trampoline nodes are supposed to advertise their fee and cltv in node_update message TRAMPOLINE_FEES = [ @@ -307,6 +311,8 @@ def create_trampoline_onion( } trampoline_session_key = os.urandom(32) trampoline_onion = new_onion_packet(payment_path_pubkeys, trampoline_session_key, hops_data, associated_data=payment_hash, trampoline=True) + trampoline_onion._debug_hops_data = hops_data + trampoline_onion._debug_route = route return trampoline_onion, amount_msat, cltv