tbetter handling of channel updates for private channels - electrum - Electrum Bitcoin wallet
 (HTM) git clone https://git.parazyd.org/electrum
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
       ---
 (DIR) commit edff357fad87768268e52be7797bfc3544af1fa1
 (DIR) parent bd48072e04c702b26f49772816af8b31413cdfb6
 (HTM) Author: SomberNight <somber.night@protonmail.com>
       Date:   Sun, 21 Oct 2018 23:41:36 +0200
       
       better handling of channel updates for private channels
       
       Diffstat:
         M electrum/lnbase.py                  |      19 +++++++++----------
       
       1 file changed, 9 insertions(+), 10 deletions(-)
       ---
 (DIR) diff --git a/electrum/lnbase.py b/electrum/lnbase.py
       t@@ -215,6 +215,7 @@ class Peer(PrintError):
                    self.localfeatures |= LnLocalFeatures.INITIAL_ROUTING_SYNC
                self.localfeatures |= LnLocalFeatures.OPTION_DATA_LOSS_PROTECT_OPT
                self.attempted_route = {}
       +        self.orphan_channel_updates = OrderedDict()
        
            def send_message(self, message_name, **kwargs):
                assert type(message_name) is str
       t@@ -308,16 +309,13 @@ class Peer(PrintError):
                try:
                    self.channel_db.on_channel_update(payload)
                except NotFoundChanAnnouncementForUpdate:
       -            # If it's for a direct channel with this peer, save it in chan.
       -            # Note that this is prone to a race.. we might not have a short_channel_id
       -            # associated with the channel in some cases
       +            # If it's for a direct channel with this peer, save it for later, as it might be
       +            # for our own channel (and we might not yet know the short channel id for that)
                    short_channel_id = payload['short_channel_id']
                    self.print_error("not found channel announce for channel update in db", bh2u(short_channel_id))
       -            for chan in self.channels.values():
       -                if chan.short_channel_id_predicted == short_channel_id:
       -                    chan.pending_channel_update_message = payload
       -                    self.print_error("channel update is for our own private channel", bh2u(short_channel_id))
       -                    break
       +            self.orphan_channel_updates[short_channel_id] = payload
       +            while len(self.orphan_channel_updates) > 10:
       +                self.orphan_channel_updates.popitem(last=False)
        
            def on_channel_announcement(self, payload):
                self.channel_db.on_channel_announcement(payload)
       t@@ -807,8 +805,9 @@ class Peer(PrintError):
                # see https://github.com/lightningnetwork/lnd/issues/1347
                #self.send_message("query_short_channel_ids", chain_hash=constants.net.rev_genesis_bytes(),
                #                          len=9, encoded_short_ids=b'\x00'+chan.short_channel_id)
       -        if hasattr(chan, 'pending_channel_update_message'):
       -            self.on_channel_update(chan.pending_channel_update_message)
       +        pending_channel_update = self.orphan_channel_updates.get(chan.short_channel_id)
       +        if pending_channel_update:
       +            self.channel_db.on_channel_update(pending_channel_update)
        
                self.print_error("CHANNEL OPENING COMPLETED")