Commit Graph

610 Commits

Author SHA1 Message Date
SomberNight
556b98736e lnworker.try_force_closing: changed to not be async (and renamed)
This is to ensure that the channel is "immediately" set to FORCE_CLOSING.
(previously it took at least one event loop iteration)
2022-02-21 18:09:45 +01:00
ThomasV
b268877d53 Merge pull request #7636 from bitromortac/2201-channel-type
lightning: implement channel types
2022-02-21 12:08:54 +01:00
ThomasV
4ebe41b3a7 Trampoline MPP: save fee level in sent_htlcs_info.
If multiple HTLCs fail at the same fee level with
TRAMPOLINE_INSUFFICIENT_FEE, bump trampoline_fee_level only once.
2022-02-19 15:20:54 +01:00
ThomasV
9fd18ae7f4 Merge pull request #7623 from bitromortac/2201-multi-trampoline-mpp
Multi-trampoline multipart payments
2022-02-19 14:44:21 +01:00
ThomasV
b2f84187bc Split code in reestablish_channel:
Messages are sent in reestablish_channel (async)
  Message checks and force_close are performed in on_channel_reestablish (not async).
  That task should not be cancelled if the connection is closed.
  Revert 57583c05cf
2022-02-19 10:37:50 +01:00
SomberNight
96fcf68d84 lnworker.force_close_channel: set chan state before broadcast
It is not safe to keep using the channel after we attempted to broadcast a force-close,
even if the broadcast errored: the server cannot be trusted wrt to errors.

Note that if there is a network-error, due to the state-transition, the GUI won't offer
the force-close option to the user again. However, LNWallet will periodically rebroadcast
the tx automatically (in on_channel_update); and we also save the tx as local into the
wallet.
2022-02-18 17:20:30 +01:00
bitromortac
a4f5cfc91a trampoline: refactor routes, enable e2e mpp
* Refactor `create_trampoline_route`.
* Enables end-to-end multi-trampoline multipart payments.
  Trampoline-to-legacy payments are still not enabled, as this is
  currently not supported by Eclair.
* Reverts to a global trampoline fee level, as trampoline failures
  are currently not handled properly, see (#7648), which doubles
  fee rates.
2022-02-18 10:14:51 +01:00
ThomasV
57583c05cf request_force_close: add 1s delay before closing the tranport,
so that the remote task does not get cancelled.
2022-02-16 18:54:42 +01: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
c131831373 util: rm SilentTaskGroup. this does not seem to be needed anymore
I think this was originally needed due to incorrect management of group lifecycles,
which our current code is doing better.

also note that if we needed this, in newer aiorpcx, the name of
the field was ~changed from `_closed` to `joined`:
239002689a
2022-02-15 18:22:40 +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
bitromortac
6915e3cb10 lnpeer+wallet: use channel type for channel open
* channel_type is put into storage, serialized as int and
  deserialized as ChannelType
* check for static_remotekey is done via channel type
2022-01-20 16:47:48 +01:00
ghost43
ce44a03c24 Merge pull request #7202 from bitromortac/2104-mpp-channel-splitting
MPP splitting algorithm: redesign and split within channels
2021-12-17 13:58:54 +00:00
SomberNight
0df05dd914 qt preferences: always show cb for LN/"Create recoverable channels"
This makes it explicit that the option cannot be enabled if so (instead of hiding the checkbox).
2021-11-17 17:54:52 +01:00
SomberNight
56b03e2e8d lnpeer: more forwarding is now event-driven
This should make unit tests less reliant on sleeps.
2021-11-04 19:16:02 +01:00
SomberNight
4f907e3889 lnworker: change api of 'htlc_{fulfilled,failed}' events 2021-11-04 16:41:23 +01:00
bitromortac
f2f8c4533b implement option_shutdown_anysegwit
https://github.com/lightningnetwork/lightning-rfc/pull/672

We check the received shutdown script against higher segwit versions and
accept closing to that script if option_shutdown_anysegwit has been
negotiated.
2021-10-26 14:51:09 +02:00
SomberNight
1ff9f9910f ln update_fee: enforce that feerate is over default min relay fee
(this was always already the case when we are the funder, but we were
not checking it when remote is responsible for update_fee)
2021-09-28 19:48:31 +02:00
bitromortac
4ee5fa75f6 lnrouter+lnworker: rename my_channels 2021-07-29 16:26:23 +02:00
bitromortac
68bc9c2474 lnworker: improve route creation
- Separates the trampoline and local routing multi-part payment cases.
- Ask only for splits that don't send over a single channel (those have
  been tried already in the single-part case).
- Makes sure that create_routes_for_payment only yields partial routes
  that belong to a single split configuration.
- Tracks trampoline fee levels on a per node basis, previously, in the
  case of having two channels with a trampoline forwarder, the global
  fee level would have increased by two levels upon first try.
2021-07-16 11:27:36 +02:00
bitromortac
3c521f4ce3 mpp_split: split algorithm with channel splits
- The splitting algorithm is redesigned to use random distribution of
  subsplittings over channels.
- Splittings can include multiple subamounts within a channel.
- The single-channel splittings are implicitly activated once the
  liquidity hints don't support payments of large size.
2021-07-16 11:22:38 +02:00
SomberNight
8481afb286 lnchannel: introduce HTLCWithStatus NamedTuple 2021-07-15 01:35:24 +02:00
SomberNight
6a049d9901 wallet: make sure payment requests are persisted
Fixes: after adding a payment request, if the process was killed,
the payreq might get lost. In case of using the GUI, neither the
callee nor the caller called wallet.save_db().

Unclear where wallet.save_db() should be called...
Now each method tries to persist their changes by default,
but as an optimisation, the caller can pass write_to_disk=False
e.g. when calling multiple such methods and then call wallet.save_db() itself.

If we had partial writes, which would either rm the need for wallet.save_db()
or at least make it cheaper, this code might get simpler...

related: https://github.com/spesmilo/electrum/pull/6435
related: https://github.com/spesmilo/electrum/issues/4823
2021-07-05 18:39:10 +02:00
SomberNight
a339338958 LN private route hints: don't include low receive capacity channels
see code comment.

While the balance in the channels might shift before the sender tries to
pay the invoice, as we are not a forwarding node, that seems unlikely to matter.
2021-07-02 19:52:36 +02:00
SomberNight
3a7f5373ac trampoline: improve payment success
- better error handling: previously we stopped all attempts on any of
  TRAMPOLINE_EXPIRY_TOO_SOON, UNKNOWN_NEXT_PEER, TEMPORARY_NODE_FAILURE.
  Instead we should retry (but see code comments).
- previously payments failed if ALL of the following criteria applied:
  - sender is paying via trampoline, but not via the ACINQ node (which is
    special cased)
  - receiver only has private channels and has put r_tags into invoice, along
    with setting the trampoline feature bit in the invoice, however the receiver
    is not connected to any trampoline forwarders directly
  The sender would then assume that the private routing hints in the invoice
  correspond to trampoline forwarders.
- also, previously if both the sender and the recipient used trampoline and
  they shared a trampoline forwarder (that they were both connected to), the
  private channels the recipient had (with nodes other than the shared TF)
  would never be attempted.
2021-07-02 18:44:39 +02:00
SomberNight
57e52da77f lnaddr: clean-up SEGWIT_HRP vs BOLT11_HRP confusion
With signet, SEGWIT_HRP != BOLT11_HRP, so the previous "currency" string
became a flawed concept. Instead we pass around net objects now.
2021-06-22 16:16:21 +02:00
ThomasV
ad06398e4e lnworker: rm unused import 2021-06-11 12:27:05 +00:00
SomberNight
7ee4a2e299 follow-up prev 2021-06-10 18:52:12 +02:00
bitromortac
2749ea4d49 lnrouter: add inflight htlcs to liquidity hints 2021-05-11 09:17:11 +02:00
bitromortac
591a36fb3b lnworker: async gen create_routes_for_payments 2021-05-10 09:32:41 +02:00
bitromortac
4cb0b99996 lnworker: fix path_finder access 2021-04-26 08:43:50 +02:00
ghost43
0f83270053 Merge pull request #7152 from bitromortac/2103-liquidity-hints
Liquidity hints for pathfinding
2021-04-22 14:45:41 +00:00
SomberNight
12fac3a167 fix running with --offline 2021-04-13 19:05:07 +02:00
bitromortac
bc20f57a78 lnrouter: remove blacklist boolean 2021-04-09 11:11:21 +02:00
ThomasV
e936b6e4a5 fix #7185 2021-04-07 17:21:48 +02:00
bitromortac
4df67a4f78 lnrouter+lnworker: use liquidity hints
Adds liquidity hints for the sending capabilities of routing channels in the
graph. The channel blacklist is incorporated into liquidity hints.
Liquidity hints are updated when a payment fails with a temporary
channel failure or when it succeeds. Liquidity hints are used to give a
penalty in the _edge_cost heuristics used by the pathfinding algorithm.
The base penalty in (_edge_cost) is removed because it is now part of the
liquidity penalty. We don't return early from get_distances, as we want
to explore all channels.
2021-04-06 20:13:42 +02:00
ThomasV
5b1d54d014 fix #7165 2021-04-01 14:25:39 +02:00
SomberNight
f830939586 lnworker: change crypto for onchain static backups
Use scripthash as nonce instead of scriptPubKey,
as first two bytes of scriptPubKey are static, i.e. wasted.
2021-03-30 18:48:17 +02:00
SomberNight
e2e8cf1043 wallet: (minor) fix filtering history by year
E | gui.qt.exception_window.Exception_Hook | exception caught by crash reporter
Traceback (most recent call last):
  File "...\electrum\electrum\gui\qt\main_window.py", line 870, in timer_actions
    self.update_wallet()
  File "...\electrum\electrum\gui\qt\main_window.py", line 1003, in update_wallet
    self.update_tabs()
  File "...\electrum\electrum\gui\qt\main_window.py", line 1010, in update_tabs
    self.history_model.refresh('update_tabs')
  File "...\electrum\electrum\util.py", line 412, in <lambda>
    return lambda *args, **kw_args: do_profile(args, kw_args)
  File "...\electrum\electrum\util.py", line 408, in do_profile
    o = func(*args, **kw_args)
  File "...\electrum\electrum\gui\qt\history_list.py", line 329, in refresh
    self.view.filter()
  File "...\electrum\electrum\gui\qt\util.py", line 705, in filter
    self.hide_rows()
  File "...\electrum\electrum\gui\qt\util.py", line 709, in hide_rows
    self.hide_row(row)
  File "...\electrum\electrum\gui\qt\util.py", line 685, in hide_row
    should_hide = self.should_hide(row_num)
  File "...\electrum\electrum\gui\qt\history_list.py", line 445, in should_hide
    date = tx_item['date']
KeyError: 'date'
2021-03-30 17:48:46 +02:00
ThomasV
cd4df2fd85 detect conflicting channel backups, add warning before channel creation 2021-03-30 09:55:18 +02:00
SomberNight
5a3ec45b16 lnworker: fix another peer-handling race
(related to prev commit, but really another bug)

If we had two peers with the same pubkey (peer A in the process of teardown, peer B ~freshly connected),
peer A might remove peer B from lnworker.peers via close_and_cleanup().

rm `close_and_cleanup()` call from reestablish_channel - it was added
as a workaround for this bug (in 8b95b2127d)
before we understood the cause.
2021-03-29 20:51:54 +02:00
SomberNight
0c81414304 lnworker: handle multiple transports with same remote node id
If a remote node tries to establish a transport with us but we already
have an open transport with such a node id, there are two sane ways to go, either:
- keep existing transport open, reject new transport
- close existing transport, establish new transport

We could do either; I chose to do the second option here, as that is what
lnd and eclair seem to be doing.
Previously we would get into an inconsistent state: both transports open,
but only one of them stored in lnworker.peers.
2021-03-29 19:12:56 +02:00
ThomasV
602437bd17 fix remove_channel_backup (typo) 2021-03-29 18:18:41 +02:00
ThomasV
f06433e435 fix privkey in request_force_close_from_backup 2021-03-29 17:35:04 +02:00
SomberNight
f9ae47eb99 lnworker.num_sats_can_send should not return negative values 2021-03-29 16:20:24 +02:00
ThomasV
41f22df26b submarine swaps: use num_sats_can_receive_no_mpp, to prevent funds being locked 2021-03-26 16:27:32 +01:00
ThomasV
fdb0fe2f4c lnworker: guess routing fee in num_sats_can_send 2021-03-26 10:34:50 +01:00
ThomasV
4b870f15a7 fix wrong call to request_force_close_from_backup, make it private 2021-03-25 12:26:43 +01:00
ThomasV
18d7db12da Change warning shown on first channel creation
Qt: if created channel is not recoverable, show channel backup after creation
2021-03-24 10:24:14 +01:00
SomberNight
2c047c72e1 (trivial) just add some TODOs 2021-03-23 17:30:40 +01:00