Browse Source

further simplify lnwatcher

regtest_lnd
ThomasV 6 years ago
committed by SomberNight
parent
commit
c64d56cabf
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 12
      electrum/lnwatcher.py

12
electrum/lnwatcher.py

@ -45,7 +45,6 @@ class LNWatcher(AddressSynchronizer):
self.config = network.config self.config = network.config
self.start_network(network) self.start_network(network)
self.lock = threading.RLock() self.lock = threading.RLock()
self.watched_addresses = set()
self.channel_info = storage.get('channel_info', {}) # access with 'lock' self.channel_info = storage.get('channel_info', {}) # access with 'lock'
# [funding_outpoint_str][prev_txid] -> set of EncumberedTransaction # [funding_outpoint_str][prev_txid] -> set of EncumberedTransaction
# prev_txid is the txid of a tx that is watched for confirmations # prev_txid is the txid of a tx that is watched for confirmations
@ -107,7 +106,7 @@ class LNWatcher(AddressSynchronizer):
@with_watchtower @with_watchtower
def watch_channel(self, address, outpoint): def watch_channel(self, address, outpoint):
self.watch_address(address) self.add_address(address)
with self.lock: with self.lock:
if address not in self.channel_info: if address not in self.channel_info:
self.channel_info[address] = outpoint self.channel_info[address] = outpoint
@ -128,11 +127,6 @@ class LNWatcher(AddressSynchronizer):
for address, outpoint in channel_info_items: for address, outpoint in channel_info_items:
await self.check_onchain_situation(outpoint) await self.check_onchain_situation(outpoint)
def watch_address(self, addr):
with self.lock:
self.watched_addresses.add(addr)
self.add_address(addr)
async def check_onchain_situation(self, funding_outpoint): async def check_onchain_situation(self, funding_outpoint):
txid, index = funding_outpoint.split(':') txid, index = funding_outpoint.split(':')
ctx_candidate_txid = self.spent_outpoints[txid].get(int(index)) ctx_candidate_txid = self.spent_outpoints[txid].get(int(index))
@ -164,8 +158,8 @@ class LNWatcher(AddressSynchronizer):
# make sure we are subscribed to all outputs of tx # make sure we are subscribed to all outputs of tx
not_yet_watching = False not_yet_watching = False
for o in prev_tx.outputs(): for o in prev_tx.outputs():
if o.address not in self.watched_addresses: if o.address not in self.get_addresses():
self.watch_address(o.address) self.add_address(o.address)
not_yet_watching = True not_yet_watching = True
if not_yet_watching: if not_yet_watching:
self.print_error('prev_tx', prev_tx, 'not yet watching') self.print_error('prev_tx', prev_tx, 'not yet watching')

Loading…
Cancel
Save