URI: 
       tfollow-up prev: don't reuse funding tx change address for static_remotekey - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 530a446172ac244a7a96b277edfeae9fffa65c1d
   DIR parent 6040e953a32803a65a10f62d4f7ac815d1a9e590
  HTML Author: SomberNight <somber.night@protonmail.com>
       Date:   Fri, 22 May 2020 17:11:53 +0200
       
       follow-up prev: don't reuse funding tx change address for static_remotekey
       
       see comment in code
       
       Diffstat:
         M electrum/lnpeer.py                  |      29 +++++++++++++++++++++++++++--
         M electrum/lnworker.py                |       2 +-
       
       2 files changed, 28 insertions(+), 3 deletions(-)
       ---
   DIR diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py
       t@@ -517,9 +517,34 @@ class Peer(Logger):
                )
                return local_config
        
       +    def temporarily_reserve_funding_tx_change_address(func):
       +        # During the channel open flow, if we initiated, we might have used a change address
       +        # of ours in the funding tx. The funding tx is not part of the wallet history
       +        # at that point yet, but we should already consider this change address as 'used'.
       +        async def wrapper(self: 'Peer', *args, **kwargs):
       +            funding_tx = kwargs['funding_tx']  # type: PartialTransaction
       +            wallet = self.lnworker.wallet
       +            change_addresses = [txout.address for txout in funding_tx.outputs()
       +                                if wallet.is_change(txout.address)]
       +            for addr in change_addresses:
       +                wallet.set_reserved_state_of_address(addr, reserved=True)
       +            try:
       +                return await func(self, *args, **kwargs)
       +            finally:
       +                for addr in change_addresses:
       +                    self.lnworker.wallet.set_reserved_state_of_address(addr, reserved=False)
       +        return wrapper
       +
            @log_exceptions
       -    async def channel_establishment_flow(self, password: Optional[str], funding_tx: 'PartialTransaction', funding_sat: int,
       -                                         push_msat: int, temp_channel_id: bytes) -> Tuple[Channel, 'PartialTransaction']:
       +    @temporarily_reserve_funding_tx_change_address
       +    async def channel_establishment_flow(
       +            self, *,
       +            password: Optional[str],
       +            funding_tx: 'PartialTransaction',
       +            funding_sat: int,
       +            push_msat: int,
       +            temp_channel_id: bytes
       +    ) -> Tuple[Channel, 'PartialTransaction']:
                await asyncio.wait_for(self.initialized, LN_P2P_NETWORK_TIMEOUT)
                feerate = self.lnworker.current_feerate_per_kw()
                local_config = self.make_local_config(funding_sat, push_msat, LOCAL)
   DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py
       t@@ -749,7 +749,7 @@ class LNWallet(LNWorker):
                # will raise if init fails
                await asyncio.wait_for(peer.initialized, LN_P2P_NETWORK_TIMEOUT)
                chan, funding_tx = await peer.channel_establishment_flow(
       -            password,
       +            password=password,
                    funding_tx=funding_tx,
                    funding_sat=funding_sat,
                    push_msat=push_sat * 1000,