URI: 
       tdo not try to reestablish channels in PREOPENING state (per BOLT2). - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 54ef6db762b5ea120a59af0a2470eac999c55d93
   DIR parent 8730fa3f75c3feca7defa517a83014e73e08dbe8
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Sun, 23 Feb 2020 14:54:04 +0100
       
       do not try to reestablish channels in PREOPENING state (per BOLT2).
       
       Diffstat:
         M electrum/lnchannel.py               |      11 ++++++-----
         M electrum/lnpeer.py                  |       2 ++
         M electrum/lnworker.py                |       1 +
       
       3 files changed, 9 insertions(+), 5 deletions(-)
       ---
   DIR diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py
       t@@ -62,9 +62,11 @@ if TYPE_CHECKING:
        # Note: these states are persisted by name (for a given channel) in the wallet file,
        #       so consider doing a wallet db upgrade when changing them.
        class channel_states(IntEnum):
       -    PREOPENING      = 0 # negotiating
       -    OPENING         = 1 # awaiting funding tx
       -    FUNDED          = 2 # funded (requires min_depth and tx verification)
       +    PREOPENING      = 0 # Initial negotiation. Channel will not be reestablished
       +    OPENING         = 1 # Channel will be reestablished. (per BOLT2)
       +                        #  - Funding node: has broadcast the funding tx.
       +                        #  - Non-funding node: has sent the funding_signed message.
       +    FUNDED          = 2 # Funding tx was mined (requires min_depth and tx verification)
            OPEN            = 3 # both parties have sent funding_locked
            FORCE_CLOSING   = 4 # force-close tx has been broadcast
            CLOSING         = 5 # closing negotiation
       t@@ -283,7 +285,6 @@ class Channel(Logger):
                    self.config[LOCAL].current_commitment_signature=remote_sig
                    self.hm.channel_open_finished()
                    self.peer_state = peer_states.GOOD
       -            self.set_state(channel_states.OPENING)
        
            def set_state(self, state):
                """ set on-chain state """
       t@@ -344,7 +345,7 @@ class Channel(Logger):
                return True
        
            def should_try_to_reestablish_peer(self) -> bool:
       -        return self._state < channel_states.CLOSED and self.peer_state == peer_states.DISCONNECTED
       +        return channel_states.PREOPENING < self._state < channel_states.CLOSED and self.peer_state == peer_states.DISCONNECTED
        
            def get_funding_address(self):
                script = funding_output_script(self.config[LOCAL], self.config[REMOTE])
   DIR diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py
       t@@ -611,6 +611,7 @@ class Peer(Logger):
                remote_sig = payload['signature']
                chan.receive_new_commitment(remote_sig, [])
                chan.open_with_first_pcp(remote_per_commitment_point, remote_sig)
       +        chan.set_state(channel_states.OPENING)
                return chan, funding_tx
        
            def create_channel_storage(self, channel_id, outpoint, local_config, remote_config, constraints):
       t@@ -726,6 +727,7 @@ class Peer(Logger):
            async def reestablish_channel(self, chan: Channel):
                await self.initialized
                chan_id = chan.channel_id
       +        assert channel_states.PREOPENING < chan.get_state() < channel_states.CLOSED
                if chan.peer_state != peer_states.DISCONNECTED:
                    self.logger.info('reestablish_channel was called but channel {} already in state {}'
                                     .format(chan_id, chan.get_state()))
   DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py
       t@@ -764,6 +764,7 @@ class LNWallet(LNWorker):
                if funding_tx.is_complete():
                    # TODO make more robust (timeout low? server returns error?)
                    await asyncio.wait_for(self.network.broadcast_transaction(funding_tx), LN_P2P_NETWORK_TIMEOUT)
       +            chan.set_state(channel_states.OPENING)
                return chan, funding_tx
        
            def add_channel(self, chan):