1
0
Commit Graph

627 Commits

Author SHA1 Message Date
SomberNight
2378f92a6a tests: add more "sweep" tests for different script types 2023-02-14 12:19:18 +00:00
SomberNight
df2bd61de6 bip32: change hardened char "'"->"h" when encoding derivation paths
We accept either when decoding - this only changes what we use when encoding.
Single quotes are annoying to use in a shell, as they often need to be escaped.
2023-02-14 12:19:10 +00:00
ThomasV
8fa549c418 Merge pull request #8135 from spesmilo/scid_alias
Add support for option_scid_alias
2023-01-13 18:44:13 +01:00
ThomasV
7d52021d6b Merge pull request #8139 from SomberNight/202301_locale_decimal_point
locale amounts: consistently use "." as dec point, and " " as thou sep
2023-01-13 16:00:47 +01:00
ThomasV
b9393b0603 Support scid alias:
- save remote alias for use in invoices
 - derive local alias from wallet xpub
 - send channel_type without the option_scid_alias bit
   (apparently LND does not like it)
2023-01-13 15:47:30 +01:00
ThomasV
c109d5e722 lnwire: update csv files with recent BOLTs
Note: there are no more optional fields in msgdata, per f068dd0d8d
2023-01-13 12:50:48 +01:00
ThomasV
d95f3e5622 Use different trampoline bits than Eclair. Fixes #8141 2023-01-13 12:48:13 +01:00
SomberNight
762a9a9e7a follow-up prev: fix tests 2023-01-13 10:55:52 +00:00
SomberNight
7dcaa4b204 tests: add tests for wallet/invoices functionality
only for payment requests ("incoming invoices") for now
2023-01-12 18:19:08 +00:00
SomberNight
2a9909c252 locale amounts: consistently use "." as dec point, and " " as thou sep
Always use "." as decimal point, and " " as thousands separator.

Previously,
- for decimal point, we were using
  - "." in some places (e.g. AmountEdit, most fiat amounts), and
  - `locale.localeconv()['decimal_point']` in others.
- for thousands separator, we were using
  - "," in some places (most fiat amounts), and
  - " " in others (format_satoshis)

I think it is better to be consistent even if whatever we pick differs from the locale.
Using whitespace for thousands separator (vs comma) is probably less confusing for people
whose locale would user "." for ts and "," for dp (as in e.g. German).

The alternative option would be to always use the locale. Even if we decide to do that later,
this refactoring should be useful.

closes https://github.com/spesmilo/electrum/issues/2629
2023-01-10 14:45:35 +00:00
ThomasV
a383f56909 Simplify RBF user experience:
- replace complex strategies with a simpler choice,
   between preserving or decreasing the payment.
 - Always expose that choice to the user.
 - Show the resulting fees to the user before they click OK
2022-12-13 11:26:44 +01:00
ThomasV
49984b2ed4 fix tests (follow-up e1dc7d1e6f) 2022-12-11 07:24:28 +01:00
SomberNight
84faf7f99a tests: fix TestLNTransport probabilistic failure
lucky CI run: https://github.com/spesmilo/electrum/runs/9273471816
2022-11-03 15:45:15 +00:00
SomberNight
21c18bbbe7 util.parse_URI: honour docstring and only raise InvalidBitcoinURI
follow-up ac1d53f067
2022-11-03 12:47:21 +00:00
SomberNight
ac1d53f067 util.parse_URI: allow bip21 with lightning key without fallback addr
We would reject bip21 URIs that contained both an "address=" and a "lightning=" key with a bolt11 invoice,
where the bolt11 invoice did not contain a fallback address.
2022-10-31 19:03:12 +00:00
SomberNight
2863fb4ab4 tests: add "as_testnet" fn decorator, to run single tests in testnet
As opposed to using TestCaseForTestnet class, this allows having a single class
of many related unit tests, some using testnet and some using mainnet constants.
2022-10-31 18:44:38 +00:00
SomberNight
d3227d7489 transaction: for witness v0 txins, put both UTXO and WIT_UTXO in psbt
Until now we have been only putting PSBT_IN_NON_WITNESS_UTXO (="UTXO", full tx)
in segwit witness v0 txins, as signers wanted the full tx anyway due to
bip-143 sighash issue [0], and as WITNESS_UTXO can be calculated from UTXO.

My reading of bip-174 is that either behaviour is correct, but
achow101 said bip-174 expects PSBT_IN_WITNESS_UTXO for segwit inputs.
Regardless, including both fields does not increase the tx size too much
(UTXO can be very large ofc but we were already including that, WIT_UTXO is small).
This also might increase compatibility with some other software - I've found
some issues where this might have been the culprit [1][2][3].

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

related:
[0] https://github.com/spesmilo/electrum/pull/6198
[1] https://github.com/cryptoadvance/specter-desktop/issues/868
[2] https://github.com/cryptoadvance/specter-desktop/issues/1046
[3] https://github.com/cryptoadvance/specter-desktop/issues/1544
2022-10-31 17:14:21 +00:00
SomberNight
01b5e3f8e0 flake8: enable more mandatory tests 2022-10-31 16:13:22 +00:00
SomberNight
30ac889656 transaction: never put ypub/zpub in psbts, only plain xpubs
BIP-0174 specifies using standard bip32-compliant serialization for extended keys.
> The 78 byte serialized extended public key as defined by BIP 32.

closes https://github.com/spesmilo/electrum/issues/8036
2022-10-27 16:03:05 +00:00
SomberNight
45a939c146 tests: add test to check if we include xpubs in psbts
related: https://github.com/spesmilo/electrum/issues/8036
2022-10-27 15:55:01 +00:00
ThomasV
6e429ebf9a test_lnpeer: instead of sleeping for 0.2s, wait until peers are initialized
this should fix https://cirrus-ci.com/task/6585628493086720
2022-09-23 12:42:15 +02:00
ThomasV
fe6a83d6c1 fix test_fail_pending_htlcs_on_shutdown: poll number of htlcs 2022-09-22 18:26:02 +02:00
ThomasV
79bcedd064 test_lnpeer: reset electrum.trampoline._TRAMPOLINE_NODES_UNITTESTS in tearDown 2022-09-20 19:17:32 +02:00
ThomasV
20bcb15480 Factorize code in create_routes_for_payment.
Calling suggest_splits with exclude_single_part_payments=False
2022-09-20 13:55:22 +02:00
ThomasV
b8cb561d1a test_mpp_split: add tests for exclude_single_part_payments=False 2022-09-20 13:49:16 +02:00
ThomasV
9251f482b5 test_lnpeer: add unit test for direct payment to trampoline node 2022-09-20 11:28:51 +02:00
ThomasV
2af59e32b2 lnworker: define use_trampoline() for code clarity 2022-09-19 17:43:13 +02:00
ThomasV
68bf714ae6 Trampoline: Remember failed routes (fixes #7967).
Upon receiving UNKNOWN_NEXT_PEER, TEMPORARY_NODE_FAILURE
or TEMPORARY_CHANNEL_FAILURE, remember the trampoline route
that was used, and try other routes before raising the
trampoline fee.

Before this commit, we used to raise the trampoline fee
upon receiving any error message, in order to ensure
termination of the payment loop.

Note that we will still retry failing routes after we have
raised the trampoline fee. This choice is questionable, it
is unclear if doing so significantly increases the probability
of success.

Tests: add a test for trampoline handling of UNKNOWN_NEXT_PEER
2022-09-19 16:42:46 +02:00
ThomasV
26245c1ac9 unit tests: split test_payment_trampoline into two tests 2022-09-03 11:16:37 +02:00
ThomasV
70da10d662 fix watchtower regtest flakiness caused by CTN variability. fixes #7961 2022-09-01 09:56:46 +02:00
SomberNight
03b514863e exchange_rate: more robust spot price against temporary network issues
We poll the fx rate provider every 2.5 minutes (unchanged).
Previously if there was any error during a tick, there was no fx rate
available in the client until the next tick.
Now, instead, we keep the last rates received with a 10 minute expiry.

One potential drawback is that previously there was instant feedback
to the user when e.g. changing proxy settings, and this is no longer
the case. E.g. consider a provider that bans Tor exit nodes. If a user
enables using a Tor proxy in the network settings, the fxrate used to
disappear immediately - but now the cached rate would still be
available.
2022-08-26 11:48:51 +00:00
SomberNight
05863a611f tests: test_lnpeer.py: clean-up temp dirs created in /tmp, in tearDown 2022-08-10 18:16:17 +02:00
SomberNight
233d2373df util: implement is_subpath 2022-08-09 18:48:21 +02:00
SomberNight
73ba00d7dd wallet.restore_wallet_from_text: support creating wallet in-memory 2022-08-08 16:34:04 +02:00
SomberNight
2c73e7f854 wallet: (regression) fix get_spendable_coins when "domain" arg is given
`get_spendable_coins` was ignoring the "domain" param, and returning utxos for the whole wallet
2022-07-11 16:18:38 +02:00
bitromortac
fe2fbbd9b1 add lnurl-pay and lightning address support
* bundles all payment identifiers into handle_payment_identifier
* adds lnurl decoding
* adds lightning address decoding
2022-06-29 16:18:15 +02:00
ThomasV
dbf055de9a EventListener class to handle callbacks
and QtEventListener for Qt
2022-06-22 02:07:46 +02:00
ThomasV
9fe93524b7 Index lightning requests with rhash instead of onchain address.
get_unused_addresses() has been broken since #7730, because
addresses are considered as permanently used if they are in
the list of keys of receive_requests. This is true even if
an address is used as fallback for a lightning payment. This
means that the number of lightning payments we can receive
is constrained by the gap limit.

If a payment succeeds off-chain, we want to be able to reuse
its fallback address in other requests (this does not reduce
privacy, because invoices already share the same public key).

This implies that we should not use the onchain address as key
for lightning-enabled requests in wallet.receive_requests. If
we did, paid invoices would be overwritten when the address is
reused. That is the reason for the wallet_db upgrade.

Related: a3faf85e3c
2022-06-15 18:44:52 +02:00
ThomasV
a3faf85e3c wallet:
- add new index: requests_rhash_to_key (fixes #7845)
 - when creating a request, do not save its description in labels.
   Instead, return it as default value in wallet.get_label_by_rhash
lnworker:
  - rename 'payments' to 'payment_info'
  - add note to delete_payment_info
commands: rename 'rmrequest' to 'delete_request'
2022-06-14 13:39:18 +02:00
ThomasV
121d8732f1 Persist LNWatcher transactions in wallet file:
- separate AddressSynchronizer from Wallet and LNWatcher
 - the AddressSynchronizer class is referred to as 'adb' (address database)
 - Use callbacks to replace overloaded methods
2022-06-10 13:07:53 +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
Jeremy Rand
1aa444e0f8 Fix "== None" linter fails
Credit to Zoltan Konder for pointing me to this issue.
2022-05-24 02:39:11 +00:00
ThomasV
53151244e2 LNWorker: Add suggest_rebalance methods for sending and receiving.
These methods return a list of channels that can be rebalanced,
in order to receive or send a given amount.

Also add 'channels' parameter to submarine swaps.
Previously, swaps were not considering which channel to use.

When we do not have liquidity to pay an invoice:
 - add 'rebalance' option in order to pay an invoice
 - use the suggested channel in the 'swap' option

When we do not have the liquidity to receive an invoice:
 - add 'Rebalance' and 'Swap' buttons to the receive tab
2022-05-21 20:25:44 +02:00
SomberNight
dd5cb2a5c1 lnworker: rework num_sats_can_receive and routing_hints_for_invoice
follow-up https://github.com/spesmilo/electrum/pull/7818

- note it matters whether a sender pays us end-to-end-trampoline or just via legacy
  - consider: Alice has 0.1 BTC recv cap in chan1 and 1 BTC recv cap in chan2, both with border-node T1
    - if sender is paying e2e trampoline, it can realistically pay even ~1.1 BTC, as T1 can resplit the HTLCs
    - if sender is paying legacy, it will have a hard time trying to pay more than 1 BTC, in practice
      - although note if T1 has implemented non-strict-forwarding (see BOLT-04), achieving 1 BTC is easy,
        as T1 can redirect HTLCs (but cannot split them, in this case)
  - to make num_sats_can_receive realistic, it assumes the legacy case
- To calc num_sats_can_receive, we sort our channels in decreasing order of receive-capacities, iterate over them
  and calculate a running sum - we stop adding channels when the next chan's recv cap is small compared to
  the running total.
- When putting routing hints in an invoice, we do the same, with the added condition that we keep adding channels
  if their recv cap is larger than the invoice amount.
  - consider: Alice has 0.1 BTC recv cap in chan1 with Bob, and 1 BTC recv cap in chan2 with Carol
    - if Alice wants to recv 100 sats, it is useful to add hints for both channels into the invoice, for redundancy
    - if Alice wants to recv 0.9 BTC, it is questionable whether adding the smaller chan is useful - the code here won't add it
2022-05-19 18:28:04 +02:00
ThomasV
f90a08bbe2 Filter nodes for receiving:
- increase MPP_RECEIVE_CUTOFF from 5 to 20 percent
 - filter channels by node_id, not channel_id
 - make num_sats_can_receive consistent with routing hints
2022-05-18 18:11:40 +02:00
SomberNight
872ce82418 tests: clean up event-loop creation 2022-05-04 01:53:21 +02:00
SomberNight
2c57c78ebe asyncio: stop using get_event_loop(). introduce ~singleton loop.
asyncio.get_event_loop() became deprecated in python3.10. (see https://github.com/python/cpython/issues/83710)
```
.../electrum/electrum/daemon.py:470: DeprecationWarning: There is no current event loop
  self.asyncio_loop = asyncio.get_event_loop()
.../electrum/electrum/network.py:276: DeprecationWarning: There is no current event loop
  self.asyncio_loop = asyncio.get_event_loop()
```
Also, according to that thread, "set_event_loop() [... is] not deprecated by oversight".
So, we stop using get_event_loop() and set_event_loop() in our own code.
Note that libraries we use (such as the stdlib for python <3.10), might call get_event_loop,
which then relies on us having called set_event_loop e.g. for the GUI thread. To work around
this, a custom event loop policy providing a get_event_loop implementation is used.

Previously, we have been using a single asyncio event loop, created with
util.create_and_start_event_loop, and code in many places got a reference to this loop
using asyncio.get_event_loop().
Now, we still use a single asyncio event loop, but it is now stored as a global in
util._asyncio_event_loop (access with util.get_asyncio_loop()).

I believe these changes also fix https://github.com/spesmilo/electrum/issues/5376
2022-04-29 18:49:07 +02:00
ThomasV
f4e902e907 LNWorker: give up payment after timeout, not number of attempts.
Limiting attempts may interrupt a MPP before we receive a MPP_timeout
The attempts parameter is still used in unit tests.
2022-04-29 12:17:38 +02:00
ThomasV
149cccbc4a fix tests (follow-up 2117118047) 2022-04-23 19:40:21 +02:00
ThomasV
60865f3902 Show options if we do not have the liquidity to pay a lightning invoice:
pay onchain, open channel, rebalance.

If we do a swap or open a channel, the payment will be scheduled.
2022-04-20 12:48:22 +02:00