Browse Source

ln: fix race in on_network_update

regtest_lnd
Janus 7 years ago
committed by SomberNight
parent
commit
c657137366
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 36
      electrum/lnworker.py

36
electrum/lnworker.py

@ -114,21 +114,27 @@ class LNWorker(PrintError):
self.network.trigger_callback('channel', chan) self.network.trigger_callback('channel', chan)
def on_network_update(self, event, *args): def on_network_update(self, event, *args):
for chan in self.channels.values(): """ called from network thread """
if chan.state == "OPENING": # Race discovered in save_channel (assertion failing):
res = self.save_short_chan_id(chan) # since short_channel_id could be changed while saving.
if not res: # Mitigated by posting to loop:
self.print_error("network update but funding tx is still not at sufficient depth") async def network_jobs():
continue for chan in self.channels.values():
# this results in the channel being marked OPEN if chan.state == "OPENING":
peer = self.peers[chan.node_id] res = self.save_short_chan_id(chan)
peer.funding_locked(chan) if not res:
elif chan.state == "OPEN": self.print_error("network update but funding tx is still not at sufficient depth")
if event == 'fee_histogram': continue
peer.on_bitcoin_fee_update(chan) # this results in the channel being marked OPEN
conf = self.wallet.get_tx_height(chan.funding_outpoint.txid)[1] peer = self.peers[chan.node_id]
peer = self.peers[chan.node_id] peer.funding_locked(chan)
peer.on_network_update(chan, conf) elif chan.state == "OPEN":
if event == 'fee_histogram':
peer.on_bitcoin_fee_update(chan)
conf = self.wallet.get_tx_height(chan.funding_outpoint.txid)[1]
peer = self.peers[chan.node_id]
peer.on_network_update(chan, conf)
asyncio.run_coroutine_threadsafe(network_jobs(), self.network.asyncio_loop).result()
async def _open_channel_coroutine(self, node_id, local_amount_sat, push_sat, password): async def _open_channel_coroutine(self, node_id, local_amount_sat, push_sat, password):
peer = self.peers[node_id] peer = self.peers[node_id]

Loading…
Cancel
Save