tln: show full chan id in list, use Event for initialized, more timeouts, return peer from add_peer, set max_htlc_value_in_flight_msat to capacity - electrum - Electrum Bitcoin wallet (HTM) git clone https://git.parazyd.org/electrum (DIR) Log (DIR) Files (DIR) Refs (DIR) Submodules --- (DIR) commit 18bd93446189757143953af09c5982f3123c7872 (DIR) parent 19e60f00bbb1571ee266e51eb1a246c17c451a16 (HTM) Author: Janus <ysangkok@gmail.com> Date: Wed, 30 Jan 2019 17:50:10 +0100 ln: show full chan id in list, use Event for initialized, more timeouts, return peer from add_peer, set max_htlc_value_in_flight_msat to capacity Diffstat: M electrum/lnbase.py | 21 ++++++++++++--------- M electrum/lnworker.py | 9 +++++---- 2 files changed, 17 insertions(+), 13 deletions(-) --- (DIR) diff --git a/electrum/lnbase.py b/electrum/lnbase.py t@@ -199,7 +199,7 @@ class Peer(PrintError): def __init__(self, lnworker: 'LNWorker', peer_addr: LNPeerAddr, request_initial_sync=False, transport: LNTransportBase=None): - self.initialized = asyncio.Future() + self.initialized = asyncio.Event() self.transport = transport self.peer_addr = peer_addr self.lnworker = lnworker t@@ -302,6 +302,9 @@ class Peer(PrintError): self.network.trigger_callback('ln_status') def on_init(self, payload): + if self.initialized.is_set(): + self.print_error("ALREADY INITIALIZED BUT RECEIVED INIT") + return # if they required some even flag we don't have, they will close themselves # but if we require an even flag they don't have, we close our_flags = set(list_enabled_bits(self.localfeatures)) t@@ -315,7 +318,7 @@ class Peer(PrintError): self.localfeatures ^= 1 << flag # disable flag first_timestamp = self.lnworker.get_first_timestamp() self.send_message('gossip_timestamp_filter', chain_hash=constants.net.rev_genesis_bytes(), first_timestamp=first_timestamp, timestamp_range=b"\xff"*4) - self.initialized.set_result(True) + self.initialized.set() def on_channel_update(self, payload): try: t@@ -402,7 +405,7 @@ class Peer(PrintError): revocation_basepoint=keypair_generator(LnKeyFamily.REVOCATION_BASE), to_self_delay=9, dust_limit_sat=546, - max_htlc_value_in_flight_msat=0xffffffffffffffff, + max_htlc_value_in_flight_msat=funding_sat * 1000, max_accepted_htlcs=5, initial_msat=initial_msat, ctn=-1, t@@ -424,7 +427,7 @@ class Peer(PrintError): # dry run creating funding tx to see if we even have enough funds funding_tx_test = wallet.mktx([TxOutput(bitcoin.TYPE_ADDRESS, wallet.dummy_address(), funding_sat)], password, self.lnworker.config, nonlocal_only=True) - await self.initialized + await asyncio.wait_for(self.initialized.wait(), 1) feerate = self.lnworker.current_feerate_per_kw() local_config = self.make_local_config(funding_sat, push_msat, LOCAL) # for the first commitment transaction t@@ -452,7 +455,7 @@ class Peer(PrintError): channel_reserve_satoshis=local_config.reserve_sat, htlc_minimum_msat=1, ) - payload = await self.channel_accepted[temp_channel_id].get() + payload = await asyncio.wait_for(self.channel_accepted[temp_channel_id].get(), 1) if payload.get('error'): raise Exception('Remote Lightning peer reported error: ' + repr(payload.get('error'))) remote_per_commitment_point = payload['first_per_commitment_point'] t@@ -528,12 +531,12 @@ class Peer(PrintError): funding_txid=funding_txid_bytes, funding_output_index=funding_index, signature=sig_64) - payload = await self.funding_signed[channel_id].get() + payload = await asyncio.wait_for(self.funding_signed[channel_id].get(), 1) self.print_error('received funding_signed') remote_sig = payload['signature'] chan.receive_new_commitment(remote_sig, []) # broadcast funding tx - await self.network.broadcast_transaction(funding_tx) + await asyncio.wait_for(self.network.broadcast_transaction(funding_tx), 1) chan.remote_commitment_to_be_revoked = chan.pending_commitment(REMOTE) chan.config[REMOTE] = chan.config[REMOTE]._replace(ctn=0, current_per_commitment_point=remote_per_commitment_point, next_per_commitment_point=None) chan.config[LOCAL] = chan.config[LOCAL]._replace(ctn=0, current_commitment_signature=remote_sig, got_sig_for_next=False) t@@ -551,7 +554,7 @@ class Peer(PrintError): feerate = int.from_bytes(payload['feerate_per_kw'], 'big') temp_chan_id = payload['temporary_channel_id'] - local_config = self.make_local_config(funding_sat * 1000, push_msat, REMOTE) + local_config = self.make_local_config(funding_sat, push_msat, REMOTE) # for the first commitment transaction per_commitment_secret_first = get_per_commitment_secret_from_seed(local_config.per_commitment_secret_seed, RevocationStore.START_INDEX) t@@ -654,7 +657,7 @@ class Peer(PrintError): @log_exceptions async def reestablish_channel(self, chan: Channel): - await self.initialized + await self.initialized.wait() chan_id = chan.channel_id if chan.get_state() != 'DISCONNECTED': self.print_error('reestablish_channel was called but channel {} already in state {}' (DIR) diff --git a/electrum/lnworker.py b/electrum/lnworker.py t@@ -178,7 +178,7 @@ class LNWorker(PrintError): def suggest_peer(self): for node_id, peer in self.peers.items(): - if not(peer.initialized.done()): + if not peer.initialized.is_set(): continue if not all([chan.get_state() in ['CLOSED'] for chan in peer.channels.values()]): continue t@@ -193,7 +193,7 @@ class LNWorker(PrintError): port = int(port) peer_addr = LNPeerAddr(host, port, node_id) if node_id in self.peers: - return + return self.peers[node_id] self._last_tried_peer[peer_addr] = time.time() self.print_error("adding peer", peer_addr) peer = Peer(self, peer_addr, request_initial_sync=self.config.get("request_initial_sync", True)) t@@ -340,7 +340,7 @@ class LNWorker(PrintError): async def _open_channel_coroutine(self, peer, local_amount_sat, push_sat, password): # peer might just have been connected to - await asyncio.wait_for(peer.initialized, 5) + await asyncio.wait_for(peer.initialized.wait(), 5) chan = await peer.channel_establishment_flow( password, funding_sat=local_amount_sat + push_sat, t@@ -579,7 +579,8 @@ class LNWorker(PrintError): yield { 'local_htlcs': json.loads(encoder.encode(chan.hm.log[LOCAL ])), 'remote_htlcs': json.loads(encoder.encode(chan.hm.log[REMOTE])), - 'channel_id': bh2u(chan.short_channel_id), + 'channel_id': bh2u(chan.short_channel_id) if chan.short_channel_id else None, + 'full_channel_id': bh2u(chan.channel_id), 'channel_point': chan.funding_outpoint.to_str(), 'state': chan.get_state(), 'remote_pubkey': bh2u(chan.node_id),