ln invoices: more relaxed filtering of chans to include route hints for

e.g. just because remote peer is temporarily offline, we might still want it
included in the invoice
This commit is contained in:
SomberNight 2020-05-11 16:01:33 +02:00
parent 1788e5c1c0
commit c034219c5a
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9

View file

@ -1216,19 +1216,21 @@ class LNWallet(LNWorker):
"""calculate routing hints (BOLT-11 'r' field)""" """calculate routing hints (BOLT-11 'r' field)"""
routing_hints = [] routing_hints = []
channels = list(self.channels.values()) channels = list(self.channels.values())
random.shuffle(channels) # not sure this has any benefit but let's not leak channel order
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: else:
# for no amt invoices, check if channel can receive at least 1 msat # 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, # do minimal filtering of channels.
ignore_min_htlc_value=ignore_min_htlc_value): # we include channels that cannot *right now* receive (e.g. peer disconnected or balance insufficient)
if not (chan.is_open() and not chan.is_frozen_for_receiving()):
continue
if amount_msat > 1000 * chan.constraints.capacity:
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