Skip to content

Commit

Permalink
lnpeer: fix some type hints
Browse files Browse the repository at this point in the history
related #8924

note: "forwarding_key" can be stored as False. I think this is ugly and
might be better to do a storage upgrade to change those values to None.
  • Loading branch information
SomberNight committed Mar 1, 2024
1 parent c6802ad commit 0faadc0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions electrum/lnpeer.py
Expand Up @@ -2021,7 +2021,7 @@ def maybe_fulfill_htlc(
processed_onion: ProcessedOnionPacket,
onion_packet_bytes: bytes,
already_forwarded: bool = False,
) -> Tuple[Optional[str], Optional[Tuple[str, Callable[[], Awaitable[Optional[str]]]]]]:
) -> Tuple[Optional[bytes], Optional[Tuple[str, Callable[[], Awaitable[Optional[str]]]]]]:
"""
Decide what to do with an HTLC: return preimage if it can be fulfilled, forwarding callback if it can be forwarded.
Return (preimage, (payment_key, callback)) with at most a single element not None.
Expand Down Expand Up @@ -2613,6 +2613,7 @@ async def htlc_switch(self):
for htlc_id, (local_ctn, remote_ctn, onion_packet_hex, forwarding_key) in unfulfilled.items():
if not chan.hm.is_htlc_irrevocably_added_yet(htlc_proposer=REMOTE, htlc_id=htlc_id):
continue
forwarding_key = forwarding_key or None # type: Optional[str]
htlc = chan.hm.get_htlc_by_id(REMOTE, htlc_id)
error_reason = None # type: Optional[OnionRoutingFailure]
error_bytes = None # type: Optional[bytes]
Expand All @@ -2632,7 +2633,7 @@ async def htlc_switch(self):
onion_packet_bytes=onion_packet_bytes,
onion_packet=onion_packet)
if _forwarding_key:
assert forwarding_key is False
assert forwarding_key is None
unfulfilled[htlc_id] = local_ctn, remote_ctn, onion_packet_hex, _forwarding_key
except OnionRoutingFailure as e:
error_bytes = construct_onion_error(e, onion_packet.public_key, our_onion_private_key=self.privkey)
Expand Down Expand Up @@ -2688,9 +2689,9 @@ def process_unfulfilled_htlc(
self, *,
chan: Channel,
htlc: UpdateAddHtlc,
forwarding_key: str,
forwarding_key: Optional[str],
onion_packet_bytes: bytes,
onion_packet: OnionPacket) -> Tuple[Optional[bytes], Union[bool, None, Tuple[str, int]], Optional[bytes]]:
onion_packet: OnionPacket) -> Tuple[Optional[bytes], Optional[str], Optional[bytes]]:
"""
return (preimage, payment_key, error_bytes) with at most a single element that is not None
raise an OnionRoutingFailure if we need to fail the htlc
Expand Down Expand Up @@ -2739,7 +2740,7 @@ async def wrapped_callback():
return None, None, None
else:
# HTLC we are supposed to forward, and have already forwarded
# for trampoline onions, forwarding failures are stored with forwarding_key (which is the inner key)
# for final trampoline onions, forwarding failures are stored with forwarding_key (which is the inner key)
payment_key = forwarding_key
preimage = self.lnworker.get_preimage(payment_hash)
error_bytes, error_reason = self.lnworker.get_forwarding_failure(payment_key)
Expand Down

0 comments on commit 0faadc0

Please sign in to comment.