1
0
Commit Graph

19447 Commits

Author SHA1 Message Date
f321x
b1e58450bd tests: test_lnpeer: add test_payment_bundle_with_hold_invoice
Adds test_payment_bundle_with_hold_invoice to simulate the use of a
payment bundle in which one invoice of the bundle needs to trigger a hold invoice
callback (similar to submarine swaps).
Also modifies the test helper _test_simple_payment() to compare the
results of all payment attempts instead of just returning after the
first (of multiple) payments raises its result causing the test to miss
if all payments were successful or not.
2025-11-27 17:58:43 +01:00
f321x
95729a08ef lnpeer: report htlc_switch exceptions to crash reporter
It seems useful to report exceptions happening in the htlc_switch to the
crash reporter as it shouldn't raise exceptions in theory and this could
help catch subtle bugs.
2025-11-27 17:58:41 +01:00
f321x
042557da9b tests: test_lnpeer: test_htlc_switch_iteration_benchmark
Benchmark how long a call to _run_htlc_switch_iteration takes with 10
trampoline mpp sets of 1 htlc each.
2025-11-27 17:58:40 +01:00
f321x
f56b13b610 tests: test_lnpeer: test_hold_invoice_set_doesnt_get_exp
Add test `test_hold_invoice_set_doesnt_get_expired` to test_lnpeer to
ensure a mpp set on which a hold invoice callback doesn't get expired
automatically if the cltv_abs falls below MIN_FINAL_CLTV_DELTA_ACCEPTED
as these sets should only get failed if the htlcs are safe to fail by
the target of the hold invoice callback (e.g. swap got refunded
successfully).
2025-11-27 17:58:38 +01:00
f321x
bb828097b3 tests: test_lnpeer: test compare trampoline onions
Adds test_forwarder_fails_for_inconsistent_trampoline_onions
which checks that a forwarder compares the trampoline onions of a mpp
set and fails the set if the onions are not similar.
In the test alice sends a mpp through bob with 2 htlcs, in one
trampoline onion amt_to_forward is off by 1 msat so bob fails the htlc
set instead of initiating the trampoline forwarding.
2025-11-27 17:58:34 +01:00
f321x
447d91d7b6 tests: lnpeer: test_trampoline_mpp_consolidation_forwarding_amount
Add sanity check that bob is not forwarding more sats to carol if than
he receives from alice. (he only forwards once and doesn't try to
forward multiple times).
This should get caught by asserts in lnworker/lnpeer, nevertheless it
seems to make sense to just add this test to prevent regressions of this
kind.
2025-11-27 17:57:26 +01:00
f321x
f35b353841 tests: lnpeer: test_mpp_cleanup_after_expiry
1. Alice sends two HTLCs to Bob, not reaching total_msat,
   and eventually they MPP_TIMEOUT
2. Bob fails both HTLCs
3. Alice then retries and sends HTLCs again to Bob, for the same RHASH,
   this time reaching total_msat, and the payment succeeds

Test that the sets are properly cleaned up after MPP_TIMEOUT
and the sender gets a second chance to pay the same invoice.
2025-11-27 17:57:25 +01:00
f321x
a91f7c519f tests: lnpeer: test_dont_settle_partial_mpp_trigger_with_invalid_cltv_htlc
Adds unittest to verify that lnpeer doesn't settle any htlcs of
incomplete mpp.
2025-11-27 17:57:23 +01:00
f321x
a7de8de5a2 tests: lnpeer: test_reject_multiple_payments_of_same_invoice
Test that lnpeer rejects incoming htlcs for payments that have already
been paid so invoices cannot be paid twice.
2025-11-27 17:57:21 +01:00
f321x
7840df2e0d tests: lnpeer: test_reject_payment_for_expired_invoice
Test that lnpeer is rejecting incoming htlcs for invoices that are
already expired.
2025-11-27 17:57:19 +01:00
f321x
da5f59903d tests: lnpeer: test_reject_invalid_min_final_cltv_delta
Add `test_reject_invalid_min_final_cltv_delta` which is supposed to test
that the peer rejects incoming htlcs with final cltv delta differing
from what has been requested in the lightning invoice.
2025-11-27 17:57:18 +01:00
f321x
0f314d1dd9 lnpeer/lnworker: refactor htlc_switch
refactor `htlc_switch` to new architecture to make it more robust
against partial settlement of htlc sets and increase maintainability.
Htlcs are now processed in two steps, first the htlcs are collected into
sets from the channels, and potentially failed on their own already.
Then a second loop iterates over the htlc sets and finalizes only on
whole sets.

# Conflicts:
#	electrum/lnpeer.py
2025-11-27 17:57:14 +01:00
f321x
41d391a617 Fix: For inner trampoline onions amt_to_forward can be larger than the htlc amount
Add unittest to TestPeerForwarding which sends a multi trampoline
payment.

Wait another htlc_switch iteration in tests because trampolines might have different delays
2025-11-27 17:44:31 +01:00
SomberNight
bc2bd48516 qml: (trivial) QEConfig.formatMilliSats: conv unused fallback to assert 2025-11-27 16:14:52 +00:00
ghost43
8358a17ebb Merge pull request #10325 from f321x/debug_not_enough_balance
lightning: fix race when doing concurrent payments
2025-11-27 16:06:52 +00:00
ghost43
2c46cf0ebd Merge pull request #10321 from accumulator/qml_msat_precision
qml millisat precision fix
2025-11-27 15:46:34 +00:00
f321x
196cc33c1c ln: fix race when doing concurrent ln payments
There is a race when initiating multiple lightning payments concurrently
(e.g. when doing a reverse swap with prepayment + swap payment).
suggest_splits might overallocate
split amounts for a channel as the splitting of both invoice amounts runs
concurrently and before acutal htlcs that reduce the channels balance
have been added to the channel yet. This results in a "not
enough balance" PaymentFailure once we try to send the htlcs and the
other payment attempt already reduced the available balance of the
channel.

This fix takes a lock from splitting the amount until the htlcs are
put on the channel, so suggest_splits always acts on the correct channel
balance.
2025-11-27 16:43:40 +01:00
ghost43
10fc366688 Merge pull request #10326 from accumulator/fix_10324
run_electrum: proxy command line option implies proxy enabled
2025-11-27 15:24:27 +00:00
Sander van Grieken
3a9e3848e8 run_electrum: proxy command line option implies proxy enabled (fixes #10324) 2025-11-27 16:10:32 +01:00
Sander van Grieken
c519083b9b qml: show lightning invoice amounts with msat precision, allow msat precision entry for no-amount lightning invoices 2025-11-27 12:38:57 +01:00
Sander van Grieken
e137c888a1 qeconfig: fix btc amount regex, add msat regex property, add regex tests 2025-11-27 12:38:49 +01:00
Sander van Grieken
93c9dd9d12 qml: refactor invoice amount checks, msat precision for lightning.
add qeconfig unit tests for conversion methods.
2025-11-27 12:38:49 +01:00
Sander van Grieken
0f2a41e078 simple_config: factor out self.decimal_point and self.get_decimal_point() in favor of self.BTC_AMOUNTS_DECIMAL_POINT 2025-11-27 12:38:49 +01:00
ThomasV
c8dc4a557c Merge pull request #10303 from f321x/submarine_payment_func
swaps/qt: expose swaps to external address
2025-11-27 11:39:09 +01:00
f321x
3b80795e9c qt: move pubkey_to_q_icon in qt.util
Move the pubkey_to_q_icon utility function from qt.swap_dialog in
qt.util.
2025-11-27 11:31:10 +01:00
f321x
8a70fdcb81 qt: expose swaps to address as Submarine Payments
Exposes reverse submarine swaps to an external/specific address in the
TxEditor gui as "Submarine Payments". The user can enter a onchain
address in the Send Tab and then pay it from the lightning balance in
the send tab by enabling the Submarine Payments option in the TxEditor
dialog menu and switching to the Submarine Payment tab in the Tab bar.
2025-11-27 11:17:53 +01:00
ThomasV
9f50d2a61d Merge pull request #10276 from f321x/2fa_conf_qt
trustedcoin: qt: set higher minimumHeight for QR component
2025-11-27 10:39:42 +01:00
f321x
a0455f8382 swaps: allow reverse swaps to external address
Implement logic to claim a reverse swap funding output to any given
address. This allows to do onchain payments to external recipients
through a submarine swap.
2025-11-27 09:50:04 +01:00
SomberNight
d7bc617034 lnonion: add OnionFailureCode.from_int() helper 2025-11-26 17:17:59 +00:00
Sander van Grieken
30f2bc9eb8 lnonion: work around immutability of OnionHopsDataSingle 2025-11-25 15:26:34 +01:00
Sander van Grieken
23d5ed87e7 onion_message: move encrypt_onionmsg_tlv_hops_data() to lnonion as encrypt_hops_recipient_data()
and add support payloads other than onionmsg_tlv
2025-11-25 15:15:12 +01:00
f321x
a6e103b63c lnonion:
add helper properties
 minor refactoring
2025-11-25 13:14:57 +01:00
f321x
c65ec6b2b9 add helper method: run_htlc_switch_iteration
no code modification, indent-only
2025-11-25 13:14:46 +01:00
ThomasV
d36b753cfe remove plugin payserver (moved to spesmilo/electrum-payserver) 2025-11-25 11:40:25 +01:00
ghost43
530260638a Merge pull request #10317 from f321x/fix_payto
cli: payto: fix feerate parsing
2025-11-21 18:37:08 +00:00
ghost43
dabf5bb183 Merge pull request #10316 from SomberNight/202511_trampoline_recursion
lnonion: explicitly forbid nesting trampoline-in-trampoline
2025-11-21 18:19:25 +00:00
SomberNight
4fedab8bba fix tests: follow-up prev 2025-11-21 18:16:59 +00:00
Sander van Grieken
d92b0c74a3 onion_message: num_hops in blinded path is byte, not int. 2025-11-21 17:19:02 +01:00
SomberNight
c288656dc0 trampoline: when sending payment, log "is_legacy" (e2e vs pay2legacy) 2025-11-21 15:45:33 +00:00
f321x
114c48e452 cli: payto: fix feerate parsing
Feerate is passed to `Commands._get_fee_policy()` as str which then
tried to multiply the string by 1000. Now it first casts the string to
`Decimal` and multiplies the decimal.

Fixes https://github.com/spesmilo/electrum/issues/10315
2025-11-19 17:38:58 +01:00
SomberNight
ecd1b7ade8 lnonion: explicitly forbid nesting trampoline-in-trampoline
This assert is needed because I don't want to reason about
what could happen without it.

We currently use fixed 400 bytes trampoline onion sizes, which would
implicitly prevent this. However the current bolts PR actually specifies
variable size trampoline onions.
2025-11-19 16:28:50 +00:00
ThomasV
30d34238e6 Merge pull request #10307 from SomberNight/202511_qml_feehistogram_colours
qml: fee histogram colours: extend colour palette to cover sub-1 s/b
2025-11-19 17:27:48 +01:00
ghost43
d15598bcf0 Merge pull request #10313 from SomberNight/202511_keystore_lrucache
keystore: fix memory leak for LRU cache
2025-11-18 18:25:31 +00:00
SomberNight
c919d4940a keystore: fix memory leak for LRU cache
Using `@functools.lru_cache` on an instance method behaves in interesting ways.
The cache kept a ref around for `self`, so in effect we were never GC-ing keystore objects. Effectively there was a single global cache for derive_pubkey, with keys `(keystore, for_change, n)`.

This PR now changes the caching to be per-keystore:
each ks has a cache, keyed `(for_change, n)`.
GC-ing individual keystores should now be possible, which should result in cleaning up just their own cache.

This also enables the corresponding previously silence flake8-bugbear check for `@functools.lru_cache`. (note that the check can selectively be disabled by adding a comment on the relevant line: `# noqa: B019`)
2025-11-18 17:06:42 +00:00
SomberNight
bdb7a3566f ci: update flake8 2025-11-18 17:02:23 +00:00
ghost43
ee80065bb8 Merge pull request #10312 from SomberNight/202511_pr10230_1
lnonion: immutable OnionPacket and OnionHopsDataSingle
2025-11-18 16:41:19 +00:00
SomberNight
1b600b49e9 lnmsg/lnonion: follow-up prev: "hide" MappingProxyType usage 2025-11-18 14:54:33 +00:00
ghost43
c09b3d2b2a Merge pull request #10311 from SomberNight/202511_tests_mixed_spend
test_wallet_vertical: add case spending mixed segwit/non-segwit UTXOs
2025-11-18 14:01:25 +00:00
SomberNight
e52ed5073e test_wallet_vertical: add case spending mixed segwit/non-segwit UTXOs
I needed such a tx to test something in electrumx and wanted to copy-paste one from the electrum unit tests. Weird that we were lacking such a test case, I was fairly certain there was one already...
2025-11-17 19:20:36 +00:00
SomberNight
e6071bbf5d qml: fee histogram colours: extend colour palette to cover sub-1 s/b
Currently on master the qml fee histogram colours are calculated for feerates clamped to [1, 600] sat/vbyte. I want to extend it to now cover [0, 600] sat/vbyte.
I would like to extend it in a way that does not change the existing colour meanings/mapping, so not just e.g. doing an offset.

follow-up bd6dfc53a2
2025-11-15 01:46:31 +00:00