mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-27 15:31:31 +00:00
calc short_channel_id after funding locked
This commit is contained in:
parent
5f1f9a5cf8
commit
d44d1a8467
2 changed files with 19 additions and 5 deletions
|
@ -469,9 +469,9 @@ class AddressSynchronizer(PrintError):
|
|||
return info.height, info.txpos
|
||||
elif tx_hash in self.unverified_tx:
|
||||
height = self.unverified_tx[tx_hash]
|
||||
return (height, 0) if height > 0 else ((1e9 - height), 0)
|
||||
return (height, -1) if height > 0 else ((1e9 - height), -1)
|
||||
else:
|
||||
return (1e9+1, 0)
|
||||
return (1e9+1, -1)
|
||||
|
||||
def with_local_height_cached(func):
|
||||
# get local height only once, as it's relatively expensive.
|
||||
|
|
|
@ -546,6 +546,14 @@ def make_commitment(ctn, local_funding_pubkey, remote_funding_pubkey, remote_pay
|
|||
|
||||
return tx
|
||||
|
||||
|
||||
def calc_short_channel_id(block_height: int, tx_pos_in_block: int, output_index: int) -> bytes:
|
||||
bh = block_height.to_bytes(3, byteorder='big')
|
||||
tpos = tx_pos_in_block.to_bytes(3, byteorder='big')
|
||||
oi = output_index.to_bytes(2, byteorder='big')
|
||||
return bh + tpos + oi
|
||||
|
||||
|
||||
def sign_and_get_sig_string(tx, local_config, remote_config):
|
||||
pubkeys = sorted([bh2u(local_config.multisig_key.pubkey), bh2u(remote_config.multisig_key.pubkey)])
|
||||
tx.sign({bh2u(local_config.multisig_key.pubkey): (local_config.multisig_key.privkey, True)})
|
||||
|
@ -979,17 +987,23 @@ class Peer(PrintError):
|
|||
if conf >= chan.constraints.funding_txn_minimum_depth:
|
||||
async def set_local_funding_locked_result():
|
||||
try:
|
||||
self.local_funding_locked[channel_id].set_result(1)
|
||||
self.local_funding_locked[channel_id].set_result(short_channel_id)
|
||||
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))
|
||||
block_height, tx_pos = wallet.get_txpos(chan.funding_outpoint.txid)
|
||||
if tx_pos == -1:
|
||||
self.print_error('funding tx is not yet SPV verified.. but there are '
|
||||
'already enough confirmations (currently {})'.format(conf))
|
||||
return
|
||||
short_channel_id = calc_short_channel_id(block_height, tx_pos, chan.funding_outpoint.output_index)
|
||||
asyncio.run_coroutine_threadsafe(set_local_funding_locked_result(), asyncio.get_event_loop())
|
||||
self.network.unregister_callback(on_network_update)
|
||||
self.network.register_callback(on_network_update, ['updated']) # thread safe
|
||||
self.network.register_callback(on_network_update, ['updated', 'verified']) # thread safe
|
||||
|
||||
try:
|
||||
await self.local_funding_locked[channel_id]
|
||||
short_channel_id = await self.local_funding_locked[channel_id]
|
||||
finally:
|
||||
del self.local_funding_locked[channel_id]
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue