mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 08:51:32 +00:00
ln: share more code with control path for failed htlc, verify ctx'es
This commit is contained in:
parent
5011578790
commit
add2ef5d87
2 changed files with 19 additions and 37 deletions
|
@ -879,12 +879,9 @@ class Peer(PrintError):
|
||||||
self.attempted_route[(chan.channel_id, htlc.htlc_id)] = route
|
self.attempted_route[(chan.channel_id, htlc.htlc_id)] = route
|
||||||
|
|
||||||
sig_64, htlc_sigs = chan.sign_next_commitment()
|
sig_64, htlc_sigs = chan.sign_next_commitment()
|
||||||
|
|
||||||
self.send_message(gen_msg("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=len(htlc_sigs), htlc_signature=b"".join(htlc_sigs)))
|
self.send_message(gen_msg("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=len(htlc_sigs), htlc_signature=b"".join(htlc_sigs)))
|
||||||
await self.receive_revoke(chan)
|
await self.receive_revoke(chan)
|
||||||
|
|
||||||
await self.receive_commitment(chan)
|
await self.receive_commitment(chan)
|
||||||
|
|
||||||
self.revoke(chan)
|
self.revoke(chan)
|
||||||
|
|
||||||
fulfill_coro = asyncio.ensure_future(self.update_fulfill_htlc[chan.channel_id].get())
|
fulfill_coro = asyncio.ensure_future(self.update_fulfill_htlc[chan.channel_id].get())
|
||||||
|
@ -892,42 +889,31 @@ class Peer(PrintError):
|
||||||
|
|
||||||
done, pending = await asyncio.wait([fulfill_coro, failure_coro], return_when=FIRST_COMPLETED)
|
done, pending = await asyncio.wait([fulfill_coro, failure_coro], return_when=FIRST_COMPLETED)
|
||||||
if failure_coro.done():
|
if failure_coro.done():
|
||||||
|
fulfill_coro.cancel()
|
||||||
sig_64, htlc_sigs = chan.sign_next_commitment()
|
sig_64, htlc_sigs = chan.sign_next_commitment()
|
||||||
# TODO this is wrong when the htlc is dust
|
self.send_message(gen_msg("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=len(htlc_sigs), htlc_signature=b"".join(htlc_sigs)))
|
||||||
self.send_message(gen_msg("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=1, htlc_signature=htlc_sigs[0]))
|
|
||||||
self.revoke(chan)
|
|
||||||
while (await self.commitment_signed[chan.channel_id].get())["htlc_signature"] != b"":
|
|
||||||
pass
|
|
||||||
# TODO process above commitment transactions
|
|
||||||
await self.receive_revoke(chan)
|
await self.receive_revoke(chan)
|
||||||
chan.fail_htlc(htlc)
|
chan.fail_htlc(htlc)
|
||||||
|
await self.receive_commitment(chan)
|
||||||
|
self.revoke(chan)
|
||||||
sig_64, htlc_sigs = chan.sign_next_commitment()
|
sig_64, htlc_sigs = chan.sign_next_commitment()
|
||||||
self.send_message(gen_msg("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=0))
|
res = failure_coro.result()
|
||||||
await self.receive_revoke(chan)
|
else:
|
||||||
fulfill_coro.cancel()
|
failure_coro.cancel()
|
||||||
self.lnworker.save_channel(chan)
|
update_fulfill_htlc_msg = fulfill_coro.result()
|
||||||
return failure_coro.result()
|
preimage = update_fulfill_htlc_msg["payment_preimage"]
|
||||||
|
chan.receive_htlc_settle(preimage, int.from_bytes(update_fulfill_htlc_msg["id"], "big"))
|
||||||
|
await self.receive_commitment(chan)
|
||||||
|
self.revoke(chan)
|
||||||
|
bare_ctx = chan.make_commitment(chan.remote_state.ctn + 1, False, chan.remote_state.next_per_commitment_point,
|
||||||
|
msat_remote, msat_local)
|
||||||
|
sig_64 = sign_and_get_sig_string(bare_ctx, chan.local_config, chan.remote_config)
|
||||||
|
res = bh2u(preimage)
|
||||||
|
|
||||||
failure_coro.cancel()
|
|
||||||
update_fulfill_htlc_msg = fulfill_coro.result()
|
|
||||||
|
|
||||||
preimage = update_fulfill_htlc_msg["payment_preimage"]
|
|
||||||
chan.receive_htlc_settle(preimage, int.from_bytes(update_fulfill_htlc_msg["id"], "big"))
|
|
||||||
|
|
||||||
await self.receive_commitment(chan)
|
|
||||||
|
|
||||||
self.revoke(chan)
|
|
||||||
|
|
||||||
bare_ctx = chan.make_commitment(chan.remote_state.ctn + 1, False, chan.remote_state.next_per_commitment_point,
|
|
||||||
msat_remote, msat_local)
|
|
||||||
|
|
||||||
sig_64 = sign_and_get_sig_string(bare_ctx, chan.local_config, chan.remote_config)
|
|
||||||
self.send_message(gen_msg("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=0))
|
self.send_message(gen_msg("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=0))
|
||||||
|
|
||||||
await self.receive_revoke(chan)
|
await self.receive_revoke(chan)
|
||||||
|
|
||||||
self.lnworker.save_channel(chan)
|
self.lnworker.save_channel(chan)
|
||||||
return bh2u(preimage)
|
return res
|
||||||
|
|
||||||
async def receive_revoke(self, m):
|
async def receive_revoke(self, m):
|
||||||
revoke_and_ack_msg = await self.revoke_and_ack[m.channel_id].get()
|
revoke_and_ack_msg = await self.revoke_and_ack[m.channel_id].get()
|
||||||
|
@ -996,9 +982,7 @@ class Peer(PrintError):
|
||||||
|
|
||||||
if commit_coro.done():
|
if commit_coro.done():
|
||||||
# this branch is taken with lnd after a fee update (initiated by us, of course)
|
# this branch is taken with lnd after a fee update (initiated by us, of course)
|
||||||
|
await revoke_coro
|
||||||
# TODO await process_commit(chan, commit_coro.result())
|
|
||||||
await asyncio.wait([revoke_coro])
|
|
||||||
process_revoke(revoke_coro.result())
|
process_revoke(revoke_coro.result())
|
||||||
self.revoke(chan)
|
self.revoke(chan)
|
||||||
await self.receive_commitment(chan)
|
await self.receive_commitment(chan)
|
||||||
|
@ -1010,7 +994,7 @@ class Peer(PrintError):
|
||||||
elif revoke_coro.done():
|
elif revoke_coro.done():
|
||||||
process_revoke(revoke_coro.result())
|
process_revoke(revoke_coro.result())
|
||||||
|
|
||||||
await asyncio.wait([commit_coro])
|
await commit_coro
|
||||||
await self.receive_commitment(chan, commit_coro.result())
|
await self.receive_commitment(chan, commit_coro.result())
|
||||||
self.revoke(chan)
|
self.revoke(chan)
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,6 @@ class TestLNBaseHTLCStateMachine(unittest.TestCase):
|
||||||
payment_hash = paymentHash,
|
payment_hash = paymentHash,
|
||||||
amount_msat = one_bitcoin_in_msat,
|
amount_msat = one_bitcoin_in_msat,
|
||||||
cltv_expiry = 5,
|
cltv_expiry = 5,
|
||||||
total_fee = 0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# First Alice adds the outgoing HTLC to her local channel's state
|
# First Alice adds the outgoing HTLC to her local channel's state
|
||||||
|
@ -326,7 +325,6 @@ class TestLNHTLCDust(unittest.TestCase):
|
||||||
payment_hash = paymentHash,
|
payment_hash = paymentHash,
|
||||||
amount_msat = 1000 * htlcAmt,
|
amount_msat = 1000 * htlcAmt,
|
||||||
cltv_expiry = 5, # also in create_test_channels
|
cltv_expiry = 5, # also in create_test_channels
|
||||||
total_fee = 0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
aliceHtlcIndex = alice_channel.add_htlc(htlc)
|
aliceHtlcIndex = alice_channel.add_htlc(htlc)
|
||||||
|
|
Loading…
Add table
Reference in a new issue