mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-29 16:31:29 +00:00
lnbase: avoid race while waiting for funding_locked, wait for un-reversed hash
This commit is contained in:
parent
4d3c34e04e
commit
f0e19ffdfd
2 changed files with 17 additions and 16 deletions
|
@ -588,7 +588,7 @@ class Peer(PrintError):
|
||||||
|
|
||||||
def on_funding_locked(self, payload):
|
def on_funding_locked(self, payload):
|
||||||
channel_id = int.from_bytes(payload['channel_id'], byteorder="big")
|
channel_id = int.from_bytes(payload['channel_id'], byteorder="big")
|
||||||
self.funding_locked[channel_id].set_result(payload)
|
self.remote_funding_locked[channel_id].set_result(payload)
|
||||||
|
|
||||||
def on_node_announcement(self, payload):
|
def on_node_announcement(self, payload):
|
||||||
pubkey = payload['node_id']
|
pubkey = payload['node_id']
|
||||||
|
@ -766,29 +766,31 @@ class Peer(PrintError):
|
||||||
revocation_pubkey, local_delayedpubkey,
|
revocation_pubkey, local_delayedpubkey,
|
||||||
funding_txid, funding_index, funding_satoshis,
|
funding_txid, funding_index, funding_satoshis,
|
||||||
local_amount, remote_amount, to_self_delay, dust_limit_satoshis)
|
local_amount, remote_amount, to_self_delay, dust_limit_satoshis)
|
||||||
# return for now
|
self.print_error('Done making commitment')
|
||||||
print('Done')
|
|
||||||
return
|
|
||||||
# broadcast funding tx
|
# broadcast funding tx
|
||||||
self.local_funding_locked[channel_id] = asyncio.Future()
|
self.local_funding_locked[channel_id] = asyncio.Future()
|
||||||
self.remote_funding_locked[channel_id] = asyncio.Future()
|
self.remote_funding_locked[channel_id] = asyncio.Future()
|
||||||
self.network.broadcast(funding_tx)
|
success, _txid = self.network.broadcast(funding_tx)
|
||||||
|
assert success
|
||||||
# wait until we see confirmations
|
# wait until we see confirmations
|
||||||
|
|
||||||
def on_network_update(event, *args):
|
def on_network_update(event, *args):
|
||||||
if event == 'updated':
|
if event == 'updated':
|
||||||
conf = wallet.get_tx_height(funding_txid)[1]
|
conf = wallet.get_tx_height(bh2u(funding_txid[::-1]))[1]
|
||||||
if conf >= funding_txn_minimum_depth:
|
if conf >= funding_txn_minimum_depth:
|
||||||
try:
|
async def set_local_funding_locked_result():
|
||||||
self.local_funding_locked[channel_id].set_result(1)
|
try:
|
||||||
except (asyncio.InvalidStateError, KeyError) as e:
|
self.local_funding_locked[channel_id].set_result(1)
|
||||||
# FIXME race condition if updates come in quickly, set_result might be called multiple times
|
except (asyncio.InvalidStateError, KeyError) as e:
|
||||||
# or self.local_funding_locked[channel_id] might be deleted already
|
# FIXME race condition if updates come in quickly, set_result might be called multiple times
|
||||||
self.print_error('local_funding_locked.set_result error for channel {}: {}'.format(channel_id, e))
|
# or self.local_funding_locked[channel_id] might be deleted already
|
||||||
self.network.unregister_callback(on_network_update, ['updated'])
|
self.print_error('local_funding_locked.set_result error for channel {}: {}'.format(channel_id, e))
|
||||||
|
asyncio.run_coroutine_threadsafe(set_local_funding_locked_result(), asyncio.get_event_loop())
|
||||||
|
self.network.unregister_callback(on_network_update)
|
||||||
else:
|
else:
|
||||||
self.print_error("unexpected network message:", event, args)
|
self.print_error("unexpected network message:", event, args)
|
||||||
self.network.register_callback(on_network_update, ['updated'])
|
self.network.register_callback(on_network_update, ['updated']) # thread safe
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.local_funding_locked[channel_id]
|
await self.local_funding_locked[channel_id]
|
||||||
|
@ -800,7 +802,7 @@ class Peer(PrintError):
|
||||||
payload = await self.remote_funding_locked[channel_id]
|
payload = await self.remote_funding_locked[channel_id]
|
||||||
finally:
|
finally:
|
||||||
del self.remote_funding_locked[channel_id]
|
del self.remote_funding_locked[channel_id]
|
||||||
self.print_error('Done')
|
self.print_error('Done waiting for remote_funding_locked')
|
||||||
|
|
||||||
def on_update_add_htlc(self, payload):
|
def on_update_add_htlc(self, payload):
|
||||||
# no onion routing for the moment: we assume we are the end node
|
# no onion routing for the moment: we assume we are the end node
|
||||||
|
|
|
@ -39,7 +39,6 @@ if __name__ == "__main__":
|
||||||
peer = Peer(host, port, pubkey, request_initial_sync=False, network=network)
|
peer = Peer(host, port, pubkey, request_initial_sync=False, network=network)
|
||||||
network.futures.append(asyncio.run_coroutine_threadsafe(peer.main_loop(), network.asyncio_loop))
|
network.futures.append(asyncio.run_coroutine_threadsafe(peer.main_loop(), network.asyncio_loop))
|
||||||
# run blocking test
|
# run blocking test
|
||||||
start = time.time()
|
|
||||||
coro = peer.channel_establishment_flow(wallet, config)
|
coro = peer.channel_establishment_flow(wallet, config)
|
||||||
fut = asyncio.run_coroutine_threadsafe(coro, network.asyncio_loop)
|
fut = asyncio.run_coroutine_threadsafe(coro, network.asyncio_loop)
|
||||||
while network.asyncio_loop.is_running():
|
while network.asyncio_loop.is_running():
|
||||||
|
|
Loading…
Add table
Reference in a new issue