Browse Source

follow-up prev

we can't just test with a 1 msat htlc as that might be below htlc_minimum_msat
master
SomberNight 5 years ago
parent
commit
f52072e169
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 19
      electrum/lnchannel.py
  2. 8
      electrum/lnworker.py

19
electrum/lnchannel.py

@ -688,7 +688,8 @@ class Channel(AbstractChannel):
self.storage['frozen_for_receiving'] = bool(b) self.storage['frozen_for_receiving'] = bool(b)
util.trigger_callback('channel', self) util.trigger_callback('channel', self)
def _assert_can_add_htlc(self, *, htlc_proposer: HTLCOwner, amount_msat: int) -> None: def _assert_can_add_htlc(self, *, htlc_proposer: HTLCOwner, amount_msat: int,
ignore_min_htlc_value: bool = False) -> None:
"""Raises PaymentFailure if the htlc_proposer cannot add this new HTLC. """Raises PaymentFailure if the htlc_proposer cannot add this new HTLC.
(this is relevant both for forwarding and endpoint) (this is relevant both for forwarding and endpoint)
""" """
@ -712,10 +713,11 @@ class Channel(AbstractChannel):
strict = (htlc_proposer == LOCAL) strict = (htlc_proposer == LOCAL)
# check htlc raw value # check htlc raw value
if amount_msat <= 0: if not ignore_min_htlc_value:
raise PaymentFailure("HTLC value must be positive") if amount_msat <= 0:
if amount_msat < chan_config.htlc_minimum_msat: raise PaymentFailure("HTLC value must be positive")
raise PaymentFailure(f'HTLC value too small: {amount_msat} msat') if amount_msat < chan_config.htlc_minimum_msat:
raise PaymentFailure(f'HTLC value too small: {amount_msat} msat')
if amount_msat > LN_MAX_HTLC_VALUE_MSAT and not self._ignore_max_htlc_value: if amount_msat > LN_MAX_HTLC_VALUE_MSAT and not self._ignore_max_htlc_value:
raise PaymentFailure(f"HTLC value over protocol maximum: {amount_msat} > {LN_MAX_HTLC_VALUE_MSAT} msat") raise PaymentFailure(f"HTLC value over protocol maximum: {amount_msat} > {LN_MAX_HTLC_VALUE_MSAT} msat")
@ -752,12 +754,15 @@ class Channel(AbstractChannel):
return False return False
return True return True
def can_receive(self, amount_msat: int, *, check_frozen=False) -> bool: def can_receive(self, amount_msat: int, *, check_frozen=False,
ignore_min_htlc_value: bool = False) -> bool:
"""Returns whether the remote can add an HTLC of given value.""" """Returns whether the remote can add an HTLC of given value."""
if check_frozen and self.is_frozen_for_receiving(): if check_frozen and self.is_frozen_for_receiving():
return False return False
try: try:
self._assert_can_add_htlc(htlc_proposer=REMOTE, amount_msat=amount_msat) self._assert_can_add_htlc(htlc_proposer=REMOTE,
amount_msat=amount_msat,
ignore_min_htlc_value=ignore_min_htlc_value)
except PaymentFailure: except PaymentFailure:
return False return False
return True return True

8
electrum/lnworker.py

@ -1197,13 +1197,17 @@ class LNWallet(LNWorker):
channels = list(self.channels.values()) channels = list(self.channels.values())
scid_to_my_channels = {chan.short_channel_id: chan for chan in channels scid_to_my_channels = {chan.short_channel_id: chan for chan in channels
if chan.short_channel_id is not None} if chan.short_channel_id is not None}
ignore_min_htlc_value = False
if amount_sat: if amount_sat:
amount_msat = 1000 * amount_sat amount_msat = 1000 * amount_sat
else: # for no amt invoices, check if channel can receive at least 1 sat: else:
# for no amt invoices, check if channel can receive at least 1 msat
amount_msat = 1 amount_msat = 1
ignore_min_htlc_value = True
# note: currently we add *all* our channels; but this might be a privacy leak? # note: currently we add *all* our channels; but this might be a privacy leak?
for chan in channels: for chan in channels:
if not chan.can_receive(amount_msat=amount_msat, check_frozen=True): if not chan.can_receive(amount_msat=amount_msat, check_frozen=True,
ignore_min_htlc_value=ignore_min_htlc_value):
continue continue
chan_id = chan.short_channel_id chan_id = chan.short_channel_id
assert isinstance(chan_id, bytes), chan_id assert isinstance(chan_id, bytes), chan_id

Loading…
Cancel
Save