Commit Graph

478 Commits

Author SHA1 Message Date
ThomasV f16358ec3c add request_force_close command to CLI
add regtest for channel backup
2021-03-12 16:10:02 +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
bitromortac 10c799faab mpp_split: add penalty for exhaustion of channels
A penalty is added for split configurations which saturate a channel.
Saturation of channels is discouraged as we don't know the fees
beforehand. The penalty is accomplished via an exponential function that
kicks in when the subamount reaches about the total funds available
(this amount is controlled by the parameter EXHAUST_DECAY_FRACTION).
2021-03-11 16:19:15 +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
SomberNight 05fd424548 tests: maybe fix tearDown() issue in test_storage_upgrade.py
from travis logs:

--- Logging error ---

Traceback (most recent call last):
  File "/opt/python/3.7.6/lib/python3.7/logging/__init__.py", line 1028, in emit
    stream.write(msg + self.terminator)
ValueError: I/O operation on closed file.

Call stack:
  File "/opt/python/3.7.6/lib/python3.7/threading.py", line 890, in _bootstrap
    self._bootstrap_inner()
  File "/opt/python/3.7.6/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/home/travis/build/spesmilo/electrum/electrum/plugin.py", line 213, in run
    self.run_jobs()
  File "/home/travis/build/spesmilo/electrum/electrum/util.py", line 359, in on_stop
    self.logger.info("stopped")
Message: 'stopped'
2021-03-10 20:16:25 +01:00
SomberNight 9740744d70 crypto: add chacha20_decrypt; unused for now 2021-03-10 17:13:42 +01:00
ThomasV 549b9a95df test_lnpeer: add test for mpp_timeout 2021-03-10 17:09:07 +01:00
SomberNight 3c019c2f9c daemon/wallet/network: make stop() methods async 2021-03-09 17:52:36 +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 f397b315ac remove trampoline and forwarding regtests, as they are covered by unittests 2021-03-05 13:18:44 +01:00
ThomasV 1f60d5d8ee test_lnpeer: add test for trampoline 2021-03-05 13:00:24 +01:00
SomberNight e25602ab3b wallet: don't put partial tx as UTXO into psbt
if there is a chain of unsigned txs, we cannot populate NON_WITNESS_UTXO

closes #7080
closes #7009
closes #6482
2021-03-04 13:20:49 +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 058d9ab6bb wallet.bump_fee: add new strategy: decrease payment amounts
- Rename bump_fee "methods" to "strategies".
- Refactor strategies so that bump_fee can use any subset of them in any permutation.
- Adds a new strategy which decreases the payment outputs (instead of change).
2021-02-25 15:32:07 +01:00
bitromortac 5081a83245 mpp_split: undo side effect in tearDown 2021-02-25 08:37:07 +01:00
SomberNight 691ebaf4f8 lnworker/lnpeer: add some type hints, force some kwargs 2021-02-24 20:03:12 +01:00
SomberNight 52eb9dcad9 tests: fix thinko in ElectrumTestCase base class
can't see why it was cross-calling the setUpClass from the
individual test setUp
2021-02-24 13:32:29 +01:00
SomberNight a9d0e3fca9 tests: try to eliminate random failures from mpp_split tests
closes: #7062
2021-02-24 12:54:43 +01:00
bitromortac 9b0b78eca1 mpp_split: fix tests for python versions < 3.8 2021-02-23 08:02:02 +01:00
SomberNight 4aab843f17 lnutil.LnFeatures: impl and use "supports" method for feature-bit-tests
Note that for a required feature, BOLT-09 allows setting either:
- only the REQ bit
- both the REQ bit and the OPT bit

Hence, when checking if a feature is supported by e.g. an invoice, both
bits should be checked.

Note that in lnpeer.py, in self.features specifically, REQ implies OPT,
as it is set by ln_compare_features.
2021-02-22 19:53:01 +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
bitromortac 613bab145d mpp_split: implement splitting logic 2021-02-22 11:25:00 +01:00
SomberNight b856336f8c bip32: add new test vectors from BIP
also yet-to-be-merged test from https://github.com/bitcoin/bips/pull/1030
2021-02-18 02:57:02 +01:00
ThomasV cf818fe08c Trampoline routing:
- add support for trampoline forwarding
 - add regtest with trampoline payment
2021-02-17 17:28:56 +01:00
ThomasV ded449233e Trampoline routing.
- trampoline is enabled by default in config, to prevent download of `gossip_db`.
   (if disabled, `gossip_db` will be downloaded, regardless of the existence of channels)
 - if trampoline is enabled:
    - the wallet can only open channels with trampoline nodes
    - already-existing channels with non-trampoline nodes are frozen for sending.
 - there are two types of trampoline payments: legacy and end-to-end (e2e).
 - we decide to perform legacy or e2e based on the invoice:
    - we use trampoline_routing_opt in features to detect Eclair and Phoenix invoices
    - we use trampoline_routing_hints to detect Electrum invoices
 - when trying a legacy payment, we add a second trampoline to the path to preserve privacy.
   (we fall back to a single trampoline if the payment fails for all trampolines)
 - the trampoline list is hardcoded, it will remain so until `trampoline_routing_opt` feature flag is in INIT.
 - there are currently only two nodes in the hardcoded list, it would be nice to have more.
 - similar to Phoenix, we find the fee/cltv by trial-and-error.
    - if there is a second trampoline in the path, we use the same fee for both.
    - the final spec should add fee info in error messages, so we will be able to fine-tune fees
2021-02-17 17:28:13 +01:00
SomberNight 01ed5e7345 wallet.bump_fee: (fix) method2 was bumping too much if output was rm-ed
regression from bafe8a2fff
2021-02-15 10:20:34 +01:00
SomberNight ca86e35724 wallet.bump_fee: (fix) make sure all inputs have same sequence number
Previously, if bump_fee decided to add new inputs to the tx, they would
have a different sequence number than the existing inputs. This was
unintentional.
2021-02-12 04:59:34 +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