Commit Graph

509 Commits

Author SHA1 Message Date
SomberNight
eb6b4580e8 fix tests: adapt to breaking change of ipaddress.ip_address in py3.9.5
fixes https://github.com/spesmilo/electrum/issues/7307

We can simply remove that test as we don't actually care whether the
leading zeroes are allowed.

see 60ce8f0be6
see https://bugs.python.org/issue36384
2021-06-05 08:01:38 +02:00
SomberNight
af44c846cc tests: add test for payto command 2021-04-22 17:13:56 +02:00
ghost43
0f83270053 Merge pull request #7152 from bitromortac/2103-liquidity-hints
Liquidity hints for pathfinding
2021-04-22 14:45:41 +00:00
SomberNight
9a38c4d2a1 logging: don't lose log messages during early startup
Previously, during early-startup (until configure_logging(config) is
called in run_electrum),
- the stderr log handler lost all log messages below warning level, and
- the file log handler lost all log messages regardless of log level

We now instead start buffering log messages in memory as soon as
electrum.logging is imported. The buffer is dumped into the
stderr and file log handlers when they are fully set up, and then
the buffer is discarded (and the temporary log handler is removed).

Note that messages are not logged until configure_logging() is called.
Previously WARNING/ERROR messages would get logged immediately to stderr,
but not anymore. This was changed so that the order of the log messages
can be kept intact. (if we log WARNINGs immediately, but need to delay
INFOs until the config is available, messages would either be out of order
or alternatively there would be duplicates)

Relatedly, we now follow the recommendation of the python docs re
logging for libraries [0]: we try to only configure logging if running via
run_electrum (the main script) and not when e.g. a 3rd party script
imports electrum.

[0]: https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library
2021-04-14 19:14:26 +02:00
SomberNight
67c6f0e1bd wallet: make sure we don't create zero input txs
fixes #7207
2021-04-14 19:08:04 +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
bitromortac
209449bec4 lnrouter tests: add another channel to graph
We need another channel to have routes with three hops. This can be
later used to test payment successes.
2021-04-02 10:25:25 +02:00
SomberNight
8ea2b4432a tests: add test for keystore.get_lightning_xprv 2021-03-30 19:05:42 +02:00
ThomasV
8b95b2127d regtest backups: test both cases (onchain and imported)
lnpeer: call close_and_cleanup() after we force close,
or the above test will fail.
2021-03-29 19:08:31 +02:00
ThomasV
f06433e435 fix privkey in request_force_close_from_backup 2021-03-29 17:35:04 +02:00
ThomasV
a4210ce5e7 Qt: remove the 'local watchtower' option from GUI.
It is not realistic to expect Electrum to be used as a watchtower
in GUI mode, and possibly counter-productive (may set wrong
expectations).

A proper watchtower should be configured as a daemon. The
documentation will be updated to reflect this change.
2021-03-28 10:44:03 +02:00
SomberNight
638d4f7472 commands: fix signtransaction cmd when used with "privkey" arg
A naive "solver" is implemented locally for p2pkh-like inputs.
Other more complex scripts cannot be signed atm without a wallet.

closes https://github.com/spesmilo/electrum/issues/7117
2021-03-24 20:52:35 +01: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
4f13c451c7 tests: rework lntransport test a bit
send multiple messages, and not only short ones
2021-03-21 22:11:16 +01:00
Benoit Verret
f731c38293 Minor style changes 2021-03-21 00:36:23 -04: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.

b201efe054/01-messaging.md (lightning-message-format)
2021-03-19 20:51:38 +01:00
SomberNight
d8352f1a0a lnworker: nicer logs/error msgs for payment failure
try to decode onion error and log it in human-readable form
2021-03-19 19:13:50 +01:00
ThomasV
64a931f21e Deterministic NodeID:
- use_recoverable_channel is a user setting, available
   only in standard wallets with a 'segwit' seed_type
 - if enabled, 'lightning_xprv' is derived from seed
 - otherwise, wallets use the existing 'lightning_privkey2'

Recoverable channels:
 - channel recovery data is added funding tx using an OP_RETURN
 - recovery data = 4 magic bytes + node id[0:16]
 - recovery data is chacha20 encrypted using funding_address as nonce.
   (this will allow to fund multiple channels in the same tx)

GUI:
  - whether channels are recoverable is shown in wallet info dialog.
  - if the wallet can have recoverable channels but has an old node_id,
    users are told to close their channels and restore from seed
    to have that feature.
2021-03-19 10:17:02 +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
ThomasV
e5686c8dc5 test_backup: sleep is not needed anymore 2021-03-18 07:26:33 +01:00
ThomasV
8870ed7cc5 test_backup: check onchain balance 2021-03-17 19:20:33 +01:00
SomberNight
4315fa4371 BIP-0350: use bech32m for witness version 1+ addresses
We have supported sending to any witness version since Electrum 3.0, using
addresses as specified in BIP-0173 (bech32 encoding).
BIP-0350 makes a breaking change in address encoding, and recommends using
(and using only) a new encoding (bech32m) for sending to witness version 1
and later. The address encoding for currently in use witness v0 addresses
remains the same, as in BIP-0173; following the BIP-0350 spec.

closes https://github.com/spesmilo/electrum/issues/6949

related:
cd3885c0fb/bip-0350.mediawiki
https://github.com/bitcoin/bitcoin/pull/20861
2021-03-17 18:11:55 +01:00
SomberNight
468636eae0 tests: add missing test vectors from BIP-0173 (bech32) 2021-03-17 17:13:10 +01:00
ThomasV
8d8f078544 Merge pull request #7107 from bitromortac/2103-trampoline-mpp-single
mpp_split: use single nodes for mpp payments over trampoline
2021-03-17 13:47:13 +01:00
bitromortac
8828998093 mpp_split: use single nodes for mpp payments over trampoline 2021-03-17 08:22:19 +01:00
SomberNight
fa999de305 tests: re bolt11 tests, also check invoice str in test_roundtrip 2021-03-16 20:39:51 +01:00
SomberNight
cedc71a8e3 ln gossip: make sure all signatures are verified
we have not been verifying signatures of ChannelUpdate messages...
(regression from 2d0ef78a11)
2021-03-15 20:44:20 +01:00
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 196b4c00a3/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