tfollow-up prev - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit f52072e1693107b07e29e4d3a68ee944f1020381 DIR parent 12d771737afe87f520ffefb7648fd3878076b923 HTML Author: SomberNight <somber.night@protonmail.com> Date: Sat, 18 Apr 2020 18:51:20 +0200 follow-up prev we can't just test with a 1 msat htlc as that might be below htlc_minimum_msat Diffstat: M electrum/lnchannel.py | 19 ++++++++++++------- M electrum/lnworker.py | 8 ++++++-- 2 files changed, 18 insertions(+), 9 deletions(-) --- DIR diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py t@@ -688,7 +688,8 @@ class Channel(AbstractChannel): self.storage['frozen_for_receiving'] = bool(b) 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. (this is relevant both for forwarding and endpoint) """ t@@ -712,10 +713,11 @@ class Channel(AbstractChannel): strict = (htlc_proposer == LOCAL) # check htlc raw value - if amount_msat <= 0: - raise PaymentFailure("HTLC value must be positive") - if amount_msat < chan_config.htlc_minimum_msat: - raise PaymentFailure(f'HTLC value too small: {amount_msat} msat') + if not ignore_min_htlc_value: + if amount_msat <= 0: + raise PaymentFailure("HTLC value must be positive") + 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: raise PaymentFailure(f"HTLC value over protocol maximum: {amount_msat} > {LN_MAX_HTLC_VALUE_MSAT} msat") t@@ -752,12 +754,15 @@ class Channel(AbstractChannel): return False 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.""" if check_frozen and self.is_frozen_for_receiving(): return False 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: return False return True DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py t@@ -1197,13 +1197,17 @@ class LNWallet(LNWorker): channels = list(self.channels.values()) scid_to_my_channels = {chan.short_channel_id: chan for chan in channels if chan.short_channel_id is not None} + ignore_min_htlc_value = False if 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 + ignore_min_htlc_value = True # note: currently we add *all* our channels; but this might be a privacy leak? 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 chan_id = chan.short_channel_id assert isinstance(chan_id, bytes), chan_id