Commit Graph

787 Commits

Author SHA1 Message Date
SomberNight
9f1b8613d0 swaps: code style clean-up, add type hints, force kwargs
no intended functional changes
2023-11-22 17:50:29 +00:00
SomberNight
6a8fb26881 (trivial) follow-up prev 2023-11-20 11:37:39 +00:00
SomberNight
4cdd199f5b lnworker: add/fix some type hints, add some comments
follow-up recent refactor
2023-11-20 11:34:56 +00:00
ThomasV
1cc92d4890 trampoline forwarding: before failing payment, wait until all htcs
have failed and session is not longer active.
2023-11-18 16:08:11 +01:00
ThomasV
9b1c40e396 Refactor payment forwarding:
- all forwarding types use the same flow
 - forwarding callback returns a htlc_key or None
 - forwarding info is persisted in lnworker:
   - ongoing_forwardings
   - downstream to upstream htlc_key
   - htlc_key -> error_bytes
2023-11-18 16:03:18 +01:00
ThomasV
835992c7ea lnworker: remove if statements where the condition is always True.
Such statements creates confusion for the reader.
2023-11-16 17:34:48 +01:00
SomberNight
6ffaf7c526 lnworker: (followup prev) set .config in baseclass init, not subclasses
as methods in the base class also rely on the config field, not just methods in the subclasses
2023-11-13 15:39:15 +00:00
ThomasV
7447cf9dcc lnworker: always initialize self.config in constructor 2023-11-13 14:54:40 +01:00
ThomasV
7bebd62f13 zerofonf trusdted node: use NetworkRetryManager method _can_retry_addr 2023-11-13 10:47:18 +01:00
ThomasV
a338459d45 just-in-time channels:
- a node scid alias is derived from the node ID
 - the channel opening fee is sent in a TLV field of open_channel
 - the server requires htlc settlement before broadcasting
   (server does not trust client)
2023-11-13 10:47:18 +01:00
ThomasV
816e617aaf option_zeroconf
- accept zeroconf channels only from a single node
 - fw_info uses get_scid_or_local_alias
2023-11-13 10:47:18 +01:00
ThomasV
120faa480e If trampoline is enabled, do not add non-trampoline nodes to invoices
Rationale: The sender should not assume that they share the same list of
hardcoded trampolines as the receiver.
2023-10-29 16:21:25 +01:00
ThomasV
1170927e6b Change the constructor of LNWorker, passing node_keypair instead of xprv.
There is no need for payment_secret_key and backup_key in this class
2023-10-27 18:28:36 +02:00
SomberNight
6506abf583 lnworker: use PaymentFeeBudget
- introduce PaymentFeeBudget, which contains limits for fee budget and cltv budget
  - when splitting a payment,
    - the fee budget is linearly distributed between the parts
      - this resolves a FIXME in lnrouter ("FIXME in case of MPP")
    - the cltv budget is simply copied
  - we could also add other kinds of budgets later, e.g. for the num in-flight htlcs
- resolves TODO in lnworker ("todo: compare to the fee of the actual route we found")
2023-10-27 16:01:23 +00:00
SomberNight
53a8453e3b trampoline: fix off-by-one confusion of fees
The convention is that edges (start_node -> edge_node) store
the policy/fees for the *start_node*.
This is what the non-trampoline edges were already using (for a long time),
but the trampoline ones were off-by-one (policy was for end_node),
which was then worked around in multiple places, to correct for...

i.e. I think because of all the workarounds, there was no actual bug,
but it was just very confusing.

Also note that the prior usage of trampoline edges would not work if
we (sender) were not directly connected to a TF (trampoline-forwarder)
but had extra edges in the route to even get to the first TF.
Having the policy corresponding to the start_node of the edge would work
even in that case.
2023-10-27 14:24:19 +00:00
SomberNight
39ef1cd4b9 mpp_split: make SplitConfig a subclass of dict, not just a type-hint 2023-10-27 14:24:12 +00:00
SomberNight
0b25e593d5 lnworker.get_channel_by_short_id: give priority to real SCIDs
always check real SCIDs first, before checking aliases
2023-10-26 14:32:36 +00:00
ThomasV
36814d731a follow-up 45b248fdef 2023-10-24 13:15:03 +02:00
ThomasV
e341a6794b lnworker: fix get_scid_alias for forwarding
Note: this issue is currently not detected in python unittests,
it shows up only in regtest, and is not currently tested.
One would need to use a proper LNWallet instance in unit tests.
2023-10-24 13:05:35 +02:00
ThomasV
45b248fdef regtest: use static fees instead of hardcoded value
this allows to bump fees using "setfeerate"
2023-10-24 12:24:26 +02:00
ThomasV
6dfbdec73e follow-up prev commit 2023-10-20 13:52:55 +02:00
ThomasV
b26f954c2d lnworker.pay_to_node: skip error handling if sender_idx is None 2023-10-20 13:42:12 +02:00
SomberNight
22a8348303 renames: use consistent naming of cltv delta vs cltv abs
to avoid confusing relative vs absolute cltvs
(see b0401a6386)
2023-10-19 16:40:05 +00:00
SomberNight
f78340efbc lnworker: (trivial) fix type hint
follow-up 4c42840c1c
2023-10-19 15:26:20 +00:00
ThomasV
4c42840c1c lnpeer: obfuscate error pakets of forwarded htlcs, that we
propageate back to the sender.

lnworker: in htlc_fulfilled and htlc_failed, return early if the
htlc was forwarded, so that we do not trigger invoice callbacks
2023-10-19 15:59:26 +02:00
SomberNight
a059a9a256 lnpeer.pay: also log hops_data for trampoline_onion
We were already logging the outer-layer hops_data,
now we also log the inner trampoline-onion hops_data.

Example:
```
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | lnpeer.pay len(route)=1
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] |   0: edge=9926297x9781928x61754 hop_data=<OnionHopsDataSingle. payload={'amt_to_forward': {'amt_to_forward': 100000000}, 'outgoing_cltv_value': {'outgoing_cltv_value': 601299}, 'payment_data': {'payment_secret': b'\xd2\x9cl\xdfV\xd4\xea_\x06{\xed\xc9\xc7\xa6\xf5\xc0\n\x1a\x95\xad\xad\xd2F\xb8;&\x9f\xa1\xe1\xd1\x07H', 'total_msat': 100000000, 'amount_msat': 100000000}}. hmac=None>
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | adding trampoline onion to final payload
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | lnpeer.pay len(t_route)=3
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] |   0: t_node=02389c93b85ef8f7264c6fa3d3b239341c2631c2cab97e815b33453bd8d0254e77 hop_data=<OnionHopsDataSingle. payload={'amt_to_forward': {'amt_to_forward': 100000000}, 'outgoing_cltv_value': {'outgoing_cltv_value': 600723}, 'outgoing_node_id': {'outgoing_node_id': b'\x03\x06\xd9,\x9c\xabRe\x83Mr\x0b\x14(\xf5\x81\xf9\xfb\x9b\xfeV\xc1q\x85&L\xda\xffs\xe5y(\x81'}}. hmac=b'\xe7\x04\xe2>\x9a\xd9\xf0\x92<\xf8Q\xe4\xf4\xd8\x8cr{\x1e\xb1\xee\xb0\xd4R\xba\xe5\xfd\x83\xfc\xd7\xa7\x1dt'>
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] |   1: t_node=0306d92c9cab5265834d720b1428f581f9fb9bfe56c17185264cdaff73e5792881 hop_data=<OnionHopsDataSingle. payload={'amt_to_forward': {'amt_to_forward': 100000000}, 'outgoing_cltv_value': {'outgoing_cltv_value': 600147}, 'outgoing_node_id': {'outgoing_node_id': b'\x03\x85v\xac:\xf8AUW\xcf\x1d\x12e\xcc\xff\xb1\xea\xd6\x01\xd5\x17HX?\x12\x83\x9cD\xbe\xebC\x82o'}}. hmac=b's-\xe1\xdb\xbc\xa5\x88\x90\xc0\xafu\xab\xba\xb6k\x81\xeae)#\x85\x12fm\xe6\xc3\xbd\xf6\x86eR\xd2'>
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] |   2: t_node=038576ac3af8415557cf1d1265ccffb1ead601d51748583f12839c44beeb43826f hop_data=<OnionHopsDataSingle. payload={'amt_to_forward': {'amt_to_forward': 100000000}, 'outgoing_cltv_value': {'outgoing_cltv_value': 600147}, 'payment_data': {'payment_secret': b'B-P\x01\xc3\x1e#\x19\xf9!\xbb\xd8\xd1pu\xc7J\x11A\xa8J\xfe\xb8\x8a\xb8\xc4Oi\x0f\xe8\xac\xab', 'total_msat': 100000000}}. hmac=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'>
  1.12 | I | P/lnpeer.Peer.[MockLNWallet, alice->bob] | starting payment. len(route)=1.
```
2023-10-18 18:07:21 +00:00
ThomasV
2664ee7f63 pay_to_node: raise failure_msg if we received a trampoline error from the next onion.
that way, the error is sent back to the payer
2023-10-18 19:32:13 +02:00
SomberNight
30c863d32c lnaddr: don't call validate_features in parser
- see comment in lnaddr.py
- Previously we used feature bit 50/51 for trampoline.
  The spec subsequently defined fbit 50/51 as option_zeroconf, which
  requires fbit 46/47 (option_scid_alias) to also be set.
  We moved the non-standard trampoline fbit to a different int.
  However, old wallets might have old invoices saved that set fbit 50/51
  for trampoline, and those would not have the dependent bit set.
  Invoices are parsed at wallet-open, so if the parser ran these checks,
  those wallets could not be opened.
- note: we could potentially also run lnaddr.validate_and_compare_features
  when saving new invoices into the wallet but this is not done here
2023-10-16 17:10:49 +00:00
ThomasV
98a4d7b60d public channels:
- send node and channel announcements.
 - store channel_flags in constraints
 - store signatures in local and remote configs
2023-10-16 13:54:16 +02:00
ThomasV
aad4fd6d48 Fix sending of 'channel_ready':
- send only once
 - in channel_reestablish, do not send it if we are not funded.
 - lnworker: do not send channel_ready before channel_reestablish
2023-10-15 10:58:37 +02:00
ThomasV
89023cc123 Remove trampoline hints from invoices
This has been deprecated for a long time, was kept only for
compatibility with old electrum clients.
2023-10-11 09:47:36 +02:00
ThomasV
57c9059cab open_channel_with_peer: return funding tx
(this makes things easier the just_in_time_channels branch)
2023-10-09 17:02:19 +02:00
ThomasV
e2fb928e4f delete htlc session keys once they are no longer needed.
fixes #8630

Note: maybe we should plan a WalletDB upgrade to cleanup
existing wallets.
2023-10-08 15:52:41 +02:00
ThomasV
4e76ed6952 move INITIAL_TRAMPOLINE_FEE_LEVEL to config 2023-10-08 15:06:19 +02:00
ThomasV
40eba6f780 submarine swaps: improve labels
- claim tx was incorrectly labeled
 - if we send tx change to a swap, display both labels
2023-10-05 15:41:04 +02:00
ThomasV
d7beb109b8 lnworker: separate add_peer from _open_channel_coroutine 2023-09-19 09:45:56 +02:00
ThomasV
cffbe44c07 lnworker: get_channel_by_short_id to use remote scid_alias
This is needed when forwarding payments
2023-09-17 11:12:23 +02:00
ThomasV
375f96f7fa remove lnworker.get_channel_by_scid (redundant) 2023-09-17 11:06:25 +02:00
ThomasV
c27e6de975 Merge pull request #8616 from SomberNight/202309_dont_sign_tx_with_dummy_addr
add sanity checks we don't sign tx including dummy addr
2023-09-16 15:02:36 +02:00
ThomasV
59aa7611dd add group_id to swap refund transactions, so that the GUI shows them as part of the swap tx group 2023-09-16 11:09:39 +02:00
SomberNight
4c63d8729b add sanity checks we don't sign tx including dummy addr
Somewhat a follow-up to 649ce979ab.

This adds some safety belts so we don't accidentally sign a tx that
contains a dummy address.
Specifically we check that tx does not contain output for dummy addr:
- in wallet.sign_transaction
- in network.broadcast_transaction

The second one is perhaps redundant, but I think it does not hurt.
2023-09-16 04:36:08 +00:00
SomberNight
2746a9d93f lnchannel: replace assert htlc.payment_hash==sha256(preimage) w/ exc
asserts should not be used for security checks
2023-09-12 13:30:48 +00:00
ThomasV
649ce979ab send tx change to lightning 2023-09-09 14:14:43 +02:00
ThomasV
136978e9d0 submarine swaps: fail received HTLCs of normal swap htlcs if
the swap is still unfunded and the refund delay has expired.
2023-09-08 16:38:08 +02:00
SomberNight
a560841f3f lnworker: fix some type hints re hold_invoices 2023-09-06 19:01:41 +00:00
SomberNight
2529323ba3 (trivial) lnworker: fix type hint 2023-09-06 14:11:41 +00:00
ThomasV
af27d5b95e Payment bundles: use lists of payment keys.
That way we don't need to special case trampoline outer onions
2023-09-06 10:44:55 +02:00
ThomasV
4d0ec8d177 lnworker: choose IP address with recent timestamp (Rogach) 2023-08-30 09:32:34 +02:00
ThomasV
b2053c68f1 make use_to_trampolines a user visible option, disable it by default 2023-08-27 11:43:17 +02:00
SomberNight
a3997f8b58 lnworker: don't create invoice with dupl t-hints, & filter when sending
- when creating an invoice, if we had multiple chans with the same trampoline,
  were putting duplicate t-hints into the invoice
- when paying an invoice that had duplicate t-hints, we would sometimes
  construct invalid paths (SRC>T1->T1->DST)
2023-08-17 20:04:02 +00:00