mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
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
This commit is contained in:
parent
a565c500f6
commit
7292da24e6
3 changed files with 16 additions and 18 deletions
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue