electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 7ba3f2d54d55937c7e9bdd8340e384b0b9663ade
parent 6bf2714e3344e0116b0914936d4c2b2fd16058b9
Author: SomberNight <somber.night@protonmail.com>
Date:   Tue, 15 May 2018 16:28:32 +0200

calc short_channel_id after funding locked

Diffstat:
Melectrum/address_synchronizer.py | 4++--
Mlib/lnbase.py | 20+++++++++++++++++---
2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py @@ -397,9 +397,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. diff --git a/lib/lnbase.py b/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]