mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-28 07:51:27 +00:00
channel_establishment_flow: wait for confirmations of funding txn
This commit is contained in:
parent
9a4650dac7
commit
42b222a8b8
2 changed files with 27 additions and 3 deletions
|
@ -449,11 +449,12 @@ def make_commitment(ctn, local_funding_pubkey, remote_funding_pubkey, remotepubk
|
|||
|
||||
class Peer(PrintError):
|
||||
|
||||
def __init__(self, host, port, pubkey, request_initial_sync=True):
|
||||
def __init__(self, host, port, pubkey, request_initial_sync=True, network=None):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.privkey = os.urandom(32) + b"\x01"
|
||||
self.pubkey = pubkey
|
||||
self.network = network
|
||||
self.read_buffer = b''
|
||||
self.ping_time = 0
|
||||
self.channel_accepted = {}
|
||||
|
@ -706,6 +707,7 @@ class Peer(PrintError):
|
|||
remote_revocation_basepoint = payload['revocation_basepoint']
|
||||
remote_payment_basepoint = payload['payment_basepoint']
|
||||
remote_delayed_payment_basepoint = payload['delayed_payment_basepoint']
|
||||
funding_txn_minimum_depth = int.from_bytes(payload['minimum_depth'], byteorder="big")
|
||||
self.print_error('remote dust limit', remote_dust_limit_satoshis)
|
||||
self.print_error('remote delay', remote_delay)
|
||||
# create funding tx
|
||||
|
@ -772,6 +774,22 @@ class Peer(PrintError):
|
|||
self.remote_funding_locked[channel_id] = asyncio.Future()
|
||||
self.network.broadcast(funding_tx)
|
||||
# wait until we see confirmations
|
||||
|
||||
def on_network_update(event, *args):
|
||||
if event == 'updated':
|
||||
conf = wallet.get_tx_height(funding_txid)[1]
|
||||
if conf >= funding_txn_minimum_depth:
|
||||
try:
|
||||
self.local_funding_locked[channel_id].set_result(1)
|
||||
except (asyncio.InvalidStateError, KeyError) as e:
|
||||
# FIXME race condition if updates come in quickly, set_result might be called multiple times
|
||||
# or self.local_funding_locked[channel_id] might be deleted already
|
||||
self.print_error('local_funding_locked.set_result error for channel {}: {}'.format(channel_id, e))
|
||||
self.network.unregister_callback(on_network_update, ['updated'])
|
||||
else:
|
||||
self.print_error("unexpected network message:", event, args)
|
||||
self.network.register_callback(on_network_update, ['updated'])
|
||||
|
||||
try:
|
||||
await self.local_funding_locked[channel_id]
|
||||
finally:
|
||||
|
@ -874,7 +892,12 @@ class ChannelDB(PrintError):
|
|||
|
||||
def on_channel_update(self, msg_payload):
|
||||
short_channel_id = msg_payload['short_channel_id']
|
||||
self._id_to_channel_info[short_channel_id].on_channel_update(msg_payload)
|
||||
try:
|
||||
channel_info = self._id_to_channel_info[short_channel_id]
|
||||
except KeyError:
|
||||
pass # ignore channel update
|
||||
else:
|
||||
channel_info.on_channel_update(msg_payload)
|
||||
|
||||
def remove_channel(self, short_channel_id):
|
||||
try:
|
||||
|
|
|
@ -34,8 +34,9 @@ if __name__ == "__main__":
|
|||
# wallet
|
||||
storage = WalletStorage(config.get_wallet_path())
|
||||
wallet = Wallet(storage)
|
||||
wallet.start_threads(network)
|
||||
# start peer
|
||||
peer = Peer(host, port, pubkey, request_initial_sync=False)
|
||||
peer = Peer(host, port, pubkey, request_initial_sync=False, network=network)
|
||||
network.futures.append(asyncio.run_coroutine_threadsafe(peer.main_loop(), network.asyncio_loop))
|
||||
# run blocking test
|
||||
start = time.time()
|
||||
|
|
Loading…
Add table
Reference in a new issue