1
0
Commit Graph

201 Commits

Author SHA1 Message Date
SomberNight
1810835fae lnchannel: get_capacity() should not raise when running with --offline
```
E | gui.qt.exception_window.Exception_Hook | exception caught by crash reporter
Traceback (most recent call last):
  File "...\electrum\electrum\gui\qt\channels_list.py", line 295, in do_update_rows
    field_map = self.format_fields(chan)
  File "...\electrum\electrum\gui\qt\channels_list.py", line 99, in format_fields
    capacity_str = self.parent.format_amount(chan.get_capacity(), whitespaces=True)
  File "...\electrum\electrum\lnchannel.py", line 481, in get_capacity
    return self.lnworker.lnwatcher.get_tx_delta(self.funding_outpoint.txid, self.cb.funding_address)
AttributeError: 'NoneType' object has no attribute 'get_tx_delta'
```
2022-03-29 18:30:55 +02:00
bitromortac
3915045067 lnpeer: warnings for shutdown and open_channel 2022-03-09 13:40:44 +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
SomberNight
75af5b1542 lnchannel.set_state: add "force" option for debugging use 2022-02-18 15:43:16 +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
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
ThomasV
7a0904c0f4 wallet update: move fields that have string keys out of channel log 2021-09-20 14:47:20 +02:00
SomberNight
8481afb286 lnchannel: introduce HTLCWithStatus NamedTuple 2021-07-15 01:35:24 +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
f52c0fd571 lnchannel: rm HTLC value upper limit of ~42 mBTC
closes #7328
closes #7100
see https://github.com/lightningnetwork/lightning-rfc/pull/877#issuecomment-857577075
2021-06-10 17:26:04 +02:00
SomberNight
f2040b19ea lnpeer: log both sent and recv msgs; use pubkey for incoming transports
Previously for incoming transports, the diagnostic_name (for log messages)
was just "responder" -- not sufficient to distinguish peers.
We now use the pubkey instead.

For outgoing transports it is f"{host}:{port}" (unchanged).
We could just use the pubkey for both uniformly; but it is quite long, and
it is hard to distinguish them at a glance.
2021-03-29 21:29:51 +02:00
ThomasV
e38dabf502 lnchannel: get_state_for_GUI minor fix 2021-03-29 18:37:13 +02:00
SomberNight
a509573ea0 lnrater: don't suggest nodes we have a channel backup with
We don't want to connect to nodes we already have a channel with on another device.
2021-03-29 17:49:27 +02:00
ThomasV
b64fcfb9e3 lnpeer: if close_channel times out, check unconfirmed_closing_txid before raising an exception 2021-03-26 09:30:29 +01:00
ThomasV
6491421930 lnchannel: rename force_close_detected -> closing_detected, use it only if state is OPEN 2021-03-25 11:24:33 +01:00
ThomasV
8a7bd5cf3e (minor) fix GUI if channel is force closing 2021-03-25 11:14:05 +01:00
ThomasV
130842ecd4 Add 'has_onchain_backup' to channel storage, to fix the displayed icon.
Note that this will not fix the value for already existing channels
that have been created with onchain backup; one would need a wallet_db
upgrade in order to fix them (probably not worth the effort).
2021-03-24 11:15:24 +01:00
ThomasV
a5fea043d1 Allow user to remove onchain backups. 2021-03-23 14:41:37 +01:00
ThomasV
a67fcdbc8a channels_list: use icon to tell apart channels from backups 2021-03-23 14:06:28 +01:00
ThomasV
62a95c4b94 lnchannel: add pseudo-state force_close_detected for GUI 2021-03-23 12:03:14 +01:00
ThomasV
afcc695f4d channels_list: show backup text in the state column. fix missing import in previous commit. 2021-03-19 13:35:12 +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
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
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
8588674539 channel backups: display status from lnworker instead of channel state 2021-03-15 16:05:05 +01:00
ThomasV
65d263801a show capacity of channel backups in GUI 2021-03-12 17:39:13 +01:00
ThomasV
af7bcd4ca1 add comments about ChannelBackup fields 2021-03-12 16:11:47 +01:00
SomberNight
762ebb12b2 lnpeer: increase max_accepted_htlcs (5->30)
Counter-intuitively, the motivation is to be able to *send* more htlcs,
for MPP trickery. We don't offer more htlcs than this limit, to be
conservative with what we send, and to interoperate with clightning.

defaults of other clients:
eclair: 30
clightning: 30
lnd: 483
2021-03-05 16:12:01 +01:00
SomberNight
4445cef033 lnutil: turn global forwarding fee params into Channel attributes
useful for unit testing, and it is the conceptually correct thing anyway
2021-03-02 14:54:47 +01:00
ThomasV
693583edc5 lnworker: amount passed in HtlcLog must be without fees 2021-03-02 10:23:30 +01:00
SomberNight
16f0b30ced lnpeer: MPP recv: only fulfill htlc if amt sum exact-matches total_msat 2021-02-24 20:51:58 +01:00
ThomasV
0369829e5e MPP: can_send/can_receive is now the sum, no longer the max 2021-02-22 16:42:27 +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
87a080d30e split code in htlc_switch:
- raise OnionRoutingFailure whenever we want to fail a htlc
 - catch that exception in htlc_switch
 - this will avoid code duplication in the case of trampoline
2021-02-11 06:19:17 +01:00
ThomasV
f28a2aae73 Reorganize code so that we can send Multi Part Payments:
- LNWorker is notified about htlc events and creates payment events.
 - LNWorker._pay is a while loop that calls create_routes_from_invoice.
 - create_route_from_invoices should decide whether to split the payment,
   using graph knowledge and feedback from previous attempts (not in this commit)
 - data structures for payment logs are simplified into a single type, HtlcLog
2021-02-05 14:28:58 +01:00
ThomasV
ef5a265449 basic_mpp: receive multi-part payments 2021-02-04 16:31:17 +01:00
ThomasV
c0bf9b4509 LNWorker: do not save PR_INFLIGHT status, detect it on startup instead 2021-02-04 16:30:50 +01:00
SomberNight
2b0f156ce8 lnpeer.htlc_switch: (bugfix) don't fulfill htlc until add is irrevocable
This makes the test added in prev commit pass.
2021-01-28 20:03:30 +01:00
SomberNight
e8a2fa5596 tests: lnpeer.htlc_switch: don't fulfill htlc until add is irrevocable
This adds a failing test, where the HTLC switch fulfills an HTLC too soon,
before the corresponding 'update_add_htlc' is irrevocably committed.
2021-01-28 20:00:48 +01:00
ThomasV
b3eb8592f3 upfront_shutdown_script: fix ChannelBackup constructor 2021-01-16 23:19:57 +01:00
ThomasV
805c5a2120 upfront_shutdown_script: rm dead code, fix test 2021-01-11 12:30:49 +01:00
bitromortac
6b90a2d36c lnpeer: implement upfront shutdown script logic
Upfront shutdown script is a script provided on channel opening,
which will be used by the peer to enforce us closing to this script
on collaborative channel close.
2021-01-11 11:37:14 +01:00
ThomasV
d70431c0e7 lnchannel.available_to_spend: return zero if frozen or not active. Without this, the channel details window displays can_send/can_receive values that are inconsistent with the main window 2020-12-30 11:51:02 +01:00
ThomasV
c478f3bb91 channel backups: fix exception in raised after channel is force closed
Traceback (most recent call last):
  File "/opt/electrum/electrum/util.py", line 1056, in wrapper
    return await func(*args, **kwargs)
  File "/opt/electrum/electrum/lnwatcher.py", line 183, in on_network_update
    await callback()
  File "/opt/electrum/electrum/lnwatcher.py", line 200, in check_onchain_situation
    keep_watching = await self.do_breach_remedy(funding_outpoint, closing_tx, spenders)
  File "/opt/electrum/electrum/lnwatcher.py", line 377, in do_breach_remedy
    sweep_info_dict = chan.sweep_ctx(closing_tx)
  File "/opt/electrum/electrum/lnchannel.py", line 227, in sweep_ctx
    our_sweep_info = self.create_sweeptxs_for_our_ctx(ctx)
  File "/opt/electrum/electrum/lnchannel.py", line 216, in create_sweeptxs_for_our_ctx
    return create_sweeptxs_for_our_ctx(chan=self, ctx=ctx, sweep_address=self.sweep_address)
  File "/opt/electrum/electrum/lnchannel.py", line 321, in sweep_address
    assert self.lnworker.wallet.is_mine(addr)
AssertionError
2020-12-27 18:11:42 +01:00
bitromortac
7a62074f8e lnchannel: reflect frozen amounts and disconnected channels
in the num_sats_can_send/receive methods of the lnwallet.
2020-12-18 07:09:48 +01:00
SomberNight
ee24c74f19 lnchan.receive_revocation: tolerate not having htlc fail reason
If we get a revack after reestablish, but the fail_htlc was already
committed in a previous app-session, the fail_htlc will not be re-sent and
we will not have the reason (as it's not persisted).

fixes #6675
2020-10-23 02:35:20 +02:00
ghost43
3eba26b398 LN cooperative close: avoid address-reuse (#6590)
Previously if we coop-closed multiple channels in the same session,
they would reuse the wallet address.
2020-09-15 15:37:47 +00:00
SomberNight
aba2e0f55a lnhtlc: add all_htlcs_ever, get_htlc_by_id, was_htlc_failed and use them
towards encapsulation of hm.log
2020-09-04 19:29:14 +02:00
SomberNight
d5f368c584 LN invoices: support msat precision
fixes #6250
2020-06-22 22:48:13 +02:00
ThomasV
b06daaa669 fix display of short_channel_id for channel backups 2020-06-19 19:38:19 +02:00