Browse Source

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
dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
SomberNight 6 years ago
committed by ThomasV
parent
commit
7292da24e6
  1. 26
      electrum/lnchannel.py
  2. 2
      electrum/lnworker.py
  3. 6
      electrum/tests/test_lnchannel.py

26
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.

2
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)

6
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

Loading…
Cancel
Save