Commit Graph

319 Commits

Author SHA1 Message Date
cc25276e6c Remove deprecated network configurations and related files for testnet4, signet, and mutinynet 2025-11-27 15:09:34 +01:00
f9f992afe2 Rename electrum to pallectrum across project
Update all references from 'electrum' to 'pallectrum' including:
- Directory paths in build scripts
- Application name and metadata
- Desktop entries and MIME types
- Android package configurations
- Windows installer settings
- User data directory locations
- Website URLs and project references
2025-11-24 08:35:40 +01:00
0c5431957a Replace multiple bitcoin explorers with palladium explorer
Simplify the block explorers configuration by removing all entries except for the Palladium Explorer. This change focuses the application on a single, more relevant explorer service.
2025-11-21 10:57:22 +01:00
6a39a1401a Replace BTC references with PLM in codebase
Update all instances of BTC currency references to PLM across multiple files including UI components, utility functions, and command descriptions to reflect the new currency denomination
2025-11-20 16:43:48 +01:00
f321x
936e7fd1c2 lnonion: immutable OnionPacket and OnionHopsDataSingle
Make OnionHopsDataSingle and OnionPacket immutable for safer caching and
handling.

# Conflicts:
#	electrum/onion_message.py
2025-11-11 14:37:37 +01: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
SomberNight
5d1df96020 tests: clear util.callback_mgr between test cases
util.callback_mgr.callbacks was not getting properly cleared between tests.
Every time an Abstract_Wallet or an LNWorker (or many other subclasses of EventListener) is instantiated,
self.register_callbacks() is called in __init__, which puts callbacks into util.callback_mgr.callbacks.
These are only cleaned up if we explicitly call Abstract_Wallet.stop() or LNWorker.stop() later, which we usually do not do in the tests.

As a result, when running multiple unit tests in a row, lots of objects created in a given testcase are never GC-ed and leak into subsequent tests. This is not only a memory leak, but wastes compute too: when events are triggered and cbs get called, these old objects also have their cbs called.

After running all (~1061) unit tests, I observe util.callback_mgr.callbacks had 30 events with a total of 3156 callbacks stored.

On my laptop, running all unit tests previously took ~115 sec, and now it takes ~73 sec.
2025-09-26 15:53:41 +00:00
SomberNight
b944371ffd adb: change API of util.TxMinedInfo: height() is now always SPV-ed 2025-09-24 13:46:24 +00:00
f321x
e7bb75bc3e chore: replace calls to asyncio.iscoroutinefunction
Replace calls to deprecated asyncio.iscoroutinefunction with calls to
inspect.iscoroutinefunction to prevent the following deprecation
warnings from showing up if running with Python 3.14:
```
/home/user/code/electrum-fork/electrum/util.py:1225: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
  assert asyncio.iscoroutinefunction(func), 'func needs to be a coroutine'
/home/user/code/electrum-fork/electrum/util.py:507: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
  if asyncio.iscoroutinefunction(func):
/home/user/code/electrum-fork/electrum/util.py:1246: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
  assert asyncio.iscoroutinefunction(func), 'func needs to be a coroutine'
/home/user/code/electrum-fork/electrum/lnpeer.py:272: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
  assert asyncio.iscoroutinefunction(func), 'func needs to be a coroutine'
/home/user/code/electrum-fork/electrum/util.py:1225: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
  assert asyncio.iscoroutinefunction(func), 'func needs to be a coroutine'
/home/user/code/electrum-fork/electrum/util.py:507: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
  if asyncio.iscoroutinefunction(func):
```
2025-09-05 10:29:34 +02:00
SomberNight
23a82f328f util: fix DebugMem helper
```
 28.99 | I | util.DebugMem | Start memscan
 29.10 | E | plugin.Plugins |
Traceback (most recent call last):
  File "...\electrum\util.py", line 405, in run_jobs
    job.run()
  File "...\electrum\util.py", line 376, in run
    self.mem_stats()
  File "...\electrum\util.py", line 368, in mem_stats
    if isinstance(obj, class_):
  File "...\Python310\lib\abc.py", line 119, in __instancecheck__
    return _abc_instancecheck(cls, instance)
  File "...\electrum\simple_config.py", line 609, in __getattribute__
    raise AttributeError()
AttributeError
```
2025-08-23 14:51:01 +00:00
SomberNight
8d8d1dba0f util.format_satoshis: floating-point paranoia 2025-08-22 13:30:26 +00:00
SomberNight
74cd2b4ac3 commands: use format_satoshis consistently. don't use sci-notation
old behaviour:
```
>>> from electrum.commands import format_satoshis
>>> format_satoshis(1)
'1E-8'
```
2025-08-21 17:38:27 +00:00
SomberNight
f8926b4957 type-hint some Callables
could not figure out how to type-hint coinchooser.sufficient_funds with typing.Protocol,
at least PyCharm complained on all my attempts
2025-08-18 15:38:25 +00:00
SomberNight
d7c76b991b commands: add back from_height/to_height params to onchain_history
closes https://github.com/spesmilo/electrum/issues/10119

also:
- wallet.get_onchain_history was broken with from_height/to_height args
- "show_fees" param is and was non-existent. fees are always added to output
- MyEncoder(json.JSONEncoder) changed a bit:
  - I am pretty sure cutting the last 3 chars was intended to cut off the seconds
  - however that was making incorrect assumptions about what datetime.isoformat() returns
    - which depends on whether microsecond precision is available or whether an explicit timezone is set
  - this now makes it clear that we want minutes-resolution, but still leaves the timezone-ambiguity
2025-08-13 15:09:04 +00:00
SomberNight
b16760b861 jsonpatch exception-mangling: more robust against secrets in dict keys 2025-07-14 12:53:56 +00:00
SomberNight
4887fb3e7f util.with_lock: add support for chaining with @event_listener
Consider e.g.:
```
class AddressSynchronizer(Logger, EventListener):
[... snip ...]
    @event_listener
    @with_lock
    def on_event_blockchain_updated(self, *args):
        self._get_balance_cache = {}  # invalidate cache
        self.db.put('stored_height', self.get_local_height())
```

was raising:
```
func.__qualname__='with_lock.<locals>.func_wrapper'
Traceback (most recent call last):
  File "...\electrum\run_electrum", line 105, in <module>
    from electrum.logging import get_logger, configure_logging  # import logging submodule first
  File "...\electrum\electrum\__init__.py", line 19, in <module>
    from .wallet import Wallet
  File "...\electrum\electrum\wallet.py", line 70, in <module>
    from .address_synchronizer import (
  File "...\electrum\electrum\address_synchronizer.py", line 75, in <module>
    class AddressSynchronizer(Logger, EventListener):
  File "...\electrum\electrum\address_synchronizer.py", line 205, in AddressSynchronizer
    def on_event_blockchain_updated(self, *args):
  File "...\electrum\electrum\util.py", line 2005, in event_listener
    classname, method_name = func.__qualname__.split('.')
ValueError: too many values to unpack (expected 2)
```
2025-06-15 19:06:10 +00:00
Sander van Grieken
3c9c6a286c imports, whitespace, type hints, copyright headers 2025-06-12 14:32:00 +02:00
ThomasV
5610a94537 fix #9856 2025-06-06 12:17:21 +02:00
ThomasV
853b793bef rm verbosity_shortcuts option (unused, redundant) 2025-05-29 16:20:41 +02:00
SomberNight
f95d4ce287 util.profiler: add support for async functions 2025-05-23 16:18:59 +00:00
SomberNight
5084f75724 util.make_dir: handle multi-process race
When launching an electrum daemon and an electrum cli command quickly after each other,
in a test using a random fresh datadir, they both try to create the same folder hierarchy
and race on the "if not exist: mkdir" commands.
2025-05-23 15:49:11 +00:00
Sander van Grieken
84322500ef lnworker: imports, formatting, whitespace 2025-05-23 14:00:57 +02:00
f321x
f7ad95f42d make lightning dns seed fetching async 2025-05-16 17:10:10 +02:00
SomberNight
ba3783f998 refactor qt.util.ChoiceWidget: introduce ChoiceItem 2025-05-06 18:12:37 +00:00
f321x
ee7d2ee17d validate and deduplicate relay config input in qt gui
Adds validation and deduplication of the relay urls entered in the QT
settings dialog. This is supposed to prevent malformed or duplicated
relay entries.
Also resets the relays to the default value if no (valid) url
is entered. This prevents the user from getting stuck without relays
(otherwise the user would have to research for relay urls manually if
they don't know any).
2025-05-02 09:03:27 +02:00
ThomasV
8bb94dd57d follow-up previous commit 2025-04-22 09:41:17 +02:00
ThomasV
69f8176aab Qt: show relative locktime in tx details 2025-04-22 09:30:53 +02:00
f321x
253ab6849a implement NIP47 plugin 2025-04-10 10:22:29 +02:00
SomberNight
220e6a1ef9 Merge branch 'pr/9717': re asyncio.Event.set() race conditions
see https://github.com/spesmilo/electrum/pull/9717
plus local follow-up clean-up
2025-04-08 19:56:38 +00:00
SomberNight
4b9d874d13 util: add fn run_sync_function_on_asyncio_thread
note: the return value is not propagated out.
It would be trivial to do that for the block=True case - but what about block=False?
2025-04-08 19:53:49 +00:00
SomberNight
70d1e1170e asyncio: clarify strong refs for run_coroutine_threadsafe
We added some code in 0b3a283586
to explicitly hold strong refs for all tasks/futures. At the time I was uncertain if that also solves
GC issues with asyncio.run_coroutine_threadsafe.
ref https://github.com/spesmilo/electrum/pull/9608#issuecomment-2703681663

Looks like it does. run_coroutine_threadsafe *is* going through the custom task factory.
See the unit test.
The somewhat confusing thing is that we need a few event loop iterations for the task factory to run,
due to how run_coroutine_threadsafe is implemented. And also, the task that we will hold as strong ref
in the global set is not the concurrent.futures.Future that run_coroutine_threadsafe returns.

So this commit simply "fixes" the unit test so that it showcases this, and removes related, older, plumbing
from util.py that we now know is no longer needed because of this.
2025-04-08 18:54:58 +00:00
SomberNight
5c233ac325 ci: enable more flake8 stuff
```
$ export ELECTRUM_LINTERS=E9,E101,E129,E273,E274,E703,E71,E722,F5,F6,F7,F8,W191,W29,B
$ export ELECTRUM_LINTERS_IGNORE=B007,B009,B010,B019,B036,F541,F841
$ flake8 . --count --select="$ELECTRUM_LINTERS" --ignore="$ELECTRUM_LINTERS_IGNORE" --show-source --statistics --exclude "*_pb2.py,electrum/_vendor/"
./electrum/commands.py:98:1: F811 redefinition of unused 'format_satoshis' from line 48
def format_satoshis(x):
^
./electrum/commands.py:437:9: F811 redefinition of unused 'Mnemonic' from line 62
        from .mnemonic import Mnemonic
        ^
./electrum/gui/qt/wizard/wallet.py:37:5: F811 redefinition of unused 'Daemon' from line 14
    from electrum.daemon import Daemon
    ^
./electrum/lntransport.py:14:1: F811 redefinition of unused 'Optional' from line 12
from typing import NamedTuple, List, Tuple, Mapping, Optional, TYPE_CHECKING, Union, Dict, Set, Sequence
^
./electrum/lntransport.py:14:1: F811 redefinition of unused 'TYPE_CHECKING' from line 12
from typing import NamedTuple, List, Tuple, Mapping, Optional, TYPE_CHECKING, Union, Dict, Set, Sequence
^
./electrum/plugin.py:966:13: F811 redefinition of unused 'hid' from line 593
            import hid
            ^
./electrum/plugin.py:1040:13: F811 redefinition of unused 'hid' from line 593
            import hid
            ^
./electrum/util.py:44:1: F811 redefinition of unused 'json' from line 26
import json
^
./electrum/util.py:46:1: F811 redefinition of unused 'NamedTuple' from line 29
from typing import NamedTuple, Optional
^
./electrum/util.py:46:1: F811 redefinition of unused 'Optional' from line 29
from typing import NamedTuple, Optional
^
./electrum/util.py:1456:56: F811 redefinition of unused 'traceback' from line 34
        async def __aexit__(self, exc_type, exc_value, traceback):
                                                       ^
./electrum/wallet_db.py:536:9: F811 redefinition of unused 'LOCAL' from line 46
        LOCAL = 1
        ^
./electrum/wallet_db.py:537:9: F811 redefinition of unused 'REMOTE' from line 46
        REMOTE = -1
        ^
./tests/test_bitcoin.py:28:1: F811 redefinition of unused 'bitcoin' from line 9
from electrum import crypto, constants, bitcoin
^
./tests/test_txbatcher.py:11:1: F811 redefinition of unused 'Transaction' from line 7
from electrum.transaction import Transaction, PartialTxInput, PartialTxOutput, TxOutpoint
^
./tests/test_wallet_vertical.py:20:1: F811 redefinition of unused 'Transaction' from line 10
from electrum.transaction import Transaction, PartialTxOutput, tx_from_any, Sighash
^
16    F811 redefinition of unused 'format_satoshis' from line 48
16

```
2025-04-02 16:21:59 +00:00
f321x
2290650faa pass proxy settings to aionostr Manager
rebase on master
2025-03-10 10:57:30 +01:00
SomberNight
0b3a283586 asyncio: hold our own strong refs for tasks and futures
see https://docs.python.org/3.13/library/asyncio-task.html#asyncio.create_task :

> Important
>
> Save a reference to the result of this function, to avoid a task
> disappearing mid-execution. The event loop only keeps weak references
> to tasks. A task that isn’t referenced elsewhere may get garbage
> collected at any time, even before it’s done. For reliable
> “fire-and-forget” background tasks, gather them in a collection

ref https://github.com/python/cpython/issues/91887
ref https://github.com/beeware/toga/pull/2814
2025-03-05 17:06:04 +00:00
SomberNight
5dc2ae243e util: refactor Tor-detection to be async
- on my PC, with Tor Browser running (socks proxy on port 9150), detect_tor_socks_proxy took ~4.01 seconds
- this was because we probed port 9050, 2 sec timeout, 9051, 2 sec timeout, 9150, ~few ms to succeed
- instead we now probe all ports concurrently
2025-03-05 14:46:47 +00:00
Sander van Grieken
fea598cfbe network: create ProxySettings class replacing dict and encapsulating proxy related funcs,
allow enable/disable proxy without nuking proxy mode, host and port (explicit enable_proxy config setting),
move tor probe from frontend to backend code, add probe buttons for Qt and QML
2025-03-04 14:23:33 +01:00
ThomasV
392c219913 simplify history-related commands:
- reduce number of methods
 - use nametuples instead of dicts
 - only two types: OnchainHistoryItem and LightningHistoryItem
 - channel open/closes are groups
 - move capital gains into separate RPC
2025-02-19 11:40:21 +01:00
f321x
a47421490d increase nonce size to 32 byte and make it hex in event 2025-02-12 10:09:11 +01:00
f321x
947094c1b0 add pow, more default relays, new event type 2025-02-11 18:16:15 +01:00
SomberNight
be2cd02e54 some clean-ups now that we require python 3.10 2025-01-10 18:52:53 +00:00
bitromortac
ea584e13fc anchors: switch to zero-fee-htlcs
* sets the weight of htlc transactions to zero, thereby putting a zero
  fee for the htlc transactions
* add inputs to htlc-tx for fee bumping
* switches feature flags
* disable anchor test vectors, which are now partially invalid
2024-11-25 10:56:50 +01:00
WakiyamaP
3d375116e9 add testnet4 explorer(wakiyamap.dev) 2024-11-11 11:55:04 +09:00
accumulator
1b9f1dbb7f Merge pull request #9250 from accumulator/network_tor_stream_isolation
network: use TOR stream isolation
2024-10-28 09:50:00 +01:00
SomberNight
5c81f77b5d util: add docstring to EventListener 2024-10-25 16:58:47 +00:00
Sander van Grieken
f4520b9e0d network: use TOR stream isolation
also refactor, for proxy instantiation, use Network instance, not a proxy dict.
2024-10-25 01:10:58 +02:00
wakiyamap
1d9ff40d0b Add suport testnet4 2024-09-14 03:52:03 +09:00
SomberNight
bec78b4210 util.error_text_str_to_safe_str: truncate long errors
The messages are sometimes logged and sometimes shown to the user,
- for logging we might not want to truncate or have higher limits,
- but when shown to the user, we definitely want to truncate the error text.
It is simplest to just do the truncation here, at the lowest level.

Note that we usually prepend the error text with a header e.g. "[DO NOT TRUST THIS MESSAGE]"
and if the error text is too long, this header at the beginning might get "lost" in some way.
Hence we should truncate the error text.
2024-06-17 16:52:13 +00:00
SomberNight
13e2949088 rm some legacy cruft for old python versions 2024-06-05 14:55:48 +00:00
SomberNight
0866581b2c daemon error-handling: fix traceback.format_exception() on old python
The new API for traceback.format_exception was only added in python 3.10 (91e93794d5).
2024-06-05 14:45:28 +00:00
SomberNight
af2c9b081c util: add AsyncHangDetector, and use it for lnpeer._process_message 2024-06-03 18:36:08 +00:00