1
0
Commit Graph

19356 Commits

Author SHA1 Message Date
f321x
ce7774efa8 regtest: add timeout to wait_ functions
Add 30s timeouts to the "wait_" functions in regtest.sh as it
happens from time to time that they get stuck on the CI and waste compute.
2025-10-31 14:50:28 +01:00
f321x
76f69676d3 config/regtest: add config to disable automatic fee updates
Some regtest tests depend on manual fee injection to simulate certain
mempool conditions (e.g. lnwatcher_waits_until_fees_go_down). This is
done by manually injecting fee estimates into the `Network` object using
the `test_inject_fee_etas` cli command. However it can still happen that
the Network automatically updates its fee estimates from the connected
electrum server in the time between injecting the fee and the actual
tested logic making decisions based on the fee. This causes the test to
fail sometimes.
By setting the `test_disable_automatic_fee_eta_update` true the Network
will stop automatically updating the fee estimates and the test will
behave as expected.
2025-10-31 14:50:26 +01:00
f321x
19e32d6054 lnwatcher/txbatcher: more logging
log more clearly if an input is considered dust, this makes the logs
more helpful when debugging sweeping of lightning utxos.
2025-10-31 14:50:25 +01:00
f321x
80ea7becdc CI: regtest: stop on failed test, expose datadirs
Stops the running regtest if one test fails (using the --failfast
option) and makes the wallet data directories of alice, bob and carol
available for debugging. This seems helpful to fix issues only happening
on the CI.
2025-10-31 14:50:19 +01:00
ghost43
bf0ebc8d2b Merge pull request #10283 from f321x/fix_add_peer
cli: fix add_peer command
2025-10-28 16:15:18 +00:00
f321x
fca879d493 test_commands: add unittest for add_peer cli 2025-10-28 17:08:06 +01:00
f321x
95ba7e7547 cli: add_peer: make add_peer wait for connection
peer initialization was never awaited in the `add_peer` method.
This awaits the initialization of the peer so that the caller
actually knows if connection succeeded or timed out.
2025-10-28 17:07:57 +01:00
ghost43
5e8f43e903 Merge pull request #10285 from f321x/lnpeer_dont_send_gossip_before_init
lnpeer: await init in main_loop
2025-10-28 15:33:41 +00:00
f321x
a5cf5f75fc lnpeer: await init in main_loop
Because `LNPeer.initialized` was awaited in
`LNPeer._query_gossip()` instead of the main loop the other tasks got
spawned concurrently and each task on its own has to wait for the
initialization. In `LNPeer._send_own_gossip()` this was missing, instead
there is a fixed 10 sec sleep. If the connection was not initialized but
the 10 sec are exceeded `_send_own_gossip()` tries to send gossip and
causes this exception as the `LNTransport` is not ready:

```
  2.13 | E | lnpeer.Peer.[LNWallet, 0288fa27c0-bc1900c8] | Exception in main_loop: AttributeError("'LNTransport' object has no attribute 'sk'")
Traceback (most recent call last):
  File "/home/user/code/electrum-fork/electrum/util.py", line 1232, in wrapper
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/code/electrum-fork/electrum/lnpeer.py", line 511, in wrapper_func
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/code/electrum-fork/electrum/lnpeer.py", line 525, in main_loop
    async with self.taskgroup as group:
               ^^^^^^^^^^^^^^
  File "/home/user/code/electrum-fork/env/lib/python3.14/site-packages/aiorpcx/curio.py", line 304, in __aexit__
    await self.join()
  File "/home/user/code/electrum-fork/electrum/util.py", line 1420, in join
    task.result()
    ~~~~~~~~~~~^^
  File "/home/user/code/electrum-fork/electrum/lnpeer.py", line 573, in _send_own_gossip
    self.send_node_announcement(alias, color)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/home/user/code/electrum-fork/electrum/lnpeer.py", line 1830, in send_node_announcement
    self.transport.send_bytes(raw_msg)
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/user/code/electrum-fork/electrum/lntransport.py", line 225, in send_bytes
    lc = aead_encrypt(self.sk, self.sn(), b'', l)
                      ^^^^^^^
AttributeError: 'LNTransport' object has no attribute 'sk'. Did you mean: 'sn'?
```

By awaiting the initialization directly in the `main_loop` it is more
clear that the task getting spawned subsequently depend on the transport
being available and separates the initialization more clearly these
other functions.
2025-10-28 15:42:16 +01:00
ghost43
d379a66a8f Merge pull request #10282 from f321x/cleanup_event_loop
util: cleanup asyncio event loop after stopping
2025-10-28 14:15:03 +00:00
ghost43
36606efdb2 Merge pull request #10284 from f321x/xml_clipboard
android: qr scanner: add emoji to clipboard string
2025-10-28 13:56:38 +00:00
f321x
08673d3534 util: cleanup asyncio event loop after stopping
I noticed many ResourceWarning when running regtests with
PYTHONASYNCIODEBUG=1 and PYTHONDEVMODE=1, each time a daemon
gets stopped the asyncio loop wouldn't get properly cleaned up:

```
(env) user@hp:~/code/electrum-fork$ python3 -m unittest tests.regtest.TestLightningAB.test_lnwatcher_waits_until_fees_go_down
***** test_lnwatcher_waits_until_fees_go_down ******
initializing alice
  0.67 | W | asyncio | Executing <Task finished name='Task-1' coro=<run_offline_command() done, defined at /home/user/code/electrum-fork/./run_electrum:229> result={'msg': 'Please keep ... your wallet.', 'path': '/tmp/alice/r...efault_wallet', 'seed': 'fiction sadd...it radar desk'} created at /home/user/code/electrum-fork/electrum/util.py:1760> took 0.280 seconds
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
funding alice
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
f84277454a04243e500cf84c67aad16e04dd7a88ffa849ffcf20ce3f9af277df
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
initializing bob
  0.54 | W | asyncio | Executing <Task finished name='Task-1' coro=<run_offline_command() done, defined at /home/user/code/electrum-fork/./run_electrum:229> result={'msg': 'Please keep ... your wallet.', 'path': '/tmp/bob/reg...efault_wallet', 'seed': 'wink loud so...ory myth case'} created at /home/user/code/electrum-fork/electrum/util.py:1760> took 0.195 seconds
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
funding bob
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
f68b651e84dc8547f54dd09129018a2d0d256dedc8ccc48595ae172de895371a
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
mining 1 blocks
starting daemon (PID 38153)
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
/tmp/alice/regtest/wallets/default_wallet
/usr/lib64/python3.14/asyncio/base_events.py:758: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=True>
```

This commits adds some cleanup to `util.create_and_start_event_loop()`
to
1. cancel remaining tasks
2. shut down asyncgens
3. shutdown the default executor
4. call loop.close() to free the resources allocated to the loop
See https://stackoverflow.com/questions/30765606/whats-the-correct-way-to-clean-up-after-an-interrupted-event-loop

This seems to reliably solve the mentioned `ResourceWarning`.
2025-10-28 14:53:35 +01:00
f321x
c816987164 android: qr scanner: add emoji to clipboard string
The string is not translated and might not be accessible for non-english
speakers, even though its relatively self-explanatory i think adding
this emoji makes it more accessible.
2025-10-28 14:32:04 +01:00
SomberNight
6423323037 interface: PaddedRSTransport: keep in sync with e-x: flush on close
ref f62f986b33

note: ReplyAndDisconnect is specific to electrumx, however I think the name is descriptive enough to keep it here.
2025-10-27 18:09:33 +00:00
ghost43
356f50beae Merge pull request #10280 from f321x/fix_network_tab_selection
qt: fix ServerWidget (Network Tab)
2025-10-27 17:58:33 +00:00
ghost43
d21fd59815 Merge pull request #10281 from f321x/dont_connect_to_other_networks
interface: check genesis hash on connection
2025-10-27 17:55:09 +00:00
f321x
f2aa4404ad qt: fix ServerWidget
The ServerWidget was not working properly, when switching from "Manual
Mode" to "Auto Connect" the change wouldn't get saved as it depended on
having a correct server string entered (which isn't neccessary for Auto
Connect).
Also makes the widget behave more sane by cleaning the server input if
Auto Connect is enabled and switching to Manual Mode if the user
manually selects a server.

Update the ServerWidget every time it is shown (on initialization and
also when the user opens it again or switches between network dialog
tabs).
This will clean it up if the user has entered some invalid server and
closes it, otherwise this server would stay in the input field until the
application is restarted.

The list of servers in the ServerWidget allows the user to right click
and 'Use as server' on the servers in the list, however internally it
was handled differently than what the user would expect when clicking on
'Use as server'. E.g. if the user selects a server in autoconnect mode
it would still stay in autoconnect mode so the server could switch again
to another server any time? Now it will also change the mode to manual
(or stay in single server mode if that was selected before), making it
clear that this server will stay selected.

If the user clicks on "Follow this branch" the connect mode will get changed to
autoconnect as internally we connect to a random interface on this
branch.
2025-10-27 18:46:36 +01:00
f321x
679b7fe122 interface: add warmup budget to PaddedRSTransport
Adds a 1024 (unpadded) byte budget to the PaddedRSTransport below which
messages are instantly flushed down the socket before the transport will
beginn waiting for the buffer to reach MIN_PACKET_SIZE (1024).
This allows to get the first couple of messages sent quickly when
starting the wallet to improve UX.
2025-10-27 18:31:37 +01:00
f321x
ff2bbf159e interface: check genesis hash on connection
Prevents the client from accidentally connecting to a server on a
different network.
I noticed its possible to connect to mainnet servers on a signet
instance causing the recent peers to get populated with mainnet peers
rendering the wallet instance barely usable. Doing this check should
prevent this and similar issues.
2025-10-27 16:57:28 +01:00
ghost43
4bce545c26 Merge pull request #10275 from SomberNight/202510_android_desc
fastlane: revert full_description to plain text
2025-10-21 16:57:02 +00:00
SomberNight
224c5fa6c0 fastlane: revert full_description to plain text
Rich text does not work reliably.
This reverts to the old formatting, but keeps some of the reordering/text changes.
follow-up https://github.com/spesmilo/electrum/pull/9492

I compared looking at the description in:
- google play store app
- google play store website [1]
- fdroid app
- fdroid website [2]

notes:
- Links work on playstore website and fdroid website, but not in the apps.
  In the apps, they are not even shown at all, they are just ignored.
- ul/li/b tags do not work on playstore website

[1] https://play.google.com/store/apps/details?id=org.electrum.electrum
[2] https://f-droid.org/en/packages/org.electrum.electrum/
2025-10-21 16:48:27 +00:00
ghost43
c4306f041a Merge pull request #10268 from dulanting/master
chore: fix comment for electrum/gui/qt/main_window.py
2025-10-21 14:54:58 +00:00
dulanting
08fd2de003 chore: fix comment for electrum/gui/qt/main_window.py
Signed-off-by: dulanting <dulanting@outlook.jp>
2025-10-13 16:26:50 +08:00
ghost43
b3ab732998 Merge pull request #10265 from SomberNight/202510_ci_py314
ci: add task to also run unit tests with new python 3.14
2025-10-09 19:06:37 +00:00
SomberNight
dbacb503a4 tests: fix DeprecationWarnings for py3.14: asyncio.iscoroutinefunction
same as https://github.com/spesmilo/electrum/pull/10197
2025-10-09 15:43:54 +00:00
ghost43
611f9b4485 Merge pull request #10264 from SomberNight/202510_tx_cleanup
transaction: (trivial) add some missing type hints, minimal clean-up
2025-10-09 15:34:58 +00:00
ghost43
89734b3bd4 Merge pull request #10242 from f321x/return_preimage_cli
cli: add command to export preimage, return preimage from check_hold_invoice
2025-10-09 15:31:04 +00:00
SomberNight
2dc9ca906b ci: add task to also run unit tests with new python 3.14 2025-10-09 15:17:48 +00:00
SomberNight
6e45d6e690 lnworker: (trivial) add a few missing type-hints 2025-10-09 15:06:23 +00:00
SomberNight
3379e46249 follow-up prev: add type-hints, etc 2025-10-09 14:57:41 +00:00
SomberNight
f1ad5bc23d transaction: (move-only) move some methods from Tx to PartialTx cls
these were already assuming `isinstance(self, PartialTransaction)`
2025-10-09 14:46:42 +00:00
SomberNight
f832c33d76 qt: main_window.confirm_tx_dialog: rm dead code 2025-10-09 14:36:15 +00:00
SomberNight
58676219f4 wallet: (trivial) mark calc_unused_change_addresses as private 2025-10-07 17:45:38 +00:00
ThomasV
f4e7ffd5f3 lnworker: set OPTION_ONION_MESSAGE_OPT feature if we are forwarding. 2025-10-07 11:19:37 +02:00
SomberNight
95309e6730 Merge branch '202510_lnurlw': implement LNURL-withdraw
ref https://github.com/spesmilo/electrum/pull/9993
2025-10-03 02:21:31 +00:00
SomberNight
af6715040c lnurlw: follow-up: adapt to recent lnworker.get_bolt11_invoice refactor 2025-10-03 02:12:04 +00:00
SomberNight
ef8d53c46a lnurlw: follow-up: fix android edge-to-edge layout padding
as per https://github.com/spesmilo/electrum/pull/9993#issuecomment-3228252596
2025-10-03 02:11:43 +00:00
SomberNight
7d0ac64d06 Merge remote-tracking branch 'spesmilo/pr/9993': lnurl-withdraw
ref https://github.com/spesmilo/electrum/pull/9993
2025-10-02 23:34:40 +00:00
SomberNight
2b0cab68c6 partial merge 2: f321x's "lightning: refactor htlc switch"
split-off from https://github.com/spesmilo/electrum/pull/10230

Merge commit '286fc4b86e4d23cb9af15b9061b3d709e7592bcb'
2025-09-30 16:55:15 +00:00
f321x
b57f867c2f cli: add command to export preimage
..also export preimage in check_hold_invoice return value if available.

I intentionally did not return the preimage in the returned dict of
wallet.export_requests as this seems risky to do considering some users
of the cli might forward the response to a payer and the payserver
exposes it too.

Closes https://github.com/spesmilo/electrum/issues/10176
2025-09-30 10:37:20 +02:00
f321x
286fc4b86e lnworker: enforce creation of PaymentInfo for b11
Enforce that the information used to create a bolt11 invoice using
`get_bolt11_invoice()` is similar to the related instance of PaymentInfo
by requiring a PaymentInfo as argument for `get_bolt11_invoice()`.
This way the invoice cannot differ from the created PaymentInfo.
This allows to use the information in PaymentInfo for validation of
incoming htlcs more reliably.

To cover all required information for the creation of a b11 invoice the
PaymentInfo class has to be extended with a expiry and
min_final_cltv_expiry. This requires a db upgrade.
2025-09-30 09:54:35 +02:00
f321x
d62b627a0b lnpeer: move htlc forwarding funcs to lnworker
forwarding happens independent of the peer that received the htlc to
forward and fits better in lnworker.
2025-09-30 09:54:24 +02:00
SomberNight
3d27992fb7 lnonion: (trivial) make OnionPacket.__init__ kw-only 2025-09-29 17:13:27 +00:00
SomberNight
862f76bfef partial merge 1: f321x's "lightning: refactor htlc switch"
split-off from https://github.com/spesmilo/electrum/pull/10230
2025-09-29 17:12:25 +00:00
f321x
32aa6ab20c lnutil: rename RecvMPPResolution.ACCEPTED
Renames RecvMPPResolution.ACCEPTED to .COMPLETE as .ACCEPTED is somewhat
misleading. Accepted could imply that the preimage for this set has been
revealed or that the set has been settled, however it only means that we
have received the full set (it is complete), but the set still can be
failed (e.g. through cltv timeout) and has not been claimed yet.
2025-09-29 16:11:26 +00:00
f321x
6a4ad9e67c lnonion: check onion version in process_onion_packet
Adds checks for the onion version in process_onion_packet and fails it
back with the correct error instead of raising in the OnionPacket
constructor.
2025-09-29 16:11:23 +00:00
f321x
7d0a69a9ce lnpeer: only spawn htlc_switch for peers with LNWallet
stop spawning htlc_switch for LNGossip peers, they don't handle any
htlcs
2025-09-29 16:11:20 +00:00
f321x
fcc3796079 lnworker: move RecvMPPResolution and status to lnutil
it is required both in lnpeer and lnworker, moving it to lnutil seems to
make more sense.

# Conflicts:
#	electrum/lnworker.py
2025-09-29 16:11:17 +00:00
f321x
9db975f9d7 lightning: remove legacy payment secret derivation
This seems old and not very useful anymore.
2025-09-29 16:11:13 +00:00
f321x
0ae60d8b45 lnonion: make comparisons more constant time
makes hmac comparisons and onion error decoding more constant time
according to bolt 4. However things might still not be perfectly
constant time, however this seems out of scope for timing over network.
2025-09-29 16:11:10 +00:00