1
0
Commit Graph

90 Commits

Author SHA1 Message Date
Sander van Grieken
eda88b2972 lnaddr: fix outdated doc reference to lnworker._check_invoice
(and clean some imports/whitespace while we're at it)
2025-05-02 15:57:01 +02:00
SomberNight
373db76ac9 util: kill bh2u
no longer useful, and the name is so confusing...
2023-02-17 11:43:11 +00:00
ThomasV
a5965933d2 Fix CTNs in should_be_closed_due_to_expiring_htlcs (fixes #7906).
Also fix sending too many fee updates.
Rename lnworker.on_channel_update, that name was misleading.
2022-08-02 18:00:39 +02:00
SomberNight
ef4477a930 lnpeer.reestablish_chan: enforce order of replaying commitsig/revack
When replaying messages during channel-reestablishment,
previously we first resent all update messages, along with potential commitment_signed messages,
and then we potentially resent a single revoke_and_ack.

This can result in incorrect behaviour in case both a commitment_signed and a revoke_and_ack needs to be resent.
When replaying messages, the relative order of commitment_signed and revoke_and_messages needs to be preserved.
(the order of updates (htlc/fee) in relation to the revack messages does not matter)

implements https://github.com/lightning/bolts/pull/810

The logic here is somewhat based on what c-lightning does:
01e5f1886e/channeld/channeld.c (L3059)
2022-05-25 19:44:44 +02:00
ThomasV
b431d8e9b8 follow-up eadd1bebb2 2021-09-24 17:36:33 +02:00
ThomasV
7a0904c0f4 wallet update: move fields that have string keys out of channel log 2021-09-20 14:47:20 +02:00
bitromortac
63308f94a0 reorganize with_lock decorator 2021-04-02 09:38:39 +02:00
SomberNight
cb78f73ed0 lnworker: try to fail pending HTLCs when shutting down
This is most useful when receiving MPP where there is a non-trivial chance
that we have received some HTLCs for a payment but not all, and the user
closes the program. We try to fail them and wait for the fails to get
ACKed, with a timeout of course.
2021-03-11 19:31:22 +01:00
SomberNight
05e58671c9 lnhtlc: (trivial) rename method 2021-03-11 19:09:35 +01:00
SomberNight
f84f13529a lnhtlc: fix deadlock 2021-03-03 22:05:09 +01:00
SomberNight
6094f2751e kivy channel dialog: fix unit of displayed feerate
The amount shown was in sat/kw, incorrectly labeled as sat/kbyte.
Show sat/vbyte instead.
2021-03-01 17:09:04 +01:00
SomberNight
e8a2fa5596 tests: lnpeer.htlc_switch: don't fulfill htlc until add is irrevocable
This adds a failing test, where the HTLC switch fulfills an HTLC too soon,
before the corresponding 'update_add_htlc' is irrevocably committed.
2021-01-28 20:00:48 +01:00
SomberNight
2d739981c2 lnhtlc: fix prev: too much copy-paste 2020-09-05 17:49:02 +02:00
SomberNight
aba2e0f55a lnhtlc: add all_htlcs_ever, get_htlc_by_id, was_htlc_failed and use them
towards encapsulation of hm.log
2020-09-04 19:29:14 +02:00
SomberNight
51f42a25f9 lnhtlc: add lock to make methods thread-safe
many methods are accessed from both the asyncio thread and the GUI thread

fixes #6373
2020-09-04 19:29:11 +02:00
ThomasV
c1b1638615 fix htlc forwarding:
- persist fail_htlc error messages
 - do not rely on payment_hash in htlc_switch
2020-05-05 09:23:48 +02:00
SomberNight
9a70b79eea follow-up prev: try to handle json db int key madness :/ 2020-03-17 20:32:27 +01:00
SomberNight
b524460fdf lnpeer: implement basic handling of "update_fail_malformed_htlc" 2020-03-17 20:31:50 +01:00
SomberNight
5b23d5ee97 lnchannel/lnhtlc: speed up balance calculation for recent ctns
Move the balance calculation from lnchannel to lnhtlc.
Maintain a running balance in lnhtlc that is coupled with _maybe_active_htlc_ids
for practicality reasons.
2020-03-07 05:05:05 +01:00
SomberNight
ec7473789e lnhtlc: speed-up methods for recent ctns
we maintain a set of interesting htlc_ids
2020-03-06 21:54:05 +01:00
ThomasV
c15cc42a32 fix for old channels 2020-03-05 14:52:56 +01:00
ThomasV
8f3fcdd1a8 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
2020-03-05 07:03:09 +01:00
ThomasV
b9eaba3e85 replace await_local/remote 2020-03-05 07:03:09 +01:00
ThomasV
da67fda92a HTLC switch:
- fulfills/fails/forwards HTLCs
- onion_packets are saved when update_add_htlc is received
2020-03-02 11:19:04 +01:00
ThomasV
dbceed2647 Restructure wallet storage:
- Perform json deserializations in wallet_db
 - use StoredDict class that keeps tracks of its modifications
2020-02-04 13:35:58 +01:00
ThomasV
aa51df0a1a Use attr.s for Feeupdates and Outpoints
Storage upgrade to version 23
2020-02-01 16:45:19 +01:00
SomberNight
0973b86925 lnworker: rework "is_dangerous"
"Should channel be closed due to expiring htlcs?"
2019-08-20 09:03:12 +02:00
SomberNight
ce54b5411e lnhtlc: htlcs_by_direction now returns dict keyed by htlc_id 2019-08-20 09:03:12 +02:00
SomberNight
a27b03be6d lnhtlc: local update raw messages must not be deleted before acked
In recv_rev() previously all unacked_local_updates were deleted
as it was assumed that all of them have been acked at that point by
the revoke_and_ack itself. However this is not necessarily the case:
see new test case.

renamed log['unacked_local_updates'] to log['unacked_local_updates2']
to avoid breaking existing wallet files
2019-08-20 09:03:12 +02:00
SomberNight
7f1b456b93 lnhtlc.discard_unsigned_remote_updates: fix edge case 2019-08-20 09:03:12 +02:00
SomberNight
107f271e58 move all ctn book-keeping to lnhtlc (from lnchannel) 2019-08-20 09:03:12 +02:00
SomberNight
014b921393 lnpeer: reestablish_channel - replay un-acked local updates
Replay un-acked local updates (including commitment_signed) byte-for-byte.
If we have sent them a commitment signature that they "lost" (due to disconnect),
we need to make sure we replay the same local updates, as otherwise they could
end up with two (or more) signed valid commitment transactions at the same ctn.
Multiple valid ctxs at the same ctn is a major headache for pre-signing spending txns,
e.g. for watchtowers, hence we must ensure these ctxs coincide.
2019-08-20 09:03:12 +02:00
SomberNight
e81ae1921b lnpeer: reestablish_channel - discard unsigned remote updates 2019-08-20 09:03:12 +02:00
SomberNight
c046f2cc1c lnhtlc: move 'next_htlc_id' from ChannelConfig to lnhtlc log 2019-08-20 09:03:12 +02:00
SomberNight
a3fd6b3ce8 lnhtlc: rename ctx_pending to revack_pending, and persist it 2019-08-20 09:03:12 +02:00
SomberNight
087994e39a lnchannel: move fee update logic to lnhtlc (and hopefully fix it) 2019-08-20 09:03:12 +02:00
SomberNight
7431aac5cd lnhtlc: (fix) was locking in too many updates during commit/revoke 2019-08-20 09:03:12 +02:00
ThomasV
9abbd077a5 lnhtlc: use boolean instead of int in ctn_latest 2019-08-20 09:03:11 +02:00
SomberNight
69bffac86a lnhtlc: fix adding htlc between sending commitment_signed and receiving revoke_and_ack 2019-08-20 09:03:11 +02:00
SomberNight
fda6fb6521 lnhtlc: handle fails asymmetrically 2019-08-20 09:03:11 +02:00
SomberNight
8632f027da lnhtlc: small clean-up / docstrings 2019-08-20 09:03:11 +02:00
SomberNight
268f05c60c lnhtlc: add type hints 2019-08-20 09:03:11 +02:00
ThomasV
82491ff083 do not duplicate ctn in channel log and config 2019-08-20 09:03:11 +02:00
ThomasV
8d28188d24 lnhtlc: remove unused field in log 2019-08-20 09:03:11 +02:00
ThomasV
b215d6c4b7 lnhtlc: rename ctnheights -> ctn 2019-08-20 09:03:11 +02:00
SomberNight
a565c500f6 lnhtlc: revert 0c4e7b856f8c96c4f0a33bf3e0d1c8fd8184bd36 2019-08-20 09:03:11 +02:00
ThomasV
11c0c0d5a1 lnhtlc: fix received_in_ctn (LOCAL->REMOTE) 2019-08-20 09:03:11 +02:00
Janus
f618bb4a67 lnhtlc: handle settles like adds (asymmetrical across ctns) 2019-08-20 09:03:11 +02:00
Janus
e56e849505 lnchan refactor
- replace undoing logic with new HTLCManager class
- separate SENT/RECEIVED
- move UpdateAddHtlc to lnutil
2019-08-20 09:03:11 +02:00
Janus
1763d02b05 rename lnhtlc->lnchan, HTLCStateMachine->Channel 2019-08-20 09:03:10 +02:00