electrum

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

commit d5cb21143ff47bd400a8af454e82d0dcf25ccb88
parent 12a02a8a1e4fdef98a7ae61f32bed2c0bdba9921
Author: Janus <ysangkok@gmail.com>
Date:   Tue, 17 Jul 2018 15:28:27 +0200

ln: send update_fee on fee change, handle nodes without data_protect

Diffstat:
Melectrum/lnbase.py | 29+++++++++++++++++++++++++++--
Melectrum/lnworker.py | 4+++-
2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/electrum/lnbase.py b/electrum/lnbase.py @@ -666,7 +666,11 @@ class Peer(PrintError): local_ctn = int.from_bytes(channel_reestablish_msg["next_remote_revocation_number"], 'big') if local_ctn != chan.local_state.ctn: raise Exception("expected local ctn {}, got {}".format(chan.local_state.ctn, local_ctn)) - their = channel_reestablish_msg["my_current_per_commitment_point"] + try: + their = channel_reestablish_msg["my_current_per_commitment_point"] + except KeyError: # no data_protect option + self.channel_reestablished[chan_id].set_result(True) + return our = chan.remote_state.current_per_commitment_point if our is None: our = chan.remote_state.next_per_commitment_point @@ -1011,7 +1015,28 @@ class Peer(PrintError): def on_update_fee(self, payload): channel_id = payload["channel_id"] - self.channels[channel_id].update_fee(int.from_bytes(payload["feerate_per_kw"], "big")) + self.channels[channel_id].receive_update_fee(int.from_bytes(payload["feerate_per_kw"], "big")) + def on_bitcoin_fee_update(self, chan): + """ + called when the fee histogram (based on current mempool) changed + """ + if not chan.constraints.is_initiator: + # TODO force close if initiator does not update_fee enough + return + feerate_per_kvbyte = self.network.config.depth_to_fee(10) + feerate_per_kw = feerate_per_kvbyte / 4 + self.print_error("current feerate", chan.remote_state.feerate) + self.print_error("new feerate", feerate_per_kw) + if feerate_per_kw < chan.remote_state.feerate / 2: + self.print_error("FEES HAVE FALLEN") + chan.update_fee(feerate_per_kw) + elif feerate_per_kw > chan.remote_state.feerate * 2: + self.print_error("FEES HAVE RISEN") + chan.update_fee(feerate_per_kw) + else: + return + self.send_message(gen_msg("update_fee", channel_id=chan.channel_id, feerate_per_kw=feerate_per_kw)) + self.lnworker.save_channel(chan) diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -46,7 +46,7 @@ class LNWorker(PrintError): for host, port, pubkey in peer_list: self.add_peer(host, int(port), bfh(pubkey)) # wait until we see confirmations - self.network.register_callback(self.on_network_update, ['updated', 'verified']) # thread safe + self.network.register_callback(self.on_network_update, ['updated', 'verified', 'fee_histogram']) # thread safe self.on_network_update('updated') # shortcut (don't block) if funding tx locked and verified self.network.futures.append(asyncio.run_coroutine_threadsafe(self.main_loop(), asyncio.get_event_loop())) @@ -124,6 +124,8 @@ class LNWorker(PrintError): peer = self.peers[chan.node_id] peer.funding_locked(chan) elif chan.state == "OPEN": + if event == 'fee_histogram': + peer.on_bitcoin_fee_update(chan) conf = self.wallet.get_tx_height(chan.funding_outpoint.txid)[1] peer = self.peers[chan.node_id] peer.on_network_update(chan, conf)