1
0
Commit Graph

16609 Commits

Author SHA1 Message Date
SomberNight
c527ef8967 lnpeer: refuse to forward htlcs that correspond to payreq we created 2023-08-07 18:57:04 +00:00
ThomasV
cb907c90f9 submarine swaps: set prepay_hash for normal swaps.
This fixes the group_id of fee prepayment transactions for the server
2023-08-06 11:37:31 +02:00
SomberNight
8dd5865469 rm unused import
follow-up d51f00e2a3
2023-08-04 18:21:50 +00:00
SomberNight
5a4b98a066 CI: don't run unit tests on "python:rc", looks like it's unmaintained
The "python:rc" tag on dockerhub has not been updated for 2+ years
and is still at 3.10.0rc2. Even 3.11 has been released for many months now.
see https://hub.docker.com/_/python/tags
2023-08-04 18:18:24 +00:00
SomberNight
d51f00e2a3 asyncio.wait_for() is too buggy. use util.wait_for2() instead
wasted some time because asyncio.wait_for() was suppressing cancellations. [0][1][2]
deja vu... [3]

Looks like this is finally getting fixed in cpython 3.12 [4]
So far away...
In attempt to avoid encountering this again, let's try using
asyncio.timeout in 3.11, which is how upstream reimplemented wait_for in 3.12 [4], and
aiorpcx.timeout_after in 3.8-3.10.

[0] https://github.com/python/cpython/issues/86296
[1] https://bugs.python.org/issue42130
[2] https://bugs.python.org/issue45098
[3] https://github.com/kyuupichan/aiorpcX/issues/44
[4] https://github.com/python/cpython/pull/98518
2023-08-04 18:18:21 +00:00
SomberNight
20f4d44f09 cli: "daemon -d": init rpc credentials before os.fork()
follow-up 8b195ee77a
2023-08-03 22:42:08 +00:00
SomberNight
69336befee follow-up ImportedChannelBackup changes: fix opening wallet w/ old cbs
follow-up https://github.com/spesmilo/electrum/pull/8536

```
  1.52 | E | gui.qt.ElectrumGui |
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/gui/qt/__init__.py", line 342, in start_new_window
    wallet = self.daemon.load_wallet(path, None)
  File "/home/user/wspace/electrum/electrum/daemon.py", line 469, in func_wrapper
    return func(self, *args, **kwargs)
  File "/home/user/wspace/electrum/electrum/daemon.py", line 479, in load_wallet
    wallet = self._load_wallet(path, password, manual_upgrades=manual_upgrades, config=self.config)
  File "/home/user/wspace/electrum/electrum/util.py", line 466, in do_profile
    o = func(*args, **kw_args)
  File "/home/user/wspace/electrum/electrum/daemon.py", line 504, in _load_wallet
    db = WalletDB(storage.read(), manual_upgrades=manual_upgrades)
  File "/home/user/wspace/electrum/electrum/wallet_db.py", line 117, in __init__
    self._after_upgrade_tasks()
  File "/home/user/wspace/electrum/electrum/wallet_db.py", line 247, in _after_upgrade_tasks
    self._load_transactions()
  File "/home/user/wspace/electrum/electrum/util.py", line 466, in do_profile
    o = func(*args, **kw_args)
  File "/home/user/wspace/electrum/electrum/wallet_db.py", line 1536, in _load_transactions
    self.data = StoredDict(self.data, self, [])
  File "/home/user/wspace/electrum/electrum/json_db.py", line 117, in __init__
    self.__setitem__(k, v)
  File "/home/user/wspace/electrum/electrum/json_db.py", line 49, in wrapper
    return func(self, *args, **kwargs)
  File "/home/user/wspace/electrum/electrum/json_db.py", line 135, in __setitem__
    v = self.db._convert_dict(self.path, key, v)
  File "/home/user/wspace/electrum/electrum/json_db.py", line 247, in _convert_dict
    v = dict((k, constructor(**x)) for k, x in v.items())
  File "/home/user/wspace/electrum/electrum/json_db.py", line 247, in <genexpr>
    v = dict((k, constructor(**x)) for k, x in v.items())
TypeError: ImportedChannelBackupStorage.__init__() missing 1 required positional argument: 'local_payment_pubkey'
```
2023-08-03 17:21:11 +00:00
SomberNight
a674f63ce3 qt channels list: add TODO
(noticed on regtest)
2023-08-03 17:21:08 +00:00
SomberNight
8b195ee77a cli: "./run_electrum daemon -d" to block until daemon becomes ready
Without this,
`$ python3 -m unittest electrum.tests.regtest.TestUnixSockets.test_unixsockets`
was failing on my machine but succeeding on CI, due to timing differences.
2023-08-03 17:21:05 +00:00
SomberNight
58a9904a34 daemon: rm "daemon_jobs". maybe makes _run API less error-prone
(follow-up prev)
2023-08-03 17:21:01 +00:00
SomberNight
e94d45edd8 swapserver: small clean-up 2023-08-03 17:20:58 +00:00
Sander van Grieken
c068b80d78 qml: fix issues with 2fa, simplify terms and conditions retrieval code 2023-08-03 17:17:06 +02:00
SomberNight
d9d281338c tests: fix logic bug in some regtests
follow-up https://github.com/spesmilo/electrum/pull/8489
2023-08-03 11:40:01 +00:00
Sander van Grieken
f4f88f4294 qml: fix wizard text for keystore, wrap text 2023-07-31 11:43:15 +02:00
Sander van Grieken
583afefe33 qml: add deadzones on the edge of the screen to work around android back gesture unintended click events 2023-07-28 14:47:40 +02:00
ThomasV
a6a2679d8a Merge pull request #8536 from SomberNight/202307_ln_imported_cb
fix sweeping chan after local force-close using cb
2023-07-28 11:16:48 +02:00
ThomasV
c16074c047 Merge pull request #8489 from spesmilo/swapserver_plugin
Swapserver plugin
2023-07-27 10:12:41 +02:00
ThomasV
1b14692f30 swapserver: cleanup, add description 2023-07-26 19:20:18 +02:00
ThomasV
69a1242ea8 restructure submarine_swaps._claim_swap 2023-07-26 19:20:18 +02:00
ThomasV
1411b75584 swapserver: add test for refund path 2023-07-26 19:20:18 +02:00
ThomasV
351ff1e4b5 swapserver: support prepayment of fees 2023-07-26 19:20:18 +02:00
ThomasV
098c65d732 submarine swap server plugin:
- hold invoices
 - uses the same web API as the Boltz backend
2023-07-26 19:20:18 +02:00
ThomasV
8bd1292e9a follow-up e5ac521d38 2023-07-26 19:20:02 +02:00
ThomasV
83dcc5e4cc payment bundles: fix bundle detection for trampoline
This feels a bit like workaround; it might be better to represent
payment bundles objects using payment secrets rather than payment
hashes.
2023-07-26 18:54:20 +02:00
ThomasV
e5ac521d38 maybe_fulfill_htlc: check trampoline before hold invoice
order is important: if we receive a trampoline onion for a hold
invoice, we need to peel the onion through the recursive call.
2023-07-26 18:40:48 +02:00
ThomasV
4d84769096 Qt: Show notification instead of popup if a lightning payment fails. 2023-07-24 17:56:20 +02:00
ThomasV
49b5bf99ae fw_info: use hex value of payment_key, as this is persisted 2023-07-24 17:22:44 +02:00
ThomasV
3bb5ebf137 simplify check_mpp_status
(the distinction that was between is_accepted and is_expired does
not seem to be useful)
2023-07-24 16:43:06 +02:00
ThomasV
141cd524bc lnpeer: do not run maybe_fulfill_htlc more than once, if it
triggered a payment forwarding.

Final onions may trigger a payment forwarding, through the callback
returned by maybe_fulfill_htlc. In that case, we should not fail the
HTLC later; doing so might result in fund loss.

Remove test_simple_payment_with_hold_invoice_timing_out: once we
have accepted to forward a payment HTLC with a hold invoice, we
do not want to time it out, for the same reason.
2023-07-24 12:44:56 +02:00
ThomasV
1296d3361d use payment_secret instead of payment_hash 2023-07-22 09:35:00 +02:00
ThomasV
8630030bd9 Restrict exception type in trampoline_forwarding_failures (follow-up 017186d107) 2023-07-21 19:35:27 +02:00
3rd Iteration
0e5cb19408 Add Vendor/Device IDs for CH340 based DIY Jade devices. (#8546)
* Add Vendor/Device IDs for CH340 based DIY Jade devices.

* Add device descriptions to hardwareIDs
2023-07-21 15:14:56 +00:00
ThomasV
017186d107 Refactor trampoline forwarding and hold invoices.
- maybe_fulfill_htlc returns a forwarding callback that
   covers both cases.
 - previously, the callback of hold invoices was called as a
   side-effect of lnworker.check_mpp_status.
 - the same data structures (lnworker.trampoline_forwardings,
   lnworker.trampoline_forwarding_errors) are used for both
   trampoline forwardings and hold invoices.
 - maybe_fulfill_htlc still recursively calls itself to perform
   checks on trampoline onion. This is ugly, but ugliness is now
   contained to that method.
2023-07-21 13:40:10 +02:00
ThomasV
827792c14c lnpeer: simplify maybe_fulfill_htlc 2023-07-19 15:38:14 +02:00
ThomasV
e124ff7ee7 Trampoline MPP consolidation:
- fix parameters passed to maybe_forward_trampoline
 - use lnworker.trampoline_forwardings as a semaphore for ongoing
   trampoline payments
 - if a trampoline payment fails, fail all received HTLCs
2023-07-19 10:48:44 +02:00
ThomasV
aeaf9c71df Add unit test for trampoline MPP consolidation
This tests that a trampoline waits until all incoming HTLCs are
received, and fail or succeed them together
2023-07-19 09:49:05 +02:00
ThomasV
1e3b3b82d5 test_lnpeer: deepcopy graph definitions in test setup 2023-07-19 09:43:18 +02:00
SomberNight
6977be8e1b util.CallbackManager: keep strong references for running futures
This clears up log spam for regtest tests.

related:
- https://bugs.python.org/issue44665
- https://github.com/python/cpython/issues/88831
- https://textual.textualize.io/blog/2023/02/11/the-heisenbug-lurking-in-your-async-code/
- https://github.com/python/cpython/issues/91887#issuecomment-1434816045
- "Task was destroyed but it is pending!"

Perhaps we should inspect all our usages of
- asyncio.create_task
- loop.create_task
- asyncio.ensure_future
- asyncio.run_coroutine_threadsafe
?

Example log for running a regtest test:
```
$ python3 -m unittest electrum.tests.regtest.TestLightningAB.test_collaborative_close
***** test_collaborative_close ******
initializing alice
--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.10/logging/__init__.py", line 1100, in emit
    msg = self.format(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 943, in format
    return fmt.format(record)
  File "/home/user/wspace/electrum/electrum/logging.py", line 44, in format
    record = copy.copy(record)  # avoid mutating arg
  File "/usr/lib/python3.10/copy.py", line 92, in copy
    rv = reductor(4)
ImportError: sys.meta_path is None, Python is likely shutting down
Call stack:
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1781, in call_exception_handler
    self._exception_handler(self, context)
  File "/home/user/wspace/electrum/electrum/util.py", line 1535, in on_exception
    loop.default_exception_handler(context)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1744, in default_exception_handler
    logger.error('\n'.join(log_lines), exc_info=exc_info)
Message: "Task was destroyed but it is pending!\ntask: <Task pending name='Task-2' coro=<Abstract_Wallet.on_event_adb_set_up_to_date() running at /home/user/wspace/electrum/electrum/wallet.py:485> wait_for=<Future finished result=0> cb=[_chain_future.<locals>._call_set_state() at /usr/lib/python3.10/asyncio/futures.py:392]>"
Arguments: ()

[--- SNIP --- more of the same --- SNIP ---]

--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.10/logging/__init__.py", line 1100, in emit
    msg = self.format(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 943, in format
    return fmt.format(record)
  File "/home/user/wspace/electrum/electrum/logging.py", line 44, in format
    record = copy.copy(record)  # avoid mutating arg
  File "/usr/lib/python3.10/copy.py", line 92, in copy
    rv = reductor(4)
ImportError: sys.meta_path is None, Python is likely shutting down
Call stack:
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1781, in call_exception_handler
    self._exception_handler(self, context)
  File "/home/user/wspace/electrum/electrum/util.py", line 1535, in on_exception
    loop.default_exception_handler(context)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1744, in default_exception_handler
    logger.error('\n'.join(log_lines), exc_info=exc_info)
Message: "Task was destroyed but it is pending!\ntask: <Task pending name='Task-31' coro=<Abstract_Wallet.on_event_adb_set_up_to_date() running at /home/user/wspace/electrum/electrum/wallet.py:485> wait_for=<Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/lib/python3.10/asyncio/futures.py:385, Task.task_wakeup()]> cb=[_chain_future.<locals>._call_set_state() at /usr/lib/python3.10/asyncio/futures.py:392]>"
Arguments: ()
true
true
true
true
funding alice
```
2023-07-17 15:33:57 +00:00
SomberNight
1767d26de9 tests: make regtest tests somewhat faster by faster polling in e-x
using 4e66804dc0

on my machine, before-after:
Ran 9 tests in 495.865s
Ran 9 tests in 376.183s
2023-07-14 15:18:36 +00:00
SomberNight
1a46460d11 fix sweeping chan after local force-close using cb
scenario:
- user opens a lightning channel and exports an "imported channel backup"
- user closes channel via local-force-close
  - local ctx is published, to_local output has user's funds and they are CSV-locked for days
- user restores wallet file from seed and imports channel backup
- new wallet file should be able to sweep coins from to_local output (after CSV expires)

This was not working previously, as the local_payment_basepoint was not included in the
imported channel backups, and the code was interpreting the lack of this as the channel not
having option_static_remotekey enabled. This resulted in lnutil.extract_ctn_from_tx
using an incorrect funder_payment_basepoint, and lnsweep not recognising the ctx due to
the garbage ctn value.

The imported channel backup serialisation format is slightly changed to include the
previously missing field, and its version number is bumped (0->1). We allow importing
both version 0 and version 1 backups, however v0 backups cannot handle the above
described scenario (they can only be used to request a remote-force-close).

Note that we were/are setting the missing local_payment_basepoint to the pubkey of
one of the wallet change addresses, which is bruteforceable if necessary, but I
think it is not worth the complexity to add this bruteforce logic. Also note
that the bruteforcing could only be done after the local-force-close was broadcast.

Ideally people with existing channels and already exported v0 backups should re-export
v1 backups... Not sure how to handle this.

closes https://github.com/spesmilo/electrum/issues/8516
2023-07-14 14:29:21 +00:00
SomberNight
b04ade5d7d tests: add failing test for sweeping chan after local fclose using cb 2023-07-14 13:57:02 +00:00
Sander van Grieken
6b52aad3c8 qml: silence some null deref errors at shutdown 2023-07-14 10:28:50 +02:00
Sander van Grieken
60e007862b qml: defer updates, fixes listitems not updating 2023-07-13 19:17:16 +02:00
Sander van Grieken
0428fc7c0a qml: add explanatory infomessage when sending capacity is significantly less than local balance.
Show message when attempting unfreeze of gossip channel in trampoline mode
2023-07-13 19:17:16 +02:00
Sander van Grieken
45944d280d qml: update channelbar when conditions change 2023-07-13 19:17:16 +02:00
Sander van Grieken
2cf4cc1978 qml: render reserved channel capacity in a darker tone, take frozen into account 2023-07-13 19:17:16 +02:00
Sander van Grieken
4900d01344 allow more time to detect tor 2023-07-13 18:51:48 +02:00
Sander van Grieken
0d7ff92c43 send_tab: remove payment_identifier comments in send_tab 2023-07-11 19:54:07 +02:00
Sander van Grieken
40f15b158c payment_identifier: reconstruct PI for bip70 invoice in pay_onchain_dialog instead of taking the send_tab PI 2023-07-11 17:16:27 +02:00
SomberNight
5b9b616146 simple_config: allow deepcopy-ing ConfigVars
Was getting error:
```
>>> import copy
>>> from electrum.simple_config import SimpleConfig
>>> copy.deepcopy(SimpleConfig.EXPERIMENTAL_LN_FORWARD_PAYMENTS)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "...\Python\Python310\lib\copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle 'ConfigVar' object
```

This is useful in tests/test_lnpeer.py, to deepcopy the GRAPH_DEFINITIONS dict.
2023-07-11 14:50:09 +00:00