Commit Graph

590 Commits

Author SHA1 Message Date
bitromortac
4ee5fa75f6 lnrouter+lnworker: rename my_channels 2021-07-29 16:26:23 +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
ThomasV
a5fea043d1 Allow user to remove onchain backups. 2021-03-23 14:41:37 +01:00
ThomasV
f7d2a33d45 set initial trampoline fee level to 1 unless we are testing 2021-03-22 17:04:01 +01:00
ThomasV
0f4297cfa8 fix direct payment to trampoline node 2021-03-22 13:17:50 +01:00
ThomasV
f8804b29c9 (minor) fix mutable default value 2021-03-22 11:50:01 +01:00
Benoit Verret
f731c38293 Minor style changes 2021-03-21 00:36:23 -04:00
ThomasV
aad392f6ff lnworker: filter active channels in create_routes_for_payment 2021-03-20 13:53:46 +01:00
ThomasV
0121cbcbbe pay_to_route: raise PaymentFailure in case of dropped peer, so that we reset payment status 2021-03-20 10:12:49 +01:00
SomberNight
d8352f1a0a lnworker: nicer logs/error msgs for payment failure
try to decode onion error and log it in human-readable form
2021-03-19 19:13:50 +01:00
ThomasV
2fee920f43 On Android, if channels are not recoverable, display channel backup when a new channel is created.
Remove the 'android_backups' setting, which was unpractical.
2021-03-19 13:17:58 +01:00
ThomasV
64a931f21e Deterministic NodeID:
- use_recoverable_channel is a user setting, available
   only in standard wallets with a 'segwit' seed_type
 - if enabled, 'lightning_xprv' is derived from seed
 - otherwise, wallets use the existing 'lightning_privkey2'

Recoverable channels:
 - channel recovery data is added funding tx using an OP_RETURN
 - recovery data = 4 magic bytes + node id[0:16]
 - recovery data is chacha20 encrypted using funding_address as nonce.
   (this will allow to fund multiple channels in the same tx)

GUI:
  - whether channels are recoverable is shown in wallet info dialog.
  - if the wallet can have recoverable channels but has an old node_id,
    users are told to close their channels and restore from seed
    to have that feature.
2021-03-19 10:17:02 +01:00
ThomasV
8a051dcd76 lnworker: use booleans for enable_htlc_settle, enable_htlc_forwarding 2021-03-18 07:48:30 +01:00
ThomasV
e954bfaa54 request_force_close: close and reopen existing peer connection,
because channel_reestablish cannot be sent twice in the same session
2021-03-17 15:36:21 +01:00
ThomasV
1c8c236933 channels_with_funds: self._channels -> self.channels 2021-03-17 13:50:57 +01:00
ThomasV
8d8f078544 Merge pull request #7107 from bitromortac/2103-trampoline-mpp-single
mpp_split: use single nodes for mpp payments over trampoline
2021-03-17 13:47:13 +01:00
ThomasV
3c9838d999 lnworker: merge request_force_close and request_remote_force_close 2021-03-17 09:15:40 +01:00
bitromortac
8828998093 mpp_split: use single nodes for mpp payments over trampoline 2021-03-17 08:22:19 +01:00
SomberNight
5e12f88be3 lnworker: minor clean-up, fix typo 2021-03-16 19:19:26 +01:00
SomberNight
468f3b2b8d lnchannel: verify sig of remote chanupd (for inc edge of direct chan)
This is re the channel update for the incoming direction of our own channels.
This message can only come from the counterparty itself so maybe the sig check
is redundant... but for sanity I think we should check it anyway.
2021-03-16 19:07:31 +01:00
ThomasV
bcfcc20363 fix: add request_force_close method 2021-03-16 17:27:37 +01:00
SomberNight
dca182992f ln gossip: run sig checks in a thread
to avoid blocking the asyncio event loop
2021-03-15 20:44:24 +01:00