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