1
0

Fix detection of payments.

1. In lnhtlc, sent_in_ctn and failed_in_ctn need to look at the
remote ctx, and they need to be called when we receive a revocation,
not when we send one.

2. In lnchannel, we use 3 lnworker callbacks:
   - payment sent/payment failed (called when we receive a revocation)
   - payment received (called when we send a revocation)

3. Make revoke_current_commitment return a single value.
The second value was only used in tests, there is no need
to bloat the code with that
This commit is contained in:
ThomasV
2020-03-04 18:09:43 +01:00
parent b9eaba3e85
commit 8f3fcdd1a8
7 changed files with 51 additions and 45 deletions

View File

@@ -316,7 +316,7 @@ class TestChannel(ElectrumTestCase):
# Bob revokes his prior commitment given to him by Alice, since he now
# has a valid signature for a newer commitment.
bobRevocation, _ = bob_channel.revoke_current_commitment()
bobRevocation = bob_channel.revoke_current_commitment()
self.assertTrue(bob_channel.signature_fits(bob_channel.get_latest_commitment(LOCAL)))
# Bob finally sends a signature for Alice's commitment transaction.
@@ -365,7 +365,7 @@ class TestChannel(ElectrumTestCase):
self.assertNotEqual(tx0, tx1)
# Alice then generates a revocation for bob.
aliceRevocation, _ = alice_channel.revoke_current_commitment()
aliceRevocation = alice_channel.revoke_current_commitment()
tx2 = str(alice_channel.force_close_tx())
# since alice already has the signature for the next one, it doesn't change her force close tx (it was already the newer one)
@@ -441,7 +441,7 @@ class TestChannel(ElectrumTestCase):
self.assertEqual(alice_channel.balance(LOCAL), 500000000000)
self.assertEqual(1, alice_channel.get_oldest_unrevoked_ctn(LOCAL))
self.assertEqual(len(alice_channel.included_htlcs(LOCAL, RECEIVED, ctn=2)), 0)
aliceRevocation2, _ = alice_channel.revoke_current_commitment()
aliceRevocation2 = alice_channel.revoke_current_commitment()
aliceSig2, aliceHtlcSigs2 = alice_channel.sign_next_commitment()
self.assertEqual(aliceHtlcSigs2, [], "alice should generate no htlc signatures")
self.assertEqual(len(bob_channel.get_latest_commitment(LOCAL).outputs()), 3)
@@ -449,7 +449,8 @@ class TestChannel(ElectrumTestCase):
bob_channel.receive_new_commitment(aliceSig2, aliceHtlcSigs2)
bobRevocation2, (received, sent) = bob_channel.revoke_current_commitment()
bobRevocation2 = bob_channel.revoke_current_commitment()
received = lnchannel.htlcsum(bob_channel.hm.received_in_ctn(bob_channel.get_latest_ctn(LOCAL)))
self.assertEqual(one_bitcoin_in_msat, received)
alice_channel.receive_revocation(bobRevocation2)
@@ -525,7 +526,7 @@ class TestChannel(ElectrumTestCase):
self.assertNotEqual(fee, bob_channel.get_oldest_unrevoked_feerate(LOCAL))
self.assertEqual(fee, bob_channel.get_latest_feerate(LOCAL))
rev, _ = bob_channel.revoke_current_commitment()
rev = bob_channel.revoke_current_commitment()
self.assertEqual(fee, bob_channel.get_oldest_unrevoked_feerate(LOCAL))
alice_channel.receive_revocation(rev)
@@ -536,7 +537,7 @@ class TestChannel(ElectrumTestCase):
self.assertNotEqual(fee, alice_channel.get_oldest_unrevoked_feerate(LOCAL))
self.assertEqual(fee, alice_channel.get_latest_feerate(LOCAL))
rev, _ = alice_channel.revoke_current_commitment()
rev = alice_channel.revoke_current_commitment()
self.assertEqual(fee, alice_channel.get_oldest_unrevoked_feerate(LOCAL))
bob_channel.receive_revocation(rev)
@@ -552,14 +553,14 @@ class TestChannel(ElectrumTestCase):
bob_sig, bob_htlc_sigs = bob_channel.sign_next_commitment()
alice_channel.receive_new_commitment(bob_sig, bob_htlc_sigs)
alice_revocation, _ = alice_channel.revoke_current_commitment()
alice_revocation = alice_channel.revoke_current_commitment()
bob_channel.receive_revocation(alice_revocation)
alice_sig, alice_htlc_sigs = alice_channel.sign_next_commitment()
bob_channel.receive_new_commitment(alice_sig, alice_htlc_sigs)
self.assertNotEqual(fee, bob_channel.get_oldest_unrevoked_feerate(LOCAL))
self.assertEqual(fee, bob_channel.get_latest_feerate(LOCAL))
bob_revocation, _ = bob_channel.revoke_current_commitment()
bob_revocation = bob_channel.revoke_current_commitment()
self.assertEqual(fee, bob_channel.get_oldest_unrevoked_feerate(LOCAL))
bob_sig, bob_htlc_sigs = bob_channel.sign_next_commitment()
@@ -568,7 +569,7 @@ class TestChannel(ElectrumTestCase):
self.assertNotEqual(fee, alice_channel.get_oldest_unrevoked_feerate(LOCAL))
self.assertEqual(fee, alice_channel.get_latest_feerate(LOCAL))
alice_revocation, _ = alice_channel.revoke_current_commitment()
alice_revocation = alice_channel.revoke_current_commitment()
self.assertEqual(fee, alice_channel.get_oldest_unrevoked_feerate(LOCAL))
bob_channel.receive_revocation(alice_revocation)
@@ -805,11 +806,11 @@ class TestDust(ElectrumTestCase):
def force_state_transition(chanA, chanB):
chanB.receive_new_commitment(*chanA.sign_next_commitment())
rev, _ = chanB.revoke_current_commitment()
rev = chanB.revoke_current_commitment()
bob_sig, bob_htlc_sigs = chanB.sign_next_commitment()
chanA.receive_revocation(rev)
chanA.receive_new_commitment(bob_sig, bob_htlc_sigs)
chanB.receive_revocation(chanA.revoke_current_commitment()[0])
chanB.receive_revocation(chanA.revoke_current_commitment())
# calcStaticFee calculates appropriate fees for commitment transactions. This
# function provides a simple way to allow test balance assertions to take fee

View File

@@ -126,6 +126,7 @@ class MockLNWallet:
await_payment = LNWallet.await_payment
payment_received = LNWallet.payment_received
payment_sent = LNWallet.payment_sent
payment_failed = LNWallet.payment_failed
save_preimage = LNWallet.save_preimage
get_preimage = LNWallet.get_preimage
_create_route_from_invoice = LNWallet._create_route_from_invoice
@@ -134,7 +135,7 @@ class MockLNWallet:
_pay = LNWallet._pay
force_close_channel = LNWallet.force_close_channel
get_first_timestamp = lambda self: 0
payment_completed = LNWallet.payment_completed
class MockTransport:
def __init__(self, name):