tlnchannel: only consider payments finished when we revoke our old ctx - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 7292da24e6fa2813056f9d0843af568c6eb0a413 DIR parent a565c500f6090cd9a388dbf5ed9aebac25dd9e3d HTML Author: SomberNight <somber.night@protonmail.com> Date: Tue, 26 Feb 2019 20:56:48 +0100 lnchannel: only consider payments finished when we revoke our old ctx in the old code, `self.hm.received_in_ctn(self.config[REMOTE].ctn + 1)` did not really make sense as "received_in_ctn" compares the argument against the LOCAL ctn Diffstat: M electrum/lnchannel.py | 26 ++++++++++++-------------- M electrum/lnworker.py | 2 +- M electrum/tests/test_lnchannel.py | 6 +++--- 3 files changed, 16 insertions(+), 18 deletions(-) --- DIR diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py t@@ -435,7 +435,17 @@ class Channel(PrintError): ) assert self.signature_fits(ctx) - return RevokeAndAck(last_secret, next_point), "current htlcs" + received = self.hm.received_in_ctn(self.config[LOCAL].ctn) + sent = self.hm.sent_in_ctn(self.config[LOCAL].ctn) + for htlc in received: + self.payment_completed(self, RECEIVED, htlc, None) + for htlc in sent: + preimage = self.preimages.pop(htlc.htlc_id) + self.payment_completed(self, SENT, htlc, preimage) + received_this_batch = htlcsum(received) + sent_this_batch = htlcsum(sent) + + return RevokeAndAck(last_secret, next_point), (received_this_batch, sent_this_batch) def points(self): last_small_num = self.config[LOCAL].ctn t@@ -459,7 +469,7 @@ class Channel(PrintError): if tx is not None: self.lnwatcher.add_sweep_tx(outpoint, prev_txid, tx.as_dict()) - def receive_revocation(self, revocation) -> Tuple[int, int]: + def receive_revocation(self, revocation: RevokeAndAck): self.print_error("receive_revocation") cur_point = self.config[REMOTE].current_per_commitment_point t@@ -483,16 +493,6 @@ class Channel(PrintError): if self.constraints.is_initiator and self.pending_fee[FUNDEE_ACKED]: self.pending_fee[FUNDER_SIGNED] = True - received = self.hm.received_in_ctn(self.config[REMOTE].ctn + 1) - sent = self.hm.sent_in_ctn(self.config[REMOTE].ctn + 1) - for htlc in received: - self.payment_completed(self, RECEIVED, htlc, None) - for htlc in sent: - preimage = self.preimages.pop(htlc.htlc_id) - self.payment_completed(self, SENT, htlc, preimage) - received_this_batch = htlcsum(received) - sent_this_batch = htlcsum(sent) - next_point = self.config[REMOTE].next_per_commitment_point self.hm.recv_rev() t@@ -510,8 +510,6 @@ class Channel(PrintError): self.set_remote_commitment() self.remote_commitment_to_be_revoked = prev_remote_commitment - return received_this_batch, sent_this_batch - def balance(self, subject, ctn=None): """ This balance in mSAT is not including reserve and fees. DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py t@@ -565,7 +565,7 @@ class LNWorker(PrintError): self.storage.put('lightning_preimages', self.preimages) self.storage.write() - def get_preimage_and_timestamp(self, payment_hash: bytes) -> bytes: + def get_preimage_and_timestamp(self, payment_hash: bytes) -> Tuple[bytes, int]: try: preimage_hex, timestamp = self.preimages[bh2u(payment_hash)] preimage = bfh(preimage_hex) DIR diff --git a/electrum/tests/test_lnchannel.py b/electrum/tests/test_lnchannel.py t@@ -433,10 +433,10 @@ class TestChannel(unittest.TestCase): bob_channel.receive_new_commitment(aliceSig2, aliceHtlcSigs2) - bobRevocation2, _ = bob_channel.revoke_current_commitment() + bobRevocation2, (received, sent) = bob_channel.revoke_current_commitment() + self.assertEqual(one_bitcoin_in_msat, received) bob_channel.serialize() - received, sent = alice_channel.receive_revocation(bobRevocation2) - self.assertEqual(sent, one_bitcoin_in_msat) + alice_channel.receive_revocation(bobRevocation2) alice_channel.serialize() # At this point, Bob should have 6 BTC settled, with Alice still having