1
0
Commit Graph

16954 Commits

Author SHA1 Message Date
ThomasV
b0dbdfd5e4 test_lnpeer: split some tests, remove redundant test 2023-10-23 13:02:02 +02:00
ThomasV
6dfbdec73e follow-up prev commit 2023-10-20 13:52:55 +02:00
ThomasV
b26f954c2d lnworker.pay_to_node: skip error handling if sender_idx is None 2023-10-20 13:42:12 +02:00
ThomasV
f8781364d2 test_lnpeer:
- Refactor _run_mpp so that it takes only one set of arguments.
   Success and failure conditions are now tested by calling
   _run_mpp multiple times.

 - In test_payment_multipart with_timeout, check that the received
   failure message actually is MPP_TIMEOUT, and not a generic
   failure. Since the onion is obfuscated by the forwarding node,
   this tests that obfuscate_onion_packet and decode_onion_packet
   work as expected.
2023-10-20 11:36:50 +02:00
ThomasV
b776d79f7f lnpeer: move access to payment_secret inside try..except block, as it might raise 2023-10-20 10:12:14 +02:00
SomberNight
687171c36a exchange_rate: cleaner log line for "failed fx history"
related a38e723b40
2023-10-19 17:15:41 +00:00
SomberNight
22a8348303 renames: use consistent naming of cltv delta vs cltv abs
to avoid confusing relative vs absolute cltvs
(see b0401a6386)
2023-10-19 16:40:05 +00:00
ThomasV
b645da6514 test_lnpeer: separate graph creation from run_trampoline 2023-10-19 18:32:04 +02:00
SomberNight
f78340efbc lnworker: (trivial) fix type hint
follow-up 4c42840c1c
2023-10-19 15:26:20 +00:00
SomberNight
783dc0cdd5 lnpeer.maybe_fulfill_htlc: also check cltv and amt against inner onion
- is_trampoline was True iff we are the final recipient of a trampoline payment
  - in that case, we were only comparing htlc.cltv_expiry against the outer onion cltv
  - we should and do now also compare against the inner onion cltv
- the checks are changed from "!=" to "<", to adapt to bolts PR 1032
  - see b38156b951
  - note that the leniency is needed for the cltv off-by-one
    added in eca10eb04d to work
2023-10-19 15:23:21 +00:00
ThomasV
7ea2e68507 follow-up 4c42840c1c 2023-10-19 16:05:54 +02:00
ThomasV
4c42840c1c lnpeer: obfuscate error pakets of forwarded htlcs, that we
propageate back to the sender.

lnworker: in htlc_fulfilled and htlc_failed, return early if the
htlc was forwarded, so that we do not trigger invoice callbacks
2023-10-19 15:59:26 +02:00
ThomasV
250884489e Revert "lnonion: fix decode_onion_error"
This reverts commit 08132d6b7d.
2023-10-19 13:12:15 +02:00
ThomasV
08132d6b7d lnonion: fix decode_onion_error
error_packet was side-effected by the loop. as a result, decoding
worked only for routes of length 1
2023-10-19 12:58:14 +02:00
SomberNight
eca10eb04d lnpeer.maybe_forward_trampoline: fix cltv calculation
follow-up b0401a6386
2023-10-18 19:22:52 +00:00
SomberNight
a059a9a256 lnpeer.pay: also log hops_data for trampoline_onion
We were already logging the outer-layer hops_data,
now we also log the inner trampoline-onion hops_data.

Example:
```
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | lnpeer.pay len(route)=1
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] |   0: edge=9926297x9781928x61754 hop_data=<OnionHopsDataSingle. payload={'amt_to_forward': {'amt_to_forward': 100000000}, 'outgoing_cltv_value': {'outgoing_cltv_value': 601299}, 'payment_data': {'payment_secret': b'\xd2\x9cl\xdfV\xd4\xea_\x06{\xed\xc9\xc7\xa6\xf5\xc0\n\x1a\x95\xad\xad\xd2F\xb8;&\x9f\xa1\xe1\xd1\x07H', 'total_msat': 100000000, 'amount_msat': 100000000}}. hmac=None>
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | adding trampoline onion to final payload
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | lnpeer.pay len(t_route)=3
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] |   0: t_node=02389c93b85ef8f7264c6fa3d3b239341c2631c2cab97e815b33453bd8d0254e77 hop_data=<OnionHopsDataSingle. payload={'amt_to_forward': {'amt_to_forward': 100000000}, 'outgoing_cltv_value': {'outgoing_cltv_value': 600723}, 'outgoing_node_id': {'outgoing_node_id': b'\x03\x06\xd9,\x9c\xabRe\x83Mr\x0b\x14(\xf5\x81\xf9\xfb\x9b\xfeV\xc1q\x85&L\xda\xffs\xe5y(\x81'}}. hmac=b'\xe7\x04\xe2>\x9a\xd9\xf0\x92<\xf8Q\xe4\xf4\xd8\x8cr{\x1e\xb1\xee\xb0\xd4R\xba\xe5\xfd\x83\xfc\xd7\xa7\x1dt'>
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] |   1: t_node=0306d92c9cab5265834d720b1428f581f9fb9bfe56c17185264cdaff73e5792881 hop_data=<OnionHopsDataSingle. payload={'amt_to_forward': {'amt_to_forward': 100000000}, 'outgoing_cltv_value': {'outgoing_cltv_value': 600147}, 'outgoing_node_id': {'outgoing_node_id': b'\x03\x85v\xac:\xf8AUW\xcf\x1d\x12e\xcc\xff\xb1\xea\xd6\x01\xd5\x17HX?\x12\x83\x9cD\xbe\xebC\x82o'}}. hmac=b's-\xe1\xdb\xbc\xa5\x88\x90\xc0\xafu\xab\xba\xb6k\x81\xeae)#\x85\x12fm\xe6\xc3\xbd\xf6\x86eR\xd2'>
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] |   2: t_node=038576ac3af8415557cf1d1265ccffb1ead601d51748583f12839c44beeb43826f hop_data=<OnionHopsDataSingle. payload={'amt_to_forward': {'amt_to_forward': 100000000}, 'outgoing_cltv_value': {'outgoing_cltv_value': 600147}, 'payment_data': {'payment_secret': b'B-P\x01\xc3\x1e#\x19\xf9!\xbb\xd8\xd1pu\xc7J\x11A\xa8J\xfe\xb8\x8a\xb8\xc4Oi\x0f\xe8\xac\xab', 'total_msat': 100000000}}. hmac=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'>
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | starting payment. len(route)=1.
```
2023-10-18 18:07:21 +00:00
ThomasV
2664ee7f63 pay_to_node: raise failure_msg if we received a trampoline error from the next onion.
that way, the error is sent back to the payer
2023-10-18 19:32:13 +02:00
SomberNight
04d8eec3be tests: change fake block height in test_lnpeer. 0 might hide bugs. 2023-10-18 17:09:53 +00:00
SomberNight
b0401a6386 lnpeer.maybe_forward_trampoline: fix abs-cltv vs cltv-delta confusion
lnworker.pay_to_node(min_cltv_expiry=) expects a relative cltv, and
we were passing an absolute one.
It is not so clear what precisely should be passed here, and that is
because pay_to_node's API was not written with forwarding in mind.
The value chosen here is just some guess that typically should work.
2023-10-17 18:22:36 +00:00
SomberNight
0273659e6e trustedcoin: fix keystore name (2)
follow-up 56e80c20d7
2023-10-17 14:33:05 +00:00
SomberNight
a38e723b40 exchange_rate: cleaner log line for "failed fx quotes"
catch OSError for proxy-related issues (and probably other low level networking)

```
 19.52 | E | exchange_rate.CoinGecko | failed fx quotes: ProxyConnectionError(22, 'Can not connect to proxy localhost:9050 [The remote computer refused the network connection]')
Traceback (most recent call last):
  File "...\Python310\site-packages\python_socks\async_\asyncio\ext\_proxy.py", line 59, in _connect
    await self._stream.open_connection(
  File "...\Python310\site-packages\python_socks\async_\asyncio\ext\_stream.py", line 61, in open_connection
    self._reader, self._writer = await asyncio.open_connection(
  File "...\Python310\lib\asyncio\streams.py", line 48, in open_connection
    transport, _ = await loop.create_connection(
  File "...\Python310\lib\asyncio\base_events.py", line 1076, in create_connection
    raise exceptions[0]
  File "...\Python310\lib\asyncio\base_events.py", line 1060, in create_connection
    sock = await self._connect_sock(
  File "...\Python310\lib\asyncio\base_events.py", line 969, in _connect_sock
    await self.sock_connect(sock, address)
  File "...\Python310\lib\asyncio\proactor_events.py", line 709, in sock_connect
    return await self._proactor.connect(sock, address)
  File "...\Python310\lib\asyncio\windows_events.py", line 826, in _poll
    value = callback(transferred, key, ov)
  File "...\Python310\lib\asyncio\windows_events.py", line 613, in finish_connect
    ov.getresult()
ConnectionRefusedError: [WinError 1225] The remote computer refused the network connection

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "...\electrum\exchange_rate.py", line 85, in update_safe
    self._quotes = await self.get_rates(ccy)
  File "...\electrum\exchange_rate.py", line 345, in get_rates
    json = await self.get_json('api.coingecko.com', '/api/v3/exchange_rates')
  File "...\electrum\exchange_rate.py", line 69, in get_json
    async with session.get(url) as response:
  File "...\Python310\site-packages\aiohttp\client.py", line 1140, in __aenter__
    self._resp = await self._coro
  File "...\Python310\site-packages\aiohttp\client.py", line 535, in _request
    conn = await self._connector.connect(
  File "...\Python310\site-packages\aiohttp\connector.py", line 543, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "...\Python310\site-packages\aiohttp\connector.py", line 906, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "...\Python310\site-packages\aiohttp\connector.py", line 1174, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "...\Python310\site-packages\aiohttp_socks\connector.py", line 58, in _wrap_create_connection
    stream = await proxy.connect(
  File "...\Python310\site-packages\python_socks\async_\asyncio\ext\_proxy.py", line 47, in connect
    await self._connect()
  File "...\Python310\site-packages\python_socks\async_\asyncio\ext\_proxy.py", line 73, in _connect
    raise ProxyConnectionError(e.errno, msg) from e
python_socks._errors.ProxyConnectionError: [Errno 22] Can not connect to proxy localhost:9050 [The remote computer refused the network connection]
```
2023-10-17 14:30:15 +00:00
ThomasV
cd712f2f60 follow-up 1ea49582ab 2023-10-17 12:52:02 +02:00
ThomasV
1ea49582ab fix type of forwarding_info 2023-10-17 12:36:15 +02:00
ThomasV
026a64de94 channel_announcements:
- construct_channel_announcement: return also whether
   node ids are in reverse order
 - maybe_send_channel_announcement:
   return early if signatures have not been received
2023-10-17 12:15:35 +02:00
ThomasV
0a732a0b52 trustedcoin: fix keystore name (follow-up 56e80c20d7) 2023-10-17 10:00:17 +02:00
SomberNight
30c863d32c lnaddr: don't call validate_features in parser
- see comment in lnaddr.py
- Previously we used feature bit 50/51 for trampoline.
  The spec subsequently defined fbit 50/51 as option_zeroconf, which
  requires fbit 46/47 (option_scid_alias) to also be set.
  We moved the non-standard trampoline fbit to a different int.
  However, old wallets might have old invoices saved that set fbit 50/51
  for trampoline, and those would not have the dependent bit set.
  Invoices are parsed at wallet-open, so if the parser ran these checks,
  those wallets could not be opened.
- note: we could potentially also run lnaddr.validate_and_compare_features
  when saving new invoices into the wallet but this is not done here
2023-10-16 17:10:49 +00:00
ThomasV
98a4d7b60d public channels:
- send node and channel announcements.
 - store channel_flags in constraints
 - store signatures in local and remote configs
2023-10-16 13:54:16 +02:00
ThomasV
aad4fd6d48 Fix sending of 'channel_ready':
- send only once
 - in channel_reestablish, do not send it if we are not funded.
 - lnworker: do not send channel_ready before channel_reestablish
2023-10-15 10:58:37 +02:00
ThomasV
8d5f9185a4 follow-up #8646 2023-10-14 10:13:27 +02:00
ThomasV
ac177577a6 lnpeer: do not set channel OPEN before channel_ready has been both sent and received.
fixes #8641
2023-10-13 16:56:25 +02:00
Sander van Grieken
b20a4b9bf1 qml: increase font on seed keyboard, and height of seedkeyboard slightly 2023-10-13 13:42:16 +02:00
Sander van Grieken
8c4532c5cb qml: properly show warnings in info box in RbfBumpFeeDialog 2023-10-12 16:22:51 +02:00
Sander van Grieken
941f425ff5 qml: update invoice.canPay on channel state changes
This re-evaluates invoice.canPay when channels get connected/disconnected (enables/disables Pay button)
2023-10-12 15:53:15 +02:00
Sander van Grieken
8dbb2e0c33 qml: remove eye icon for watch-only wallets from toolbar 2023-10-12 15:17:16 +02:00
ThomasV
89023cc123 Remove trampoline hints from invoices
This has been deprecated for a long time, was kept only for
compatibility with old electrum clients.
2023-10-11 09:47:36 +02:00
SomberNight
57d2efc88d wallet: merge mktx and create_transaction 2023-10-10 17:45:26 +00:00
ThomasV
f4997c3771 follow-up 7576a99a0b 2023-10-10 19:41:37 +02:00
ThomasV
e882856d4f Merge pull request #8646 from accumulator/load_wallet_refactor
daemon: refactor load_wallet
2023-10-10 19:33:20 +02:00
ThomasV
7576a99a0b wallet.unlock: raise exception if password is missing (follow-up 2e52b17a43) 2023-10-10 19:23:09 +02:00
SomberNight
65394c37d5 wallet.make_unsigned_transaction: add batch_rbf/send_change params
Don't side-effect config just to modify the next call of make_unsigned_transaction >.<
Cleaner to pass parameters.
2023-10-10 17:13:18 +00:00
Sander van Grieken
7ca9b735d5 daemon: refactor load_wallet to not just return None, but raise specific exceptions.
The following exceptions should be expected:
FileNotFoundError: given wallet path does not exist
StorageReadWriteError: given file is not readable/writable or containing folder is not writable
InvalidPassword: wallet requires a password but no password or an invalid password was given
WalletFileException: any internal wallet data issue. specific subclasses can be caught separately:
-  WalletRequiresSplit: wallet needs splitting (split_data passed in Exception)
-  WalletRequiresUpgrade: wallet needs upgrade, and no upgrade=True was passed to load_wallet
-  WalletUnfinished: wallet file contains an action and needs additional information to finalize. (WalletDB passed in exception)

Removed qml/qewalletdb.py

This patch also fixes load_wallet calls in electrum/scripts and adds a qml workaround for dialogs opening and closing so
fast that the dialog opened==true property change is missed (which we need to manage the dialog/page stack)
2023-10-10 17:42:07 +02:00
SomberNight
bfba0dba56 storage: make partial writes pos sanity-check more robust
The return value of f.write and f.seek cannot be compared when using open() in text mode:
```
>>> import os
>>> s = "aá"
>>>
>>> with open("a1", "w", encoding='utf-8') as f:
...   a = f.write(s)
...   pos = f.seek(0, os.SEEK_END)
...   print(a, pos)
...
2 3
>>>
>>> with open("a2", "wb") as f:
...   a = f.write(s.encode('utf-8'))
...   pos = f.seek(0, os.SEEK_END)
...   print(a, pos)
...
3 3
```

Was getting errors on Windows, probably due to `\r\n` vs `\n`?
```
20231010T121334.522573Z |    ERROR | util.CallbackManager | cb errored. event='adb_set_up_to_date'. exc=AssertionError((2471475, 2522998))
Traceback (most recent call last):
  File "...\electrum\electrum\wallet.py", line 497, in on_event_adb_set_up_to_date
    self.save_db()
  File "...\electrum\electrum\wallet.py", line 403, in save_db
    self.db.write()
  File "...\electrum\electrum\json_db.py", line 48, in wrapper
    return func(self, *args, **kwargs)
  File "...\electrum\electrum\json_db.py", line 389, in write
    self._append_pending_changes()
  File "...\electrum\electrum\json_db.py", line 48, in wrapper
    return func(self, *args, **kwargs)
  File "...\electrum\electrum\json_db.py", line 400, in _append_pending_changes
    self.storage.append(s)
  File "...\electrum\electrum\storage.py", line 110, in append
    assert pos == self.pos, (self.pos, pos)
AssertionError: (2471475, 2522998)
```
2023-10-10 14:33:22 +00:00
SomberNight
63143307f1 config: follow-up rename of FEE_EST_STATIC_FEERATE
follow-up 455167136d
2023-10-10 12:11:45 +00:00
ThomasV
57c9059cab open_channel_with_peer: return funding tx
(this makes things easier the just_in_time_channels branch)
2023-10-09 17:02:19 +02:00
ThomasV
2f8325ca09 follow-up 455167136d (variable rename) 2023-10-09 12:31:23 +02:00
ThomasV
f6bebec0a5 follow-up prev commit (variable rename) 2023-10-09 12:19:23 +02:00
ThomasV
455167136d CLI: new getfeerate/setfeerate API 2023-10-09 12:14:39 +02:00
ThomasV
e2fb928e4f delete htlc session keys once they are no longer needed.
fixes #8630

Note: maybe we should plan a WalletDB upgrade to cleanup
existing wallets.
2023-10-08 15:52:41 +02:00
ThomasV
4e76ed6952 move INITIAL_TRAMPOLINE_FEE_LEVEL to config 2023-10-08 15:06:19 +02:00
ThomasV
8acb5dd7e9 CI: run unit tests in debug mode with python 3.11
Python 3.12 does not work with current aiohttp, see
https://github.com/aio-libs/aiohttp/issues/7229

It is currently possible to build a wheel using aiohttp==3.9.0b0.
However, unit tests fail in that case, because TestLNTransport::test_loop stalls.
2023-10-08 11:43:55 +02:00