1
0
Commit Graph

19466 Commits

Author SHA1 Message Date
f321x
923d48f9db lnworker: differentiate PaymentInfo by direction
Allows storing two different payment info of the same payment hash by
including the direction into the db key.
We create and store PaymentInfo for sending attempts and for requests (receiving),
if we try to pay ourself (e.g. through a channel rebalance) the checks
in `save_payment_info` would prevent this and throw an exception.
By storing the PaymentInfos of outgoing and incoming payments separately in
the db this collision is avoided and it makes it easier to reason about
which PaymentInfo belongs where.
2025-12-01 18:39:56 +01:00
SomberNight
828fc569c9 commands: version_info: include openssl version 2025-11-30 06:03:08 +00:00
ghost43
d17bb016ef Merge pull request #10330 from SomberNight/202511_lnsweep_refactor_preimage
lnsweep: factor out "maybe_reveal_preimage_for_htlc"
2025-11-28 16:57:05 +00:00
SomberNight
ef8fd03e8f lnsweep: factor out "maybe_reveal_preimage_for_htlc"
no functional changes
2025-11-28 15:55:35 +00:00
ghost43
125b7ee0d7 Merge pull request #10319 from f321x/fix_lightning_num_sats_can_send
lnworker: use config lightning fee for estimate
2025-11-28 15:35:05 +00:00
f321x
c575abc8e2 qt: update tabs on exit of SettingsDialog
Update the tabs after the SettingsDialog gets closed, some values might
have to be updated according to the new configuration.
2025-11-28 16:25:39 +01:00
f321x
af4dc24d87 lnworker: use config lightning fee for estimate
I was unable to do a "Max" amount submarine swap because the
`fee_estimate` method used by `LNWallet.num_sats_can_send()` uses a
hardcoded `fee_proportional_millionths` to estimate the fee for the
lightning payment.
When the actual fee determined later is higher
than the estimated fee the payment fails as the channel is unable to add
the htlc sum including the real fees as the amount exceeds the balance of
the channel.
Using the fees the maximum fees user has configured and estimate the
potential fee as inverse of PaymentFeeBudget is more
reliable/conservative as we definitely aren't going to pay more fees
than this amount.
2025-11-28 16:25:34 +01:00
ThomasV
bcbc1b4e6e Merge pull request #10328 from f321x/improve_lnfee_slider
qt: SettingsDialog: update ln fee config on slider moved
2025-11-28 14:06:13 +01:00
ThomasV
128026a442 SwapProvidersButton class
factorize code that is used in both SwapDialog and Submarine payments
2025-11-28 13:31:14 +01:00
ThomasV
8bec3eafd2 swaps dialog: in callbacks, update either send or receive field, depending on which one follows
before this, the content of the non-following field could be modified by callbacks
2025-11-28 10:49:23 +01:00
f321x
088f273d9b qt: SettingsDialog: update ln fee config on slider moved
When moving the lightning fee slider in the SettingsDialog by clicking
on the range instead of pulling the slider the new fee value wouldn't
get stored in the config as the sliderRelased signal is only emitted
when the slider is pulled.
This change updates it on valueChanged.
2025-11-28 09:55:32 +01:00
ghost43
3f45c41981 Merge pull request #10230 from f321x/refactor_htlc_handling
lightning: refactor htlc switch
2025-11-27 17:26:53 +00:00
ghost43
09af77872f Merge pull request #10327 from f321x/followup_10303
swaps: followup 10303
2025-11-27 17:25:22 +00:00
f321x
59586d6f94 tests: lnpeer: add test_payment_with_malformed_onion
Adds a simple forwarding test where the receiver fails a malformed onion with
`update_fail_malformed_htlc`.
2025-11-27 17:58:51 +01:00
f321x
16ed7e666c lnpeer: use INVALID_ONION_VERSION for unparsable onions
Use the `OnionFailureCode.INVALID_ONION_VERSION` (BADONION | PERM | 4)
code when sending back `update_fail_malformed_htlc` as just sending a plain
`BADONION` is not explicitly mentioned as correct in the spec.
2025-11-27 17:58:49 +01:00
f321x
1fd5458b0e tests: lnpeer: test_dont_expire_htlcs
Adds unittest to test the dont_expire_htlcs logic
2025-11-27 17:58:47 +01:00
f321x
4f2e1b65f0 tests: test_lnpeer: add test_dont_settle_htlcs
Adds test for the dont_settle_htlcs functionality of lnworker used by
Just-In-Time channels.
2025-11-27 17:58:46 +01:00
f321x
abc469c846 lnworker: split dont_settle_htlcs
Splits `LNWallet.dont_settle_htlcs` into `LNWallet.dont_settle_htlcs`
and `LNWallet.dont_expire_htlcs`.

Registering a payment hash in dont_settle_htlcs will prevent it from
getting fulfilled if we have the preimage stored. The preimage will not
be released before the the payment hash gets removed from
dont_settle_htlcs. Htlcs can still get expired as usual or failed if no
preimage is known.
This is only used by Just-in-time channel openings.

Registering a payment hash in dont_expire_htlcs allows to overwrite the
minimum final cltv delta value after which htlcs would usually get
expired. This allows to delay expiry of htlcs or, if the value in the
dont_settle_htlcs dict is None, completely prevent expiry and let the
htlc get expired onchain.

Splitting this up in two different dicts makes it more explicit and
easier to reason about what they are actually doing.

 Please enter the commit message for your changes. Lines starting
2025-11-27 17:58:44 +01:00
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
3d0ba33652 swaps: followup 10303
small followup replacing tx height integers with const variables and
considering claim tx broadcast too if there is an unconfirmed parent
(height -1).
2025-11-27 17:44:49 +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