mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-29 16:31:29 +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):
|
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.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
self.privkey = os.urandom(32) + b"\x01"
|
self.privkey = os.urandom(32) + b"\x01"
|
||||||
self.pubkey = pubkey
|
self.pubkey = pubkey
|
||||||
|
self.network = network
|
||||||
self.read_buffer = b''
|
self.read_buffer = b''
|
||||||
self.ping_time = 0
|
self.ping_time = 0
|
||||||
self.channel_accepted = {}
|
self.channel_accepted = {}
|
||||||
|
@ -706,6 +707,7 @@ class Peer(PrintError):
|
||||||
remote_revocation_basepoint = payload['revocation_basepoint']
|
remote_revocation_basepoint = payload['revocation_basepoint']
|
||||||
remote_payment_basepoint = payload['payment_basepoint']
|
remote_payment_basepoint = payload['payment_basepoint']
|
||||||
remote_delayed_payment_basepoint = payload['delayed_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 dust limit', remote_dust_limit_satoshis)
|
||||||
self.print_error('remote delay', remote_delay)
|
self.print_error('remote delay', remote_delay)
|
||||||
# create funding tx
|
# create funding tx
|
||||||
|
@ -772,6 +774,22 @@ class Peer(PrintError):
|
||||||
self.remote_funding_locked[channel_id] = asyncio.Future()
|
self.remote_funding_locked[channel_id] = asyncio.Future()
|
||||||
self.network.broadcast(funding_tx)
|
self.network.broadcast(funding_tx)
|
||||||
# wait until we see confirmations
|
# 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:
|
try:
|
||||||
await self.local_funding_locked[channel_id]
|
await self.local_funding_locked[channel_id]
|
||||||
finally:
|
finally:
|
||||||
|
@ -874,7 +892,12 @@ class ChannelDB(PrintError):
|
||||||
|
|
||||||
def on_channel_update(self, msg_payload):
|
def on_channel_update(self, msg_payload):
|
||||||
short_channel_id = msg_payload['short_channel_id']
|
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):
|
def remove_channel(self, short_channel_id):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -34,8 +34,9 @@ if __name__ == "__main__":
|
||||||
# wallet
|
# wallet
|
||||||
storage = WalletStorage(config.get_wallet_path())
|
storage = WalletStorage(config.get_wallet_path())
|
||||||
wallet = Wallet(storage)
|
wallet = Wallet(storage)
|
||||||
|
wallet.start_threads(network)
|
||||||
# start peer
|
# 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))
|
network.futures.append(asyncio.run_coroutine_threadsafe(peer.main_loop(), network.asyncio_loop))
|
||||||
# run blocking test
|
# run blocking test
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
Loading…
Add table
Reference in a new issue