Browse Source

follow-up prev: don't reuse funding tx change address for static_remotekey

see comment in code
master
SomberNight 5 years ago
parent
commit
530a446172
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 29
      electrum/lnpeer.py
  2. 2
      electrum/lnworker.py

29
electrum/lnpeer.py

@ -517,9 +517,34 @@ class Peer(Logger):
) )
return local_config 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 @log_exceptions
async def channel_establishment_flow(self, password: Optional[str], funding_tx: 'PartialTransaction', funding_sat: int, @temporarily_reserve_funding_tx_change_address
push_msat: int, temp_channel_id: bytes) -> Tuple[Channel, 'PartialTransaction']: 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) await asyncio.wait_for(self.initialized, LN_P2P_NETWORK_TIMEOUT)
feerate = self.lnworker.current_feerate_per_kw() feerate = self.lnworker.current_feerate_per_kw()
local_config = self.make_local_config(funding_sat, push_msat, LOCAL) local_config = self.make_local_config(funding_sat, push_msat, LOCAL)

2
electrum/lnworker.py

@ -749,7 +749,7 @@ class LNWallet(LNWorker):
# will raise if init fails # will raise if init fails
await asyncio.wait_for(peer.initialized, LN_P2P_NETWORK_TIMEOUT) await asyncio.wait_for(peer.initialized, LN_P2P_NETWORK_TIMEOUT)
chan, funding_tx = await peer.channel_establishment_flow( chan, funding_tx = await peer.channel_establishment_flow(
password, password=password,
funding_tx=funding_tx, funding_tx=funding_tx,
funding_sat=funding_sat, funding_sat=funding_sat,
push_msat=push_sat * 1000, push_msat=push_sat * 1000,

Loading…
Cancel
Save