electrum

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

commit 15a6a83107607d99079863bffc65805472376784
parent f3e5ba6ac16e8e30879079a8a18f7ad931a6017a
Author: SomberNight <somber.night@protonmail.com>
Date:   Tue, 31 Jul 2018 14:36:42 +0200

ln onchain fees: use 2 block ETAs with 150 s/b fallback

Diffstat:
Melectrum/lnbase.py | 16+++++++++-------
Melectrum/lnhtlc.py | 1-
Melectrum/lnworker.py | 4++--
Melectrum/simple_config.py | 1+
4 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/electrum/lnbase.py b/electrum/lnbase.py @@ -284,7 +284,6 @@ def aiosafe(f): class Peer(PrintError): def __init__(self, lnworker, host, port, pubkey, request_initial_sync=False): - self.REV_GENESIS = bytes.fromhex(bitcoin.rev_hex(constants.net.GENESIS)) self.exception = None # set by aiosafe self.host = host self.port = port @@ -499,7 +498,7 @@ class Peer(PrintError): keyfamilyrevocationroot = 5 keyfamilynodekey = 6 # TODO currently unused # amounts - local_feerate = 20000 + local_feerate = self.current_feerate_per_kw() # key derivation keypair_generator = lambda family, i: Keypair(*wallet.keystore.get_keypair([family, i], password)) local_config=ChannelConfig( @@ -522,7 +521,7 @@ class Peer(PrintError): msg = gen_msg( "open_channel", temporary_channel_id=temp_channel_id, - chain_hash=self.REV_GENESIS, + chain_hash=constants.net.rev_genesis_bytes(), funding_satoshis=funding_sat, push_msat=push_msat, dust_limit_satoshis=local_config.dust_limit_sat, @@ -734,7 +733,7 @@ class Peer(PrintError): bitcoin_signature_2=bitcoin_sigs[1], len=0, #features not set (defaults to zeros) - chain_hash=self.REV_GENESIS, + chain_hash=constants.net.rev_genesis_bytes(), short_channel_id=chan.short_channel_id, node_id_1=node_ids[0], node_id_2=node_ids[1], @@ -791,7 +790,7 @@ class Peer(PrintError): chan_ann = gen_msg("channel_announcement", len=0, #features not set (defaults to zeros) - chain_hash=self.REV_GENESIS, + chain_hash=constants.net.rev_genesis_bytes(), short_channel_id=chan.short_channel_id, node_id_1=node_ids[0], node_id_2=node_ids[1], @@ -1034,7 +1033,7 @@ class Peer(PrintError): def on_bitcoin_fee_update(self, chan): """ - called when the fee histogram (based on current mempool) changed + called when our fee estimates change """ if not chan.constraints.is_initiator: # TODO force close if initiator does not update_fee enough @@ -1056,5 +1055,8 @@ class Peer(PrintError): self.lnworker.save_channel(chan) def current_feerate_per_kw(self): - feerate_per_kvbyte = self.network.config.depth_target_to_fee(10*1000000) # 10 MB + from .simple_config import FEE_LN_ETA_TARGET, FEERATE_FALLBACK_STATIC_FEE + feerate_per_kvbyte = self.network.config.eta_target_to_fee(FEE_LN_ETA_TARGET) + if feerate_per_kvbyte is None: + feerate_per_kvbyte = FEERATE_FALLBACK_STATIC_FEE return max(253, feerate_per_kvbyte // 4) diff --git a/electrum/lnhtlc.py b/electrum/lnhtlc.py @@ -572,7 +572,6 @@ class HTLCStateMachine(PrintError): "constraints": self.constraints, "funding_outpoint": self.funding_outpoint, "node_id": self.node_id, - "channel_id": self.channel_id } def serialize(self): diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -53,7 +53,7 @@ class LNWorker(PrintError): self._last_tried_peer = {} # LNPeerAddr -> unix timestamp self._add_peers_from_config() # wait until we see confirmations - self.network.register_callback(self.on_network_update, ['updated', 'verified', 'fee_histogram']) # thread safe + self.network.register_callback(self.on_network_update, ['updated', 'verified', 'fee']) # 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())) @@ -151,7 +151,7 @@ class LNWorker(PrintError): if peer is None: self.print_error("peer not found for {}".format(bh2u(chan.node_id))) return - if event == 'fee_histogram': + if event == 'fee': peer.on_bitcoin_fee_update(chan) conf = self.wallet.get_tx_height(chan.funding_outpoint.txid)[1] peer.on_network_update(chan, conf) diff --git a/electrum/simple_config.py b/electrum/simple_config.py @@ -18,6 +18,7 @@ from .logging import get_logger, Logger FEE_ETA_TARGETS = [25, 10, 5, 2] FEE_DEPTH_TARGETS = [10000000, 5000000, 2000000, 1000000, 500000, 200000, 100000] +FEE_LN_ETA_TARGET = 2 # note: make sure the network is asking for estimates for this target # satoshi per kbyte FEERATE_MAX_DYNAMIC = 1500000