Commit Graph

201 Commits

Author SHA1 Message Date
SomberNight
60792dc808 network: fix not retrying main interface in some cases
This was a regression from e83f0dd3fc,
introduced by the change in connection_down() there.
(if the initial connection to the main interface is not successful, the
network status will not be set to 'disconnected' - but it should be)
That change is now reverted here.
That change was somewhat independent of the rest of that commit,
except the rest highlighted that something of the sort was needed:
as it might sometimes take many seconds for an interface to close
and we might launch another interface for the same server while the
first one is still closing, the "server == self.default_server" test
is highly problematic.
To fix this second - original - issue, we now introduce a "closing" state
for interfaces (in the form of network._closing_ifaces).
2021-01-21 04:02:11 +01:00
SomberNight
b1449a0a39 interface.got_disconnected: change from Future to Event
Events are far easier to reason about.
2021-01-21 03:11:15 +01:00
ThomasV
ad91257729 pass blacklist to lnrouter.find_route, so that lnrouter is stateless (see #6778) 2021-01-11 15:19:50 +01:00
SomberNight
e83f0dd3fc network: when switching servers, don't wait for old interface to close
The GUI blocks until network.set_parameters returns when switching servers,
which waits for switch_to_interface, which used to wait until interface.close()
returns. interface.close() tries to flush buffered writes to the wire, with a
30 sec timeout.

If the server or the network connection is slow, flushing the buffer can take
several seconds. In particular, servers running Fulcrum always seem to
timeout in this case, freezing the GUI for 30 seconds (when switching away).
2020-12-13 18:08:36 +01:00
SomberNight
dbb7d7ce4d network: set _loop_thread again as it helps debugging
related: #6825
2020-12-08 11:48:01 +01:00
ThomasV
0b183444b4 Rename maybe_init_lightning(). Call load_data() from there 2020-11-20 08:35:57 +01:00
ThomasV
f155f3aff5 start lngossip if instantiated; this saves a boolean 2020-10-22 18:48:27 +02: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
bitromortac
6045de759b lightning: enable by default but without gossip
Enables lightning by creating a node private key and storing it in
the wallet. The gossiper is not launched at start up, only if there
are existing channels.
2020-10-22 18:05:51 +02:00
SomberNight
c5da22a9dd network: tighten checks of server responses for type/sanity 2020-10-16 19:30:42 +02:00
SomberNight
bde415cae7 wallet: don't try to get_input_tx from network when offline
related: https://github.com/spesmilo/electrum/issues/6648#issuecomment-708499893

Trying to fetch the prev tx from the network is a blocking operation with
a 10 sec timeout - we should not hang for 10 seconds if there is no network connection.
2020-10-14 19:30:10 +02:00
SomberNight
d19ff43266 interface: check server response for some methods
some basic sanity checks

Previously if the server sent back a malformed response, it could partially corrupt a wallet file.
(as sometimes the response would get persisted, and issues would only arise later when the values were used)
2020-07-02 15:41:39 +02:00
SomberNight
2eec7e1600 network: smarter switch_unwanted_fork_interface
Previously this function would not switch to a different chain if the
current chain contained the preferred block. This was not the intended
behaviour: if there is a *stronger* chain that *also* contains the
preferred block, we should jump to that.

Note that with this commit there will now always be a preferred block
(defaults to genesis). Previously, it might seem that often there was none,
but actually in practice if the user used the GUI context menu to switch
servers even once, there was one (usually genesis).

Hence, with the old code, if an attacker mined a single header which
then got reorged, auto_connect clients which were connected to the
attacker's server would never switch servers (jump chains) even
without the user explicitly configuring preference for the stale branch.
2020-06-21 11:31:54 +02:00
SomberNight
3766420a0b network: clarify local_height/server_height 2020-06-21 08:20:56 +02:00
SomberNight
21e637f543 network: validate server peers sent by main server
Data returned by the main server for request "server.peers.subscribe"
is of course untrusted input. Previously if it contained e.g. invalid port numbers
or IP addresses, it could kill the whole network taskgroup.
(this might have only affected master and not released versions,
which would only raise exceptions once the client actually tried to connect to an invalid host/port)
2020-05-13 19:28:35 +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
SomberNight
9ac41be1e8 network: set .oneserver in __init__
fixes #6135
2020-05-01 03:27:31 +02:00
Luke Childs
cd199390e2 Use non-standard localhost port for server-string fallback (#6087)
* Use non-standard localhost port for server-string fallback

Co-authored-by: Luke Childs <lukechilds123@gmail.com>
2020-04-16 19:39:05 +00:00
SomberNight
9e57ae630b network/gui: unify host/port input fields to single server str
This allows optionally specifying the protocol for the main server.

fixes #6095
fixes #5278
2020-04-16 21:19:48 +02:00
SomberNight
b2cfaddff2 network.NetworkParameters: merge host+port+protocol into "server" field 2020-04-16 21:19:45 +02:00
SomberNight
adc3784bc2 network: allow mixed protocols among interfaces
Previously all the interfaces used either "t" or "s".
Now the network only tries to use "s" for all interfaces, except for
the main interface, which the user can manually specify to use "t".
(so e.g. if you run with "--server localhost:50002:t", the main server will use "t",
but all the rest will use "s")
2020-04-16 21:19:42 +02:00
SomberNight
76f0ad3271 util: add NetworkRetryManager, a baseclass for LNWorker and Network 2020-04-15 17:24:07 +02:00
SomberNight
86b29603cb network: (trivial) rename field to indicate private 2020-04-15 17:24:00 +02:00
SomberNight
ac749f3a19 network: introduce NUM_STICKY_SERVERS 2020-04-15 17:23:57 +02:00
SomberNight
34e3e48ba5 network: rm server_queue
it's no longer needed; now it was just an extra level of indirection
2020-04-15 17:23:54 +02:00
SomberNight
8baa79be88 network: implement exponential backoff for retries 2020-04-15 17:23:50 +02:00
SomberNight
cf1f2ba4dc network: replace "server" strings with ServerAddr objects 2020-04-15 17:23:47 +02:00
ThomasV
9224404108 Move callback manager out of Network class 2020-04-14 18:29:51 +02:00
Luke Childs
1d667fe932 Hard fail on bad server-string (#6086)
* If server-string can't be parsed, fall back to localhost.

Co-Authored-By: Luke Childs <lukechilds123@gmail.com>

Co-authored-by: ghost43 <somber.night@protonmail.com>
2020-04-14 12:15:28 +00:00
SomberNight
8be94076b5 network: update tx broadcast error msgs whitelist
fixes #6052
2020-03-31 07:08:31 +02:00
SomberNight
a7c02c770d follow-up prev: network.interface might be None 2020-03-13 18:07:05 +01:00
ThomasV
133d74adfb fee estimates: use median if auto-connect 2020-03-12 15:39:50 +01:00
ThomasV
0d160cceea Qt: test if lightinng is running 2020-03-06 11:23:26 +01:00
SomberNight
88650ed8d6 network UntrustedServerReturnedError: add "DO NOT TRUST..." tag 2020-02-28 18:47:12 +01:00
SomberNight
ce81957d25 blockchain: move init_headers_file from network.py to blockchain.py
and don't run it every time the network restarts
2020-02-27 20:45:29 +01:00
SomberNight
b21bcf5977 taskgroups: don't log CancelledError 2020-02-27 20:22:49 +01:00
SomberNight
ed234d3444 rename all TaskGroup() fields to "taskgroup"
for consistency
2020-02-27 19:13:56 +01:00
ThomasV
36f32651cc Define network.try_broadcasting() method.
Use it when rebroadcasting a force-close tx,
because the channel state is already set.
2020-02-16 12:59:09 +01:00
ThomasV
cded582fe9 Start watchtower if run_watchtower is set, even if lightning is not activated (fix #5896).
Fix parameters of sweepstore.add_sweep_tx, rm dead code.
2020-02-02 12:10:10 +01:00
SomberNight
11452722af network dns hacks: split from network.py into its own file 2020-01-22 18:32:57 +00:00
SomberNight
cb88a3b6e4 dns hacks on windows: resolve A and AAAA records in parallel 2020-01-22 18:32:57 +00:00
SomberNight
0b0139c676 network.get_transaction: move some response validation logic from Synchronizer 2020-01-09 19:23:28 +01:00
SomberNight
37747d7469 split network main_taskgroup: create daemon.taskgroup
network.main_taskgroup restarts every time the proxy settings are changed,
many long-running tasks (some introduced with lightning) are not prepared for and do not want this.
2020-01-09 19:23:21 +01:00
SomberNight
6709ec4117 dns hacks on windows: cache dns when using dnspython
related #4421
related #5337
2020-01-01 06:23:51 +01:00
SomberNight
308517d473 python 3.8: adapt to breaking changes re asyncio.CancelledError
(and TimeoutError)

closes #5798
2019-12-11 23:07:47 +01:00
SomberNight
68dad21fb4 network: make best_effort_reliable smarter and a bit more lenient
related: #5815
2019-12-01 23:24:43 +01:00
SomberNight
bafe8a2fff integrate PSBT support natively. WIP 2019-11-04 22:24:36 +01:00
ThomasV
90ce9f195b Allow user to enable lightning in the GUI. Make it a per-wallet setting. 2019-10-13 20:34:38 +02:00
SomberNight
8c1adc2f50 fix dns issue on Windows
closes #5638
2019-09-18 19:11:40 +02:00
SomberNight
b2920db8b8 config: enforce that SimpleConfig is singleton
related: #5629
2019-09-10 18:01:10 +02:00