1
0
Commit Graph

128 Commits

Author SHA1 Message Date
SomberNight
c463f5e23d password unification refactor: move methods from wallet to daemon
Note in particular that check_password_for_directory was not safe to use while the daemon had wallets loaded,
as the same file would have two corresponding Wallet() instances in memory. This was specifically handled in
the kivy GUI, on the caller side, by stopping-before and reloading-after the wallets; but it was dirty to
have the caller handle this.
2022-07-06 19:57:27 +02:00
SomberNight
c09903be68 daemon.PayServer.create_request: mark as broken...
looks like it's been broken for a long time.
- self.root ??
- lnworker.add_request API change
2022-06-22 02:46:22 +02:00
SomberNight
5b000a871f EventListener follow-ups: adapt left-out classes and minor clean-ups 2022-06-22 02:09:26 +02:00
SomberNight
641c3e23a4 daemon: default rpc socktype to "tcp" if rpcport is set
Having `rpcport` set already indicates the user does not want unix sockets,
we just default `rpchost` to "localhost".

related https://github.com/spesmilo/electrum/issues/7811
2022-05-13 16:19:28 +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
SomberNight
419fc6e1c1 gui init: raise GuiImportError instead of sys.exit if dep is missing 2022-04-11 17:40:16 +02:00
Federico
f42ae3f01c fix rpcsock (#7691)
some heuristics re default rpcsock type: if tcp-related other config keys are set, use tcp

closes https://github.com/spesmilo/electrum/issues/7686
2022-03-02 11:42:49 +00:00
sgmoore
3f20215d03 trivial: minor grammar fixes
closes https://github.com/spesmilo/electrum/pull/7664
closes https://github.com/spesmilo/electrum/pull/7665
closes https://github.com/spesmilo/electrum/pull/7666
closes https://github.com/spesmilo/electrum/pull/7667
2022-02-17 15:36:13 +01:00
ghost43
3e486b029c Merge pull request #7566 from SomberNight/202111_rpcsock_unix_default
daemon: change `rpcsock` default to "unix" where available
2022-02-16 14:50:29 +00:00
SomberNight
c9c094cfab requirements: bump min aiorpcx to 0.22.0
aiorpcx 0.20 changed the behaviour/API of TaskGroups.
When used as a context manager, TaskGroups no longer propagate
exceptions raised by their tasks. Instead, the calling code has
to explicitly check the results of tasks and decide whether to re-raise
any exceptions.
This is a significant change, and so this commit introduces "OldTaskGroup",
which should behave as the TaskGroup class of old aiorpcx. All existing
usages of TaskGroup are replaced with OldTaskGroup.

closes https://github.com/spesmilo/electrum/issues/7446
2022-02-15 18:22:44 +01:00
SomberNight
3f3212e94d some clean-ups now that we require python 3.8
In particular, asyncio.CancelledError no longer inherits Exception (it inherits BaseException directly)
2022-02-15 18:22:36 +01:00
SomberNight
12b659ff99 daemon: change rpcsock default to "unix" where available
The daemon by default listens for RPC over a socket.
Before this change, this socket was a TCP/IP network socket (over localhost),
but now we change it to be a unix domain socket by default (if available).

This socket is used not only when sending commands over JSON-RPC,
but also when using the CLI, and to a tiny extent even used when running the GUI.
The type of socket used (and hence this change) is invisible to CLI and GUI users.
JSON-RPC users might want to use either the --rpcsock CLI flag
or set the "rpcsock" config key (to "tcp") to switch back to using a TCP/IP socket.

In practice it seems unix domain sockets are available on
all mainstream OSes/platforms, except for Windows.

closes https://github.com/spesmilo/electrum/issues/7553
2021-11-15 17:44:20 +01:00
SomberNight
62e1d8ed78 daemon: (trivial) subservices log when they start listening 2021-11-15 17:43:34 +01:00
SomberNight
88a1c1a618 python 3.10: fix some deprecation warnings and compat with 3.10 2021-11-09 01:02:57 +01:00
SomberNight
ca9b48e2d6 gui: add BaseElectrumGui base class for guis 2021-11-05 20:21:50 +01:00
SomberNight
c331c311db crash reporter: add EarlyExceptionsQueue
`util.send_exception_to_crash_reporter` is now useful and can be transparently
used even before the exception hook is set up.
2021-11-05 20:01:43 +01:00
SomberNight
e0246b30b9 daemon: if taskgroup dies, show error in GUI
If daemon.taskgroup dies
- in GUI mode, show a crash reporter window to the user,
  instead of immediately stopping the whole process.
- in daemon mode, log exception and stop process, as before.
2021-11-05 20:01:38 +01:00
SomberNight
3643b9f056 daemon: rework stopping
The CLI stop() command can now also stop the GUI.
2021-11-05 19:57:39 +01:00
yanmaani
b1005694ec cli: Add support for Unix domain sockets 2021-11-03 12:00:00 +00:00
bitromortac
ff61020dd2 watchtower: watch new channels 2021-09-27 10:31:44 +02:00
MrNaif2018
c35a46a727 Don't cleanup lockfile is listen_jsonrpc is False 2021-07-07 16:57:09 +03:00
SomberNight
66f68d6b1f commands: fix "close_wallet" cmd, which was deadlocking
fixes #7348
2021-06-17 12:35:31 +02:00
SomberNight
3ea27beb4e daemon: change stop() to use events, instead of polling 2021-03-17 19:42:20 +01:00
SomberNight
5dfe1d1b6c commands: make stop() CLI cmd wait for daemon to stop 2021-03-17 19:42:16 +01:00
SomberNight
de6f5a8e03 {daemon,wallet}|.stop: small clean-up 2021-03-10 18:07:15 +01:00
SomberNight
3c019c2f9c daemon/wallet/network: make stop() methods async 2021-03-09 17:52:36 +01:00
ThomasV
ded449233e Trampoline routing.
- trampoline is enabled by default in config, to prevent download of `gossip_db`.
   (if disabled, `gossip_db` will be downloaded, regardless of the existence of channels)
 - if trampoline is enabled:
    - the wallet can only open channels with trampoline nodes
    - already-existing channels with non-trampoline nodes are frozen for sending.
 - there are two types of trampoline payments: legacy and end-to-end (e2e).
 - we decide to perform legacy or e2e based on the invoice:
    - we use trampoline_routing_opt in features to detect Eclair and Phoenix invoices
    - we use trampoline_routing_hints to detect Electrum invoices
 - when trying a legacy payment, we add a second trampoline to the path to preserve privacy.
   (we fall back to a single trampoline if the payment fails for all trampolines)
 - the trampoline list is hardcoded, it will remain so until `trampoline_routing_opt` feature flag is in INIT.
 - there are currently only two nodes in the hardcoded list, it would be nice to have more.
 - similar to Phoenix, we find the fee/cltv by trial-and-error.
    - if there is a second trampoline in the path, we use the same fee for both.
    - the final spec should add fee info in error messages, so we will be able to fine-tune fees
2021-02-17 17:28:13 +01:00
ThomasV
43c5df2ab5 Setconfig: set rpc_user rpc_password in daemon (fix #6762).
Do not disable auth if password is an empty string.
2020-11-25 11:47:30 +01:00
ThomasV
0b183444b4 Rename maybe_init_lightning(). Call load_data() from there 2020-11-20 08:35:57 +01:00
SomberNight
ec0f91942d daemon: fix local RPC server error messages to conform to jsonrpc spec
fixes #6672
2020-11-14 19:59:59 +01:00
bitromortac
4efcb53d24 network: load gossip db early
The gossip db is loaded early when the network is started to save
time when the gui is locked and a wallet not yet loaded. Side effects
of the LNWallet to start peering when a channel db is loaded is
circumvented.
2020-10-22 18:05:51 +02:00
SomberNight
83e61d6743 cli: allow specifying --wallet at any arg position, as before
Before commit 46ffab0b55 all of these used to work:
./run_electrum -o signmessage tb1qeh090ruc3cs5hry90tev4fsvrnegulw8xssdzx "asdasd" -w ~/.electrum/testnet/wallets/test_segwit_2 --testnet
./run_electrum -o signmessage -w ~/.electrum/testnet/wallets/test_segwit_2 tb1qeh090ruc3cs5hry90tev4fsvrnegulw8xssdzx "asdasd" --testnet
./run_electrum -w ~/.electrum/testnet/wallets/test_segwit_2 -o signmessage tb1qeh090ruc3cs5hry90tev4fsvrnegulw8xssdzx "asdasd" --testnet
Since then, the last one no longer works.

Related: 9d2ede8796
2020-10-05 18:02:37 +02:00
SomberNight
a81b0ecc59 daemon/rpc: include "jsonrpc" key in rpc responses
fixes #6612
2020-09-23 21:39:31 +02:00
MrNaif2018
6bd1a04aee Pass wallet to invoice_status/request_status (#6595)
* Pass wallet to invoice_status/request_status

* Check for same wallet in qt gui

Co-authored-by: ghost43 <somber.night@protonmail.com>
2020-09-18 17:28:51 +00:00
SomberNight
a32cb7784f myAiohttpClient: add id counter, and rename to JsonRPCClient 2020-06-09 17:50:06 +02:00
SomberNight
50f705ee46 fix json-rpc interface (when not using CLI) 2020-06-09 17:45:04 +02:00
ThomasV
30f5be26ac Remove dependencies: jsonrpcserver, jsonrpcclient 2020-06-09 11:26:39 +02:00
ThomasV
cfdfbd2bfe follow-up 6058829870 2020-06-02 16:32:07 +02:00
ThomasV
6058829870 Use attr.s classes for invoices and requests:
- storage upgrade
 - fixes #6192
 - add can_pay_invoice, can_receive_invoice to lnworker
2020-06-01 21:02:45 +02:00
SomberNight
9baaf1afda commands: make 'wallet'-mangling in decorator less obscure, and fixes
- some commands expect a 'wallet_path' arg, while others expect 'wallet'
- 'wallet_path' in the end is supposed to be a str,
  'wallet' in the end is supposed to be an Optional[Abstract_Wallet]
- initially, in the decorator, 'wallet' can be a str, in which case
  the decorator replaces it with an Abstract_Wallet (from the daemon)
- Previously the decorator sometimes converted 'wallet_path' to 'wallet'.
  This was because when called from the CLI it was always given 'wallet_path' (and never 'wallet),
  while when called from JSON-RPC it was given either 'wallet' or 'wallet_path' (depending on command).
  Now, the CLI also behaves as JSON-RPC, and hence 'wallet_path' and 'wallet' are fully separate.
- A bug is fixed where, when a command that only optionally takes a 'wallet' (such as gettransaction),
  was called from the JSON-RPC with the arg present, it raised; and when called from CLI with the arg present
  the arg was not actually passed to the command.
- A bug is fixed where if one command calls another command (that both take a 'wallet'),
  it would raise (due to assuming 'wallet' is str and needs to be converted to Abstract_Wallet).
  This fixes #6154.

-----

$ ./run_electrum --testnet daemon -d
$ ./run_electrum --testnet load_wallet -w ~/.electrum/testnet/wallets/default_wallet

$ curl --data-binary '{"id":"curltext","jsonrpc":"2.0","method":"gettransaction","params":{"txid":"9f43ff71ea2594873e4e7d15e61254a3661ff2df1af76325c854d9aa199550ce"}}' http://user:pass@127.0.0.1:7777
{"jsonrpc": "2.0", "result": "0200000001caaac6b5eb916e3067d0224f942fb331ce1dcfb4031cfb479e7941dcf95e409801000000fdfe0000483045022100e2a508bb78c2172eb03f081a342454ba1d24669e959700973b1a742a4fedd0c302203174e06feda265031cf9aa0364d4a4eafb71b0c0a62e76be7795cfbb307b677a01483045022100d0e14564838fac754395158741d64c73da2b86e7900dfdc6a63c7492b232ba130220778e7e7c21d94ebcd340057302aeff7e9a797a3aa3e0ac4884e9ff27339ea6e9014c69522102091f0b4d8ab30016a5d1c088249e02883fad8160f06fa53588ad8598650a3e6221035f2f8263bb3608d6cc4ee03bd4cb8d65c4d70af71049f05fbfee4978832a1fd22103fe42dab58718ea0413f7c8de693cdeee22ce19b1dc34c0bbdd7a48245465c5a253aefdffffff01cb9f0700000000001976a914c13fd6294d1be7b9410a5538f4b4ef10fc594ee788ac802c1800", "id": "curltext"}

$ curl --data-binary '{"id":"curltext","jsonrpc":"2.0","method":"gettransaction","params":{"txid":"9f43ff71ea2594873e4e7d15e61254a3661ff2df1af76325c854d9aa199550ce", "wallet":"~/.electrum/testnet/wallets/default_wallet"}}' http://user:pass@127.0.0.1:7777
{"jsonrpc": "2.0", "error": {"code": -32000, "message": "'str' object has no attribute 'db'"}, "id": "curltext"}
2020-05-14 16:33:02 +02:00
ThomasV
d3fb68575d daemon.py: Add authentication to Watchtower.
Define abstract class AuthenticatedServer
2020-05-12 10:12:30 +02:00
ThomasV
e2c2c89988 follow-up prev 2020-05-10 22:11:09 +02:00
ThomasV
13317c2f51 fix callback name: request_status 2020-05-10 21:14:31 +02:00
ThomasV
87facaa781 payserver: do not allow create_invoice by default 2020-05-10 17:07:19 +02:00
ThomasV
11aaa0b66f Simplify services (watchtower, payserver):
- Do not expose services settings in GUI
 - Use a single netaddress configuration variable.
2020-05-10 14:52:50 +02:00
ThomasV
085b6ca2ab jsonrpc: pass timeout to aiohttp session 2020-05-02 17:25:30 +02:00
SomberNight
0ee73378c9 daemon: rm "daemon.wallet" reference
related: #4905 -- when closing a wallet, it can get gc-ed now

TODO: PayServer needs to choose wallet somehow
2020-05-01 06:56:21 +02:00
SomberNight
2b1a150c52 multi-wallet: properly stop lnworker/lnwatcher 2020-05-01 04:50:08 +02:00
SomberNight
47ab8f8dc5 daemon.on_stop: adapt to python 3.8
(py3.8 has breaking changes re asyncio.CancelledError and asyncio.TimeoutError)

follow-up 308517d473
2020-04-15 19:34:52 +02:00
SomberNight
cf1f2ba4dc network: replace "server" strings with ServerAddr objects 2020-04-15 17:23:47 +02:00