diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py index ac2433dee..2c956b56b 100644 --- a/electrum/lnchannel.py +++ b/electrum/lnchannel.py @@ -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 @@ -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 @@ -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() @@ -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. diff --git a/electrum/lnworker.py b/electrum/lnworker.py index 9c5a870f3..e5db77bed 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -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) diff --git a/electrum/tests/test_lnchannel.py b/electrum/tests/test_lnchannel.py index b27cdc085..d327194a9 100644 --- a/electrum/tests/test_lnchannel.py +++ b/electrum/tests/test_lnchannel.py @@ -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