Browse Source

calc short_channel_id after funding locked

regtest_lnd
SomberNight 7 years ago
parent
commit
cb4f19f8e7
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 4
      electrum/address_synchronizer.py
  2. 20
      lib/lnbase.py

4
electrum/address_synchronizer.py

@ -405,9 +405,9 @@ class AddressSynchronizer(Logger):
return verified_tx_mined_info.height, verified_tx_mined_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.

20
lib/lnbase.py

@ -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…
Cancel
Save