Browse Source

ln: warn when negotiated feerate is too low

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
Janus 6 years ago
committed by ThomasV
parent
commit
7cf4f40dcb
  1. 13
      electrum/lnbase.py
  2. 13
      electrum/lnworker.py

13
electrum/lnbase.py

@ -423,7 +423,7 @@ class Peer(PrintError):
funding_tx_test = wallet.mktx([TxOutput(bitcoin.TYPE_ADDRESS, wallet.dummy_address(), funding_sat)],
password, self.lnworker.config, nonlocal_only=True)
await self.initialized
feerate = self.current_feerate_per_kw()
feerate = self.lnworker.current_feerate_per_kw()
local_config = self.make_local_config(funding_sat, push_msat, LOCAL)
# for the first commitment transaction
per_commitment_secret_first = get_per_commitment_secret_from_seed(local_config.per_commitment_secret_seed,
@ -1131,7 +1131,7 @@ class Peer(PrintError):
if not chan.constraints.is_initiator:
# TODO force close if initiator does not update_fee enough
return
feerate_per_kw = self.current_feerate_per_kw()
feerate_per_kw = self.lnworker.current_feerate_per_kw()
chan_fee = chan.pending_feerate(REMOTE)
self.print_error("current pending feerate", chan_fee)
self.print_error("new feerate", feerate_per_kw)
@ -1144,15 +1144,6 @@ class Peer(PrintError):
chan.update_fee(feerate_per_kw, True)
await self.update_channel(chan, "update_fee", channel_id=chan.channel_id, feerate_per_kw=feerate_per_kw)
def current_feerate_per_kw(self):
from .simple_config import FEE_LN_ETA_TARGET, FEERATE_FALLBACK_STATIC_FEE, FEERATE_REGTEST_HARDCODED
if constants.net is constants.BitcoinRegtest:
return FEERATE_REGTEST_HARDCODED // 4
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)
def on_closing_signed(self, payload):
chan_id = payload["channel_id"]
if chan_id not in self.closing_signed: raise Exception("Got unknown closing_signed")

13
electrum/lnworker.py

@ -760,6 +760,10 @@ class LNWorker(PrintError):
channels = list(self.channels.values())
now = time.time()
for chan in channels:
if constants.net is not constants.BitcoinRegtest:
ratio = chan.constraints.feerate / self.current_feerate_per_kw()
if ratio < 0.5:
self.print_error(f"WARNING: fee level for channel {bh2u(chan.channel_id)} is {chan.constraints.feerate} sat/kiloweight, current recommended feerate is {self.current_feerate_per_kw()} sat/kiloweight, consider force closing!")
if not chan.should_try_to_reestablish_peer():
continue
peer = self.peers.get(chan.node_id, None)
@ -769,6 +773,15 @@ class LNWorker(PrintError):
coro = peer.reestablish_channel(chan)
asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop)
def current_feerate_per_kw(self):
from .simple_config import FEE_LN_ETA_TARGET, FEERATE_FALLBACK_STATIC_FEE, FEERATE_REGTEST_HARDCODED
if constants.net is constants.BitcoinRegtest:
return FEERATE_REGTEST_HARDCODED // 4
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)
async def main_loop(self):
await self.on_network_update('network_updated') # shortcut (don't block) if funding tx locked and verified
await self.network.lnwatcher.on_network_update('network_updated') # ping watcher to check our channels

Loading…
Cancel
Save