From 393282d03837f55a624f6270e7d2c413b2e14005 Mon Sep 17 00:00:00 2001 From: Janus Date: Wed, 26 Sep 2018 15:08:57 +0200 Subject: [PATCH] ln fees: avoid resending same fee update before it has been committed to, docs --- electrum/lnbase.py | 7 ++++--- electrum/lnhtlc.py | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/electrum/lnbase.py b/electrum/lnbase.py index 209c20051..763dd01b1 100644 --- a/electrum/lnbase.py +++ b/electrum/lnbase.py @@ -1049,12 +1049,13 @@ class Peer(PrintError): return feerate_per_kw = self.current_feerate_per_kw() - self.print_error("current feerate", chan.remote_state.feerate) + chan_fee = chan.pending_feerate(REMOTE) + self.print_error("current pending feerate", chan_fee) self.print_error("new feerate", feerate_per_kw) - if feerate_per_kw < chan.remote_state.feerate / 2: + if feerate_per_kw < chan_fee / 2: self.print_error("FEES HAVE FALLEN") chan.update_fee(feerate_per_kw) - elif feerate_per_kw > chan.remote_state.feerate * 2: + elif feerate_per_kw > chan_fee * 2: self.print_error("FEES HAVE RISEN") chan.update_fee(feerate_per_kw) else: diff --git a/electrum/lnhtlc.py b/electrum/lnhtlc.py index 5ed04e710..ebfc7fa59 100644 --- a/electrum/lnhtlc.py +++ b/electrum/lnhtlc.py @@ -62,9 +62,17 @@ class FeeUpdate: self.progress[field] = self.height def is_proposed(self): + """ + returns True when this FeeUpdate has been proposed + at or above the current commitment number of the funder + """ return self.progress[COMMITTED] is None and self.proposed is not None and self.proposed <= self.height def had(self, field): + """ + returns true when the progress field given has been + set at the current commitment number of the funder + """ return self.progress[field] is not None and self.height >= self.progress[field] def pending_feerate(self, subject): @@ -76,6 +84,7 @@ class FeeUpdate: return self.rate if subject == LOCAL and not self.chan.constraints.is_initiator: return self.rate + # implicit return None def to_save(self): return {'rate': self.rate, 'proposed': self.proposed, 'progress': self.progress}