move feerate warning to lnpeer

This commit is contained in:
ThomasV 2020-03-06 18:14:00 +01:00
parent ee01ca352f
commit 2c617c3b00
2 changed files with 14 additions and 11 deletions

View file

@ -1249,16 +1249,25 @@ class Peer(Logger):
chan = self.channels[channel_id] chan = self.channels[channel_id]
chan.update_fee(feerate, False) chan.update_fee(feerate, False)
async def bitcoin_fee_update(self, chan: Channel): async def maybe_update_fee(self, chan: Channel):
""" """
called when our fee estimates change called when our fee estimates change
""" """
if not chan.can_send_ctx_updates(): if not chan.can_send_ctx_updates():
return return
if not chan.constraints.is_initiator:
# TODO force close if initiator does not update_fee enough
return
feerate_per_kw = self.lnworker.current_feerate_per_kw() feerate_per_kw = self.lnworker.current_feerate_per_kw()
if not chan.constraints.is_initiator:
if constants.net is not constants.BitcoinRegtest:
chan_feerate = chan.get_latest_feerate(LOCAL)
ratio = chan_feerate / feerate_per_kw
if ratio < 0.5:
# Note that we trust the Electrum server about fee rates
# Thus, automated force-closing might not be a good idea
# Maybe we should display something in the GUI instead
self.logger.warning(
f"({chan.get_id_for_log()}) feerate is {chan_feerate} sat/kw, "
f"current recommended feerate is {feerate_per_kw} sat/kw, consider force closing!")
return
chan_fee = chan.get_next_feerate(REMOTE) chan_fee = chan.get_next_feerate(REMOTE)
if feerate_per_kw < chan_fee / 2: if feerate_per_kw < chan_fee / 2:
self.logger.info("FEES HAVE FALLEN") self.logger.info("FEES HAVE FALLEN")

View file

@ -751,7 +751,7 @@ class LNWallet(LNWorker):
if peer is None: if peer is None:
self.logger.info("peer not found for {}".format(bh2u(chan.node_id))) self.logger.info("peer not found for {}".format(bh2u(chan.node_id)))
return return
await peer.bitcoin_fee_update(chan) await peer.maybe_update_fee(chan)
conf = self.lnwatcher.get_tx_height(chan.funding_outpoint.txid).conf conf = self.lnwatcher.get_tx_height(chan.funding_outpoint.txid).conf
peer.on_network_update(chan, conf) peer.on_network_update(chan, conf)
@ -1362,12 +1362,6 @@ class LNWallet(LNWorker):
for chan in channels: for chan in channels:
if chan.is_closed(): if chan.is_closed():
continue continue
if constants.net is not constants.BitcoinRegtest:
chan_feerate = chan.get_latest_feerate(LOCAL)
ratio = chan_feerate / self.current_feerate_per_kw()
if ratio < 0.5:
self.logger.warning(f"fee level for channel {bh2u(chan.channel_id)} is {chan_feerate} sat/kiloweight, "
f"current recommended feerate is {self.current_feerate_per_kw()} sat/kiloweight, consider force closing!")
# reestablish # reestablish
if not chan.should_try_to_reestablish_peer(): if not chan.should_try_to_reestablish_peer():
continue continue