Commit Graph

125 Commits

Author SHA1 Message Date
SomberNight 3a7f5373ac trampoline: improve payment success
- better error handling: previously we stopped all attempts on any of
  TRAMPOLINE_EXPIRY_TOO_SOON, UNKNOWN_NEXT_PEER, TEMPORARY_NODE_FAILURE.
  Instead we should retry (but see code comments).
- previously payments failed if ALL of the following criteria applied:
  - sender is paying via trampoline, but not via the ACINQ node (which is
    special cased)
  - receiver only has private channels and has put r_tags into invoice, along
    with setting the trampoline feature bit in the invoice, however the receiver
    is not connected to any trampoline forwarders directly
  The sender would then assume that the private routing hints in the invoice
  correspond to trampoline forwarders.
- also, previously if both the sender and the recipient used trampoline and
  they shared a trampoline forwarder (that they were both connected to), the
  private channels the recipient had (with nodes other than the shared TF)
  would never be attempted.
2021-07-02 18:44:39 +02:00
bitromortac 591a36fb3b lnworker: async gen create_routes_for_payments 2021-05-10 09:32:41 +02:00
bitromortac 95e095fa3f lnpeer test: payment now succeeds in two payments 2021-04-06 20:13:42 +02:00
bitromortac 4df67a4f78 lnrouter+lnworker: use liquidity hints
Adds liquidity hints for the sending capabilities of routing channels in the
graph. The channel blacklist is incorporated into liquidity hints.
Liquidity hints are updated when a payment fails with a temporary
channel failure or when it succeeds. Liquidity hints are used to give a
penalty in the _edge_cost heuristics used by the pathfinding algorithm.
The base penalty in (_edge_cost) is removed because it is now part of the
liquidity penalty. We don't return early from get_distances, as we want
to explore all channels.
2021-04-06 20:13:42 +02:00
SomberNight 50b165fc3b tests: rename TestSuccess(Exception) to SuccessfulTest
The test framework did not like the "Test" prefix.

```
electrum/tests/test_lnpeer.py:305

  /home/travis/build/spesmilo/electrum/electrum/tests/test_lnpeer.py:305: PytestCollectionWarning: cannot collect test class 'TestSuccess' because it has a __init__ constructor (from: electrum/tests/test_lnpeer.py)
```
2021-03-23 17:17:43 +01:00
ThomasV f7d2a33d45 set initial trampoline fee level to 1 unless we are testing 2021-03-22 17:04:01 +01:00
SomberNight c912036180 lnpeer: ignore unknown 'odd' type messages
from BOLT-01:
A receiving node:
  - upon receiving a message of odd, unknown type:
    - MUST ignore the received message.

https://github.com/lightningnetwork/lightning-rfc/blob/b201efe0546120c14bf154ce5f4e18da7243fe7a/01-messaging.md#lightning-message-format
2021-03-19 20:51:38 +01:00
ThomasV bf5aa1d690 Merge pull request #7113 from bitromortac/2103-temp-chan-fail
forwarding: temp chan fail on insufficient funds
2021-03-18 10:47:03 +01:00
bitromortac f1b5069c78 forwarding: temp chan fail on insufficient funds
When forwarding an HTLC and the outgoing channel doesn't have
enough funds or other transient issues, we are failing the
HTLC with a temporary channel failure.

From BOLT #04:
* if during forwarding to its receiving peer, an otherwise unspecified,
transient error occurs in the outgoing channel (e.g. channel capacity
reached, too many in-flight HTLCs, etc.):
-> return a temporary_channel_failure error.
2021-03-18 08:27:48 +01:00
ThomasV 8a051dcd76 lnworker: use booleans for enable_htlc_settle, enable_htlc_forwarding 2021-03-18 07:48:30 +01:00
bitromortac 8828998093 mpp_split: use single nodes for mpp payments over trampoline 2021-03-17 08:22:19 +01:00
SomberNight 2487a3fa90 tests: add test for prev 2021-03-11 20:35:21 +01: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
ThomasV 533d796a41 add TODO, rename check_received_mpp_htlc 2021-03-11 16:53:55 +01:00
ThomasV dc55cf4b2d test_multipart_payment_with_timeout: give extra time for second HTLC to timeout before next test 2021-03-11 11:01:35 +01:00
ThomasV 50ab8be7a2 lnpeer: try to fix tests 2021-03-11 10:39:39 +01:00
SomberNight a7c948bac1 tests: fix tearDown() issue in test_lnrouter.py
similar to 05fd424548

from logs when running tests:

--- Logging error ---
Traceback (most recent call last):
  File "...\Python39\lib\logging\__init__.py", line 1082, in emit
    stream.write(msg + self.terminator)
ValueError: I/O operation on closed file.
Call stack:
  File "...\Python39\lib\threading.py", line 912, in _bootstrap
    self._bootstrap_inner()
  File "...\Python39\lib\threading.py", line 954, in _bootstrap_inner
    self.run()
  File "...\Python39\lib\threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "...\electrum\electrum\sql_db.py", line 71, in run_sql
    self.logger.info("SQL thread terminated")
Message: 'SQL thread terminated'
Arguments: ()
2021-03-10 21:23:41 +01:00
ThomasV 4250f3b8a1 test_lnpeer: use 2s MPP_TIMEOUT, and split test_multipart_payment_with_timeout 2021-03-10 21:06:50 +01:00
ThomasV 549b9a95df test_lnpeer: add test for mpp_timeout 2021-03-10 17:09:07 +01:00
ThomasV ef661050c8 lnworker: set request status after LN payment 2021-03-09 09:35:43 +01:00
SomberNight a125cd5392 tests: test payreq status after getting paid via LN
The test failures corresponding to single-part (non-MPP) payments expose a bug.

see https://github.com/spesmilo/electrum/blob/196b4c00a35b288f28885c0ceb8afdd5ffbd9a0f/electrum/lnpeer.py#L1538-L1539
`lnworker.add_received_htlc` is not called for single-part payments...
2021-03-08 22:18:06 +01:00
SomberNight f662859e5c test_lnpeer: (trivial) prepare_invoice to return both LnAddr and str 2021-03-08 21:46:56 +01:00
SomberNight 4069b455d0 lnaddr: add get_features method 2021-03-08 21:36:27 +01:00
ThomasV 6ddd02506e test_lnpeer: add missing parameter in pay_to_route 2021-03-06 10:59:29 +01:00
ThomasV 83993768e5 trampoline: do not add node in trampoline hints if it already is
the last trampoline of the route
2021-03-06 10:46:58 +01:00
ThomasV 59547d0513 test_lnpeer: variables must be declared in MockLNWallet.__init__ 2021-03-05 17:04:26 +01:00
ThomasV 1f60d5d8ee test_lnpeer: add test for trampoline 2021-03-05 13:00:24 +01:00
ThomasV 3fa1aed8cd add unit test for basic mpp 2021-03-03 12:52:52 +01:00
SomberNight 9310e9023e test_lnpeer: add test: multihop payment that routes around failure
This would have caught the overpayment bug fixed in
https://github.com/spesmilo/electrum/commit/693583edc5010ece804e312626c7c40157613ff1
2021-03-02 18:35:07 +01:00
SomberNight 750d8cfab5 lnworker: run create_route_for_payment end-to-end, incl private edges
We pass the private edges to lnrouter, and let it find routes end-to-end.
Previously the edge_cost heuristics didn't apply to the private edges
and we were just randomly picking one of the route hints and use that.
So e.g. cheaper private edges were not preferred, but they are now.

PathEdge now stores both start_node and end_node; not just end_node.
2021-03-02 18:00:31 +01:00
ThomasV 259dacd56f Trampoline MPP aggregation:
- trampoline node is the final recipient of MPP
 - each trampoline receives a bucket of HTLCs
 - if a HTLC from a bucket fails, wait for the entire bucket to fail
 - move trampoline route and onion code into trampoline module
2021-03-02 14:28:15 +01:00
ThomasV 693583edc5 lnworker: amount passed in HtlcLog must be without fees 2021-03-02 10:23:30 +01:00
SomberNight 2b693d3498 tests: fix test_lnpeer.test_payment_race
broke in https://github.com/spesmilo/electrum/commit/b6b13217b4929c5701e18a1310b20caf01fb61e5
see changes to lnworker.htlc_fulfilled
2021-02-28 13:58:31 +01:00
ThomasV 5175a97671 test_payment_race: increase delay 2021-02-28 09:43:46 +01:00
ThomasV 38652cffb0 fix test_lnpeer (follow-up prev commit) 2021-02-27 20:51:19 +01:00
ThomasV b6b13217b4 lnworker: keep invoice status INFLIGHT as long as HTLCs are inflight 2021-02-27 20:26:58 +01:00
ThomasV 7f61f22857 MPP receive: allow payer to retry after mpp timeout 2021-02-27 11:48:14 +01:00
SomberNight 691ebaf4f8 lnworker/lnpeer: add some type hints, force some kwargs 2021-02-24 20:03:12 +01:00
ThomasV 6922b416d6 follow-up prev commit 2021-02-22 15:38:19 +01:00
bitromortac e9fe0ed22b lnworker: use suggest_splits for multiple routes 2021-02-22 11:25:01 +01:00
bitromortac 9f84fa9580 lnonion: add total_msat to onion payment data 2021-02-22 11:25:00 +01:00
ThomasV 42c10c2fec Separate pay_to_node logic from pay_invoice:
- pay_to_node will be needed to forward trampoline onions.
 - pay_to_node either is successful or raises
 - pay_invoice handles invoice status
2021-02-07 13:03:18 +01:00
ThomasV 0c93394513 rename lnworker._pay to pay_invoice, call it directly from GUIs 2021-02-07 12:09:37 +01:00
ThomasV 34734bd229 cleanup, follow-up f28a2aae73 2021-02-05 17:09:47 +01:00
ThomasV f28a2aae73 Reorganize code so that we can send Multi Part Payments:
- LNWorker is notified about htlc events and creates payment events.
 - LNWorker._pay is a while loop that calls create_routes_from_invoice.
 - create_route_from_invoices should decide whether to split the payment,
   using graph knowledge and feedback from previous attempts (not in this commit)
 - data structures for payment logs are simplified into a single type, HtlcLog
2021-02-05 14:28:58 +01:00
ThomasV 1102ea50e8 fix tests (follow-up previous commit) 2021-02-05 11:57:19 +01:00
ThomasV ef5a265449 basic_mpp: receive multi-part payments 2021-02-04 16:31:17 +01:00
ThomasV e477a43385 PaymentInfo: use msat precision 2021-02-01 15:03:56 +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
ThomasV ad91257729 pass blacklist to lnrouter.find_route, so that lnrouter is stateless (see #6778) 2021-01-11 15:19:50 +01:00