Browse Source

lnpeer.maybe_fulfill_htlc: also check cltv and amt against inner onion

- is_trampoline was True iff we are the final recipient of a trampoline payment
  - in that case, we were only comparing htlc.cltv_expiry against the outer onion cltv
  - we should and do now also compare against the inner onion cltv
- the checks are changed from "!=" to "<", to adapt to bolts PR 1032
  - see b38156b951
  - note that the leniency is needed for the cltv off-by-one
    added in eca10eb04d to work
master
SomberNight 2 years ago
parent
commit
783dc0cdd5
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 9
      electrum/lnpeer.py

9
electrum/lnpeer.py

@ -1838,7 +1838,7 @@ class Peer(Logger):
htlc: UpdateAddHtlc, htlc: UpdateAddHtlc,
processed_onion: ProcessedOnionPacket, processed_onion: ProcessedOnionPacket,
onion_packet_bytes: bytes, onion_packet_bytes: bytes,
is_trampoline: bool = False) -> Tuple[Optional[bytes], Optional[Callable]]: ) -> Tuple[Optional[bytes], Optional[Callable]]:
"""As a final recipient of an HTLC, decide if we should fulfill it. """As a final recipient of an HTLC, decide if we should fulfill it.
Return (preimage, forwarding_callback) with at most a single element not None Return (preimage, forwarding_callback) with at most a single element not None
""" """
@ -1872,8 +1872,7 @@ class Peer(Logger):
log_fail_reason(f"'outgoing_cltv_value' missing from onion") log_fail_reason(f"'outgoing_cltv_value' missing from onion")
raise OnionRoutingFailure(code=OnionFailureCode.INVALID_ONION_PAYLOAD, data=b'\x00\x00\x00') raise OnionRoutingFailure(code=OnionFailureCode.INVALID_ONION_PAYLOAD, data=b'\x00\x00\x00')
if not is_trampoline: if cltv_from_onion > htlc.cltv_expiry:
if cltv_from_onion != htlc.cltv_expiry:
log_fail_reason(f"cltv_from_onion != htlc.cltv_expiry") log_fail_reason(f"cltv_from_onion != htlc.cltv_expiry")
raise OnionRoutingFailure( raise OnionRoutingFailure(
code=OnionFailureCode.FINAL_INCORRECT_CLTV_EXPIRY, code=OnionFailureCode.FINAL_INCORRECT_CLTV_EXPIRY,
@ -1884,7 +1883,7 @@ class Peer(Logger):
log_fail_reason(f"'total_msat' missing from onion") log_fail_reason(f"'total_msat' missing from onion")
raise exc_incorrect_or_unknown_pd raise exc_incorrect_or_unknown_pd
if not is_trampoline and amt_to_forward != htlc.amount_msat: if amt_to_forward > htlc.amount_msat:
log_fail_reason(f"amt_to_forward != htlc.amount_msat") log_fail_reason(f"amt_to_forward != htlc.amount_msat")
raise OnionRoutingFailure( raise OnionRoutingFailure(
code=OnionFailureCode.FINAL_INCORRECT_HTLC_AMOUNT, code=OnionFailureCode.FINAL_INCORRECT_HTLC_AMOUNT,
@ -1936,7 +1935,7 @@ class Peer(Logger):
htlc=htlc, htlc=htlc,
processed_onion=trampoline_onion, processed_onion=trampoline_onion,
onion_packet_bytes=onion_packet_bytes, onion_packet_bytes=onion_packet_bytes,
is_trampoline=True) )
if preimage: if preimage:
return preimage, None return preimage, None
else: else:

Loading…
Cancel
Save