Commit Graph

539 Commits

Author SHA1 Message Date
ThomasV
077bcf515d StoredDict: use pointers instead of path
Instead of storing its own path, each StoredDict element stores
its own key and a pointer to its parent. If a dict is removed
from the db, its parent pointer is set to None. This makes
self.path return None for all branches that have been pruned.

This passes tests/tests_json_db.py and fixes issue #10000
2025-11-07 10:00:10 +01:00
f321x
a5cf5f75fc lnpeer: await init in main_loop
Because `LNPeer.initialized` was awaited in
`LNPeer._query_gossip()` instead of the main loop the other tasks got
spawned concurrently and each task on its own has to wait for the
initialization. In `LNPeer._send_own_gossip()` this was missing, instead
there is a fixed 10 sec sleep. If the connection was not initialized but
the 10 sec are exceeded `_send_own_gossip()` tries to send gossip and
causes this exception as the `LNTransport` is not ready:

```
  2.13 | E | lnpeer.Peer.[LNWallet, 0288fa27c0-bc1900c8] | Exception in main_loop: AttributeError("'LNTransport' object has no attribute 'sk'")
Traceback (most recent call last):
  File "/home/user/code/electrum-fork/electrum/util.py", line 1232, in wrapper
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/code/electrum-fork/electrum/lnpeer.py", line 511, in wrapper_func
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/code/electrum-fork/electrum/lnpeer.py", line 525, in main_loop
    async with self.taskgroup as group:
               ^^^^^^^^^^^^^^
  File "/home/user/code/electrum-fork/env/lib/python3.14/site-packages/aiorpcx/curio.py", line 304, in __aexit__
    await self.join()
  File "/home/user/code/electrum-fork/electrum/util.py", line 1420, in join
    task.result()
    ~~~~~~~~~~~^^
  File "/home/user/code/electrum-fork/electrum/lnpeer.py", line 573, in _send_own_gossip
    self.send_node_announcement(alias, color)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/home/user/code/electrum-fork/electrum/lnpeer.py", line 1830, in send_node_announcement
    self.transport.send_bytes(raw_msg)
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/user/code/electrum-fork/electrum/lntransport.py", line 225, in send_bytes
    lc = aead_encrypt(self.sk, self.sn(), b'', l)
                      ^^^^^^^
AttributeError: 'LNTransport' object has no attribute 'sk'. Did you mean: 'sn'?
```

By awaiting the initialization directly in the `main_loop` it is more
clear that the task getting spawned subsequently depend on the transport
being available and separates the initialization more clearly these
other functions.
2025-10-28 15:42:16 +01:00
f321x
d62b627a0b lnpeer: move htlc forwarding funcs to lnworker
forwarding happens independent of the peer that received the htlc to
forward and fits better in lnworker.
2025-09-30 09:54:24 +02:00
f321x
32aa6ab20c lnutil: rename RecvMPPResolution.ACCEPTED
Renames RecvMPPResolution.ACCEPTED to .COMPLETE as .ACCEPTED is somewhat
misleading. Accepted could imply that the preimage for this set has been
revealed or that the set has been settled, however it only means that we
have received the full set (it is complete), but the set still can be
failed (e.g. through cltv timeout) and has not been claimed yet.
2025-09-29 16:11:26 +00:00
f321x
7d0a69a9ce lnpeer: only spawn htlc_switch for peers with LNWallet
stop spawning htlc_switch for LNGossip peers, they don't handle any
htlcs
2025-09-29 16:11:20 +00:00
f321x
fcc3796079 lnworker: move RecvMPPResolution and status to lnutil
it is required both in lnpeer and lnworker, moving it to lnutil seems to
make more sense.

# Conflicts:
#	electrum/lnworker.py
2025-09-29 16:11:17 +00:00
f321x
9db975f9d7 lightning: remove legacy payment secret derivation
This seems old and not very useful anymore.
2025-09-29 16:11:13 +00:00
f321x
acd52da764 lnpeer: cleanup imports 2025-09-29 16:10:59 +00:00
f321x
e7bb75bc3e chore: replace calls to asyncio.iscoroutinefunction
Replace calls to deprecated asyncio.iscoroutinefunction with calls to
inspect.iscoroutinefunction to prevent the following deprecation
warnings from showing up if running with Python 3.14:
```
/home/user/code/electrum-fork/electrum/util.py:1225: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
  assert asyncio.iscoroutinefunction(func), 'func needs to be a coroutine'
/home/user/code/electrum-fork/electrum/util.py:507: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
  if asyncio.iscoroutinefunction(func):
/home/user/code/electrum-fork/electrum/util.py:1246: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
  assert asyncio.iscoroutinefunction(func), 'func needs to be a coroutine'
/home/user/code/electrum-fork/electrum/lnpeer.py:272: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
  assert asyncio.iscoroutinefunction(func), 'func needs to be a coroutine'
/home/user/code/electrum-fork/electrum/util.py:1225: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
  assert asyncio.iscoroutinefunction(func), 'func needs to be a coroutine'
/home/user/code/electrum-fork/electrum/util.py:507: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
  if asyncio.iscoroutinefunction(func):
```
2025-09-05 10:29:34 +02:00
SomberNight
835b04d5c6 swaps: add explicit check that (onchain_locktime < LN_locktime)
This was already implicitly checked. This diff makes the check explicit, and serves as an additional sanity-check.
- for client-forward-swaps, we have
  - "cltv safety requirement: (onchain_locktime < LN_locktime),   otherwise client is vulnerable"
  - server chooses onchain locktime delta = 70
    71255c1e73/electrum/submarine_swaps.py (L701)
  - client checks that onchain locktime delta is <100
    71255c1e73/electrum/submarine_swaps.py (L887)
  - client chooses LN locktime delta = 432
    71255c1e73/electrum/submarine_swaps.py (L907)
- for client-reverse-swaps, we have
  - "cltv safety requirement: (onchain_locktime < LN_locktime),   otherwise server is vulnerable"
  - server chooses onchain locktime delta = 70
    71255c1e73/electrum/submarine_swaps.py (L598)
  - server chooses LN locktime delta: unset, i.e. our default of 147
    71255c1e73/electrum/submarine_swaps.py (L612)
    71255c1e73/electrum/lnworker.py (L2273)
2025-08-26 04:55:10 +00:00
SomberNight
1380ed4ba7 lnpeer: rate-limit ordered_message_queues 2025-08-19 18:28:13 +00:00
SomberNight
b8d989e13b lnpeer: rate-limit reply_channel_range 2025-08-19 18:28:09 +00:00
SomberNight
65d04dfbb7 lnpeer: slow down peers sending too much gossip 2025-08-19 18:28:01 +00:00
SomberNight
f8926b4957 type-hint some Callables
could not figure out how to type-hint coinchooser.sufficient_funds with typing.Protocol,
at least PyCharm complained on all my attempts
2025-08-18 15:38:25 +00:00
f321x
389a0a6e91 cli: use payment hash for add_hold_invoice
Allowing to create hold invoices just by providing a payment hash
instead of the preimage right from the beginning allows for additional
use cases where the recipient doesn't have access to the preimage when
creating the invoice.
2025-06-30 09:34:05 +02:00
ThomasV
853b793bef rm verbosity_shortcuts option (unused, redundant) 2025-05-29 16:20:41 +02:00
SomberNight
65c9a5f875 lnchannel: refactor can_send_ctx_updates
This adds a lot more sanity checks to lnpeer/lnchannel for chan update operations,
and more logging in case they are violated.
2025-05-21 14:57:56 +00:00
SomberNight
d0be5fcfc8 lnchannel: persist error sent by remote peer into db
If a force-close happens due to e.g. a feerate disagreement or an invalid signature, etc,
and the remote peer sends us an error, it can be useful if users can provide us with this error.
If the user does not have logging enabled when the error is sent, without this persistence it will likely get lost.
2025-05-18 16:54:56 +00:00
ghost43
79a54c1578 Merge pull request #9826 from f321x/fix_fee_disagreement_ln
fix: reduce update_fee target for anchor channels
2025-05-15 13:30:11 +00:00
f321x
61874e9fe7 fix: reduce update_fee target for anchor channels
the update_fee logic for lightning channels was not adapted to anchor
channels causing us to send update_fee with a eta target of 2 blocks.
This causes force closes when there are mempool spikes as the fees we
try to update to are a lot higher than e.g. eclair uses. Eclair will
force close if our fee is 10x > than their fee.
2025-05-14 18:01:44 +02:00
ThomasV
6d939a0ee6 add LIGHTNING_MAX_HTLC_VALUE_IN_FLIGHT_MSAT to config
This allows to reproduce #9700 using two electrum instances
2025-05-13 13:07:00 +02:00
Sander van Grieken
0ccdddf46a logging levels
lnpeer: received orphan channel update -> debug
exchange_rate: received quotes -> debug
2025-04-24 09:10:59 +02:00
f321x
253ab6849a implement NIP47 plugin 2025-04-10 10:22:29 +02:00
SomberNight
b13de0afb5 lnpeer: request_gossip: change log line format
before/after:
`requesting channel graph since Fri Apr  4 17:19:05 2025`
`requesting channel graph since 2025-04-04T17:20:04`
2025-04-04 17:23:26 +00:00
f321x
db55e37277 fix exception if LIGHTNING_LISTEN is not set on public node 2025-04-04 12:20:48 +02:00
f321x
0b19b660c5 don't use fallback feerates in lightning by default 2025-04-01 14:12:02 +02:00
ThomasV
58be5a3ad5 Allow wallets to use non-deterministic lightning,
if they use a software keystore.

This excludes hardware wallets and watching-only wallet.
Also, this forbids creation of new channels in those wallets,
in case lightning was previously enabled.

Fixes #9440
2025-03-17 09:51:52 +01:00
ThomasV
764cc78386 Merge pull request #9590 from f321x/jit-update-unfunded-state
Handle unfunded zeroconf channels in update_unfunded_state
2025-03-07 13:55:55 +01:00
f321x
6fd833ccfb add handling of zeroconf channels to update_unfunded_state 2025-03-07 13:53:01 +01:00
ThomasV
8011ae00ab Merge pull request #9586 from f321x/jit-block-preimage
Add mechanism to block htlcs from settling back
2025-03-07 12:04:39 +01:00
f321x
109ad2b3da add mechanism to block htlcs from settling back 2025-03-07 12:03:59 +01:00
ThomasV
840243e029 separate fee policy from config
- Wallet.make_unsigned_transaction takes a FeePolicy parameter
 - fee sliders act on a FeePolicy instead of config
 - different fee policies may be used for different purposes
 - do not detect dust outputs in lnsweep, delegate that to lnwatcher
2025-03-05 10:29:26 +01:00
ThomasV
6234cbf97b Merge pull request #9603 from spesmilo/gossip_info
gossip: less log lines, use command line instead
2025-03-05 08:23:19 +01:00
ghost43
718a5137dd Merge pull request #9588 from f321x/jit-accept-non-recoverable
Refector on_channel_open to accept incoming channels if the source is a trusted zeroconf node
2025-03-04 16:06:55 +00:00
f321x
cb56f0873d improve ChannelType option check 2025-03-04 17:03:55 +01:00
ThomasV
1201b87ad7 Merge pull request #9587 from f321x/jit-invoice-creation
Disable mpp flags in invoice creation if jit channel is required and consider available liquidity
2025-03-04 16:07:54 +01:00
f321x
d62eb7ab13 disable mpp flags in invoice creation if jit channel is required, check against available liquidity if we need a jit channel 2025-03-04 15:24:03 +01:00
ThomasV
96d0dad41c gossip: less log lines, use command line instead 2025-03-04 14:33:54 +01:00
f321x
bc90f517d1 check if channel type before checking if zeroconf option 2025-03-04 14:28:17 +01:00
f321x
6d498667ef add inline method to forward gossip with semaphore 2025-03-04 13:10:37 +01:00
f321x
d348da811a introduce gossip query handling and forwarding 2025-03-04 13:10:37 +01:00
f321x
6a0e537b9c accept incoming channels if its from trusted zeroconf node 2025-02-28 12:56:33 +01:00
Sander van Grieken
7b4180202a add onion message support 2025-02-19 14:29:02 +01:00
SomberNight
ac20422fb7 lnpeer: log their_features in INIT msg 2025-02-06 17:26:26 +00:00
f321x
5eb9aa074e change to separate exception class for too low fees
store exception in variable instead of using a bool flag

add default str to routing exceptions

Add separate exception class to handle fee related payment errors
2025-01-28 16:15:03 +01:00
f321x
41e32145a8 Add maybe_fee_related bool to NoPathFound and set it on instanciation in according places 2025-01-28 15:58:03 +01:00
f321x
e61dee2e65 remove zlib compression in query_short_channel_ids 2025-01-22 13:38:17 +01:00
ThomasV
d25aca7a53 Merge pull request #9447 from f321x/node_ann_dns
Add gossip address field serialization, parsing and tests
2025-01-17 10:52:14 +01:00
ThomasV
64e07732f8 Merge pull request #9430 from SomberNight/202501_funding_pubkey_deriv
lightning: change derivation of funding_pubkey
2025-01-17 10:49:16 +01:00
f321x
1f626f3ad8 add gossip address field serialization, parsing and tests
add space

add gossip address field serialization, parsing and tests

fix linter

consolidate tests, fix intendation

refactor test in loops

add gossip address field serialization, parsing and tests
2025-01-17 10:33:56 +01:00