Commit Graph

410 Commits

Author SHA1 Message Date
SomberNight 21946e1e87 lnpeer: channel_reestablish: split "they_are_ahead" into ctn vs revnum 2026-04-18 17:23:35 +00:00
f321x ac87eea02f test_lnwallet: unittest trampoline invoice_feature and r_tag
Add unittest that verifies we only include r_tags for trampoline nodes
if we signal trampoline support in the invoice_features and only signal
trampoline support if we use trampoline or have only open trampoline
channels.
2026-03-26 12:10:24 +01:00
ThomasV 31c2ffbf64 Merge pull request #10532 from spesmilo/variable_trampoline_onions
trampoline: allow trampoline onion packets of arbitrary size
2026-03-24 12:11:56 +01:00
SomberNight 42ad18b216 rm bip70 support
- could not find a single project that still actually cares about bip70 [0]
    - well except maybe BitPay.
        - but I cannot test with BitPay:
            - they have a testnet3 staging environment on test.bitpay.com
                - but the SSL cert they use for bip70 has expired in 2021
                - the webUI probably also has not been updated since then...
                    - they claim to have added LN support in 2022 in a blog post,
                        but it's not there on test.bitpay.com
            - on mainnet, they require KYC before payment
                - < ... angry noises >
            - their loss then, I don't care.
- this is code that no one wants to maintain

- this does not yet delete the signed bip70 payment data for historical txs
    - but it is no longer possible to export it from the GUI

[0]: https://bitcoinops.org/en/topics/bip70-payment-protocol/
2026-03-20 18:12:55 +00:00
ThomasV 7ee2477b68 Merge pull request #10528 from f321x/qt_swapserver_list_resize
swaps: improve SwapServerDialog, provider CLI, bugfixes
2026-03-19 09:42:05 +01:00
f321x f56e6318e3 swaps: make SwapManager.percentage Decimal
If SwapManager.percentage was a 0.2 float, rounding differences would
cause an exception in the fee calculation inverse sanity check when entering 20
000 sats into the SwapDialog. By making self.percentage a decimal we can
prevent this kind of issue.

```
File "/home/user/code/vibecoding_vm/electrum/electrum/gui/qt/swap_dialog.py", line 294, in on_send_edited
    recv_amount = self.swap_manager.get_recv_amount(send_amount, is_reverse=self.is_reverse)
  File "/home/user/code/vibecoding_vm/electrum/electrum/submarine_swaps.py", line 1320, in get_recv_amount
    if abs(send_amount - inverted_send_amount) > 1:
           ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'
```
2026-03-19 09:17:34 +01:00
ThomasV 558f85296c trampoline: allow trampoline onion packets of arbitrary size 2026-03-19 08:47:07 +01:00
SomberNight 44e99bc1a9 tests: move qml stuff to tests/qml/ 2026-03-16 13:11:48 +00:00
SomberNight b397ddb008 tests: move revealer and timelock_recovery stuff to tests/plugins/ 2026-03-16 00:52:48 +00:00
SomberNight c2f3729424 plugins: timelock_recovery: move checksum func to base class
don't import qt from tests unless it is qt being tested
2026-03-16 00:41:33 +00:00
SomberNight 907ceb9f52 tests: timelock_recovery plugin: add test vector for checksum from bip 2026-03-16 00:35:38 +00:00
Oren 8c5af52c0b test_checksum_non_ascii 2026-03-15 11:25:14 +02:00
SomberNight 1c24c61364 tests: lnpeer: uncomment testcase: test_modern_shutdown_no_overlap
This test case has always been disabled, but looks like the justification is easy to fix.
2026-03-12 19:22:44 +00:00
SomberNight 7e3af72ad6 lnpeer: maybe_send_commitment: impl batching updates 2026-03-11 17:07:23 +00:00
ThomasV e309f89a27 test_lnpeer: factorize test_reestablish_replay_messages 2026-03-06 09:28:05 +01:00
SomberNight db003257ff tests: lnpeer: make mpp_cleanup_after_expiry more robust
As there are two htlcs, the `alice_htlc_resolved` Event might get set either once or twice by the time `alice_htlc_resolved.wait()` returns. The previous code was assuming that both htlcs are resolved by then, but it could happen that only one htlc was resolved, due to timing.
2026-03-04 18:12:53 +00:00
SomberNight fe5cb09e05 wallet_db: convert PaymentInfo amounts from 0 to None
When creating a "zero-amount" payment request, currently we save a PaymentInfo with a "None" amount.
I think there were a few releases in 2023 that saved PaymentInfos with a `0` amount instead. This was changed in #8659 [0], but as said there [1], a DB upgrade was not done.
Now an assert added in [2] is failing due to this inconsistency, for affected old wallets.
- I think to trigger that, one needs a wallet that has a payment request (with a `0` amount) created around that time, which is still unpaid.

This patch tries to restore consistency by enforcing None amounts.

fixes https://github.com/spesmilo/electrum/issues/10501

[0]: https://github.com/spesmilo/electrum/pull/8659
[1]: https://github.com/spesmilo/electrum/pull/8659#issuecomment-1777101285
[2]: https://github.com/spesmilo/electrum/commit/286fc4b86e4d23cb9af15b9061b3d709e7592bcb
2026-03-02 17:12:07 +00:00
f321x 04a034e6ba tests: add unittest for TxBatch._to_sweep_after()
Adds unittest for `TxBatch._to_sweep_after()` anchor claiming part.
2026-02-27 17:18:01 +01:00
ghost43 9a41a5472a Merge pull request #10442 from SomberNight/202601_lnworker_is_preimage_public
lnsweep: simplify maybe_reveal_preimage_for_htlc
2026-02-25 15:35:20 +00:00
SomberNight 0b2c7a8a38 lnsweep: safer maybe_reveal_preimage_for_htlc, add "is_preimage_public"
"When should we reveal preimages onchain?"
This commit tries to simplify the thinking by making the observation:
- we can reveal preimages (actually in any context) if they are already public
- a preimage is public if any other lightning node knows it besides us
  - if we learn the preimage from another LN node, it is public
  - if we send update_fulfill_htlc, it becomes public
  - if we see a preimage onchain, it is public

- in lnsweep._maybe_reveal_preimage_for_htlc:
  - partial mpp check is not relevant if preimage is already public
  - let's just always do KeepWatchingTXO, for sanity/safety

Co-authored-by: ThomasV <thomasv@electrum.org>
2026-02-24 17:49:15 +00:00
ThomasV 6feb992712 Merge pull request #10453 from f321x/debug_rbf_fee_calculation
wallet: estimate base tx feerate based on original base tx size
2026-02-24 16:45:07 +01:00
f321x f1e792cc7b test_wallet_vertical: test bump_fee raises for too low fee
Test that Abstract_Wallet.bump_fee() raises if the given feerate
of the replacement is equal to the feerate of the tx to bump as this
wouldn't be accepted to the mempool.
2026-02-24 14:37:02 +01:00
f321x 6c143fa946 test_wallet_vertical: add test for dscancel fee estimate
Check that dscancel properly raises CannotDoubleSpendTx if the
feerate of the new tx is lower than the tx to be cancelled.
2026-02-24 14:37:01 +01:00
f321x 6e1bf7c4fb test_wallet_vertical: add test for batch tx fee increase
Adds unittest to check the fee increase when adding outputs to a base
tx. Supposed to prevent creating transactions that don't get accepted
like in this traceback:
```
broadcast_transaction error [DO NOT TRUST THIS MESSAGE]: "RPCError(1, 'the transaction was rejected by network rules.\\n\\ninsufficient fee, rejecting replacement ceeaef5ac7f82286e42ebd530e965fa4c7a6c11933d6b89d6d6f0ee2c69db839; new feerate 0.00001109 BTC/kvB <= old feerate 0.00001110 BTC/kvB
```
2026-02-24 14:36:59 +01:00
f321x ddb01f5355 lnpeer: don't save our own channel update as remote upd
I noticed CLN is sending our own channel update to us on
reestablishment, we then assume it to be the remote nodes
update and try to verify the signature against their pubkey
which fails and throws `InvalidGossipMsg`.

This adds a check preventing us from trying to save our own
channel updates as remote update.
2026-02-23 17:12:15 +01:00
ghost43 aefc4aa5b3 Merge pull request #10459 from SomberNight/202602_lnaddr_format_rtags
lnwallet.pay_to_node: log r_tags from invoice
2026-02-09 17:06:21 +00:00
SomberNight 21c1dd8c96 Merge remote-tracking branch 'spesmilo/pr/10451': history export
merges https://github.com/spesmilo/electrum/pull/10451
2026-02-09 16:40:43 +00:00
ThomasV b03d6a478d gossip: broadcast channel updates along with channel announcements
The channel update in mark_open is only sent once, and only to the
channel peer. In addition, it seems to be discarded by Eclair.
2026-02-09 11:00:16 +01:00
ghost43 9644283988 Merge pull request #10441 from f321x/fix_10437
Wizard/qt/qml: validate server address input, fix #10437
2026-02-03 17:09:18 +00:00
f321x a6a57f0fec tests: add unittest for Abstract_Wallet.export_history_to_file
Adds unittest for Abstract_Wallet.export_history_to_file that
compares the output against reference files. This
should help to prevent regressions and ensure the layout
of the export stays static over time.
2026-02-03 18:01:14 +01:00
SomberNight 4d4cff7840 lnwallet.pay_to_node: log r_tags from invoice
and add helper "format_bolt11_routing_info_as_human_readable"
2026-02-03 07:36:20 +00:00
ghost43 b7e58f659a Merge pull request #10448 from f321x/gossip_0126
lnpeermgr: fix proxy check in add_peer, don't connect to onion peers if no proxy
2026-01-29 18:52:10 +00:00
ThomasV 9aa2898c15 test_lnpeer: fix typo in test_reestablish 2026-01-29 14:16:20 +01:00
f321x 79ef429b3c lnworker: don't connect to onion peers if no proxy
When gossip is enabled we waste a lot of time trying to connect
to onion peers if we don't have a proxy enabled. We should just skip
them and try to connect to clearnet peers instead.
2026-01-27 13:14:31 +01:00
f321x db6b6a16f8 lnpeermgr: add_peer: fix check if proxy enabled
LNPeerManager.add_peer would only check if self.network.proxy is set,
which it is always as Network is initialized with self.proxy =
ProxySettings(). Instead it should check if proxy is set and enabled.
2026-01-27 12:49:19 +01:00
f321x 1c5408cccb ServerConnectWizard: don't set autoconnect on user cancel
Don't set the NETWORK_AUTO_CONNECT config if the user checked the custom
server config checkbox and then cancels the wizard, so the next time the
user starts the wizard they again will have the choice instead of
silently being forced into a random server.
Currently if the user cancels the wizard during the network config the
welcome component will already have set the NETWORK_AUTO_CONNECT config
to False (as the user selected the custom server checkbox), preventing
the wizard from starting again on the next startup.
2026-01-26 15:28:54 +01:00
SomberNight 87540dbe3e util.EventListener: store WeakMethods in CallbackManager to avoid leaks
This patch changes the CallbackManager to use WeakMethods (weakrefs) to
break the ref cycle and allow the GC to clean up the wallet objects.
unregister_callbacks() will also get called automatically, from
EventListener.__del__, to clean up the CallbackManager.

I also added a few unit tests for this.

fixes https://github.com/spesmilo/electrum/issues/10427

-----

original problem:

In many subclasses of `EventListener`, such as `Abstract_Wallet`, `LNWatcher`,
`LNPeerManager`, we call `register_callbacks()` in `__init__`.
`unregister_callbacks()` is usually called in the `stop()` method.

Example - consider the wallet object:
- `Abstract_Wallet.__init__()` calls `register_callbacks()`
- there is a `start_network()` method
- there is a `stop()` method, which calls `unregister_callbacks()`
- typically the wallet API user only calls `stop()` if they also called
  `start_network()`.

This means the callbacks are often left registered, leading to the wallet
objects not getting GC-ed. The GC won't clean them up as
`util.callback_mgr.callbacks` stores strong refs to instance methods
of `Abstract_Wallet`, hence strong refs to the `Abstract_Wallet` objects.

An annoying example is `daemon.check_password_for_directory`, which
potentially creates wallet objects for all wallet files in the datadir.
It simply constructs the wallets, does not call `start_network()` and
neither does it call `stop()`.
2026-01-21 17:49:41 +00:00
SomberNight 50b10284ac util.CallbackManager: use sets instead of lists
- to gracefully take duplicate calls of register_callbacks(): should be idempotent now
- as a side-effect, the order of the callbacks is changed and not guaranteed
  - not like anyone should have been relying on it before though
2026-01-20 22:33:21 +00:00
SomberNight 57b26ba473 tests: add basic tests for util.CallbackManager and EventListener 2026-01-20 22:33:18 +00:00
ThomasV fa575ab1fc fix test_onion_message (follow-up previous commit) 2026-01-13 17:36:06 +01:00
ghost43 5778fa401d Merge pull request #10363 from f321x/unittest_lnwallet
tests: add test_lnwallet to test lnwallet utils
2026-01-12 15:20:52 +00:00
f321x dee2371738 test_lnpeer: use PeerInTests instead if Peer
ec65c53 replaces the usage of `PeerInTest` with `Peer` in
test_lnpeer.py.
PeerInTests sets `Peer.DELAY_INC_MSG_PROCESSING_SLEEP` to 0 so all
incoming messages get processed immediately. Because `Peer` instead of
`TestInPeer` was used the delay caused `test_reestablish_with_old_state`
to fail regularly because bob receives the old channel state and kills
the OldTaskGroup of the unittest with GracefulDisconnect before Alice
processed the answer of Bob and is still in ChannelState.REESTABLISHING.

```
FAILED tests/test_lnpeer.py::TestPeerDirect::test_reestablish_with_old_state - AssertionError: <PeerState.REESTABLISHING: 1> != <PeerState.BAD: 3>
```
2026-01-08 14:57:13 +01:00
f321x 562839c540 tests: add TestLNWallet to test lnwallet utils
Adds new unittest file test_lnwallet.py to allow unittesting
utility functions of LNWallet.
2026-01-08 13:16:34 +01:00
SomberNight 927724145a tests: rm some more dead code 2026-01-05 15:56:13 +00:00
SomberNight 0afd433c42 tests: properly clean-up MockLNWallets after tests finish 2026-01-05 15:56:10 +00:00
SomberNight dfeb9918d8 tests: lnchannel: rewrite create_test_channels to use LNWallet 2026-01-05 15:56:04 +00:00
SomberNight 17f41044d5 tests: lnpeer: fix cyclic lnworker.wallet.lnworker inconsistency
These better hold, lol:
wallet.lnworker.wallet == wallet
lnworker.wallet.lnworker == lnworker
2026-01-05 15:56:01 +00:00
SomberNight ea42b02ceb tests: simplify MockLNWallet, add fixme for cyclic inconsistency 2026-01-05 15:55:58 +00:00
SomberNight 91b98240dc tests: lnpeer: follow-up prev: rm horrible ugly hack 2026-01-05 15:55:54 +00:00
SomberNight ec65c53de3 tests: lnpeer: mostly unify prepare_peers and prepare_graph 2026-01-05 15:55:51 +00:00