1
0
Commit Graph

24 Commits

Author SHA1 Message Date
SomberNight
f337b4782d lnwatcher: keep watching sweep TXOs that are dust due to high fees
- if fee estimates are high atm, some outputs are not worth to sweep
- however, fee estimates might be only-temporarily very high
  - previously in such a case lnwatcher would just discard outputs as dust,
    and mark the channel REDEEMED (and hence never watch it or try again)
  - now, instead, if the outputs would not be dust if fee estimates were lower,
    lnwatcher will keep watching the channel
    - and if estimates go down, lnwatcher will sweep them then
- relatedly, previously txbatcher.is_dust() used allow_fallback_to_static_rates=True,
    and it erroneously almost always fell back to the static rates (150 s/b) during
	startup (race: lnwatcher was faster than the network managed to get estimates)
	- now, instead, txbatcher.is_dust() does not fallback to static rates,
	  and the callers are supposed to handle NoDynamicFeeEstimates.
	  - I think this makes much more sense. The previous meaning of "is_dust"
	    with the fallback was weird. Now it means: "is dust at current feerates".

fixes https://github.com/spesmilo/electrum/issues/9980
2025-07-08 14:02:52 +00:00
SomberNight
2b92e8a97a txbatcher: add type-hints 2025-06-26 14:10:18 +00:00
ThomasV
2dfe3cf6d8 txbatcher: add comment about batch_input.pop 2025-06-10 13:30:47 +02:00
ThomasV
1bf1de36cb txbatcher:
- add base_tx to wallet before broadcasting
 - remove base_tx in find_base_tx, it is local
 - add unit test in test_tx_batcher
2025-06-06 10:16:32 +02:00
ThomasV
d0c429e87f txbatcher: fix max() over empty list 2025-05-29 19:53:49 +02:00
SomberNight
197933debf adb.get_tx_height: return "LOCAL" height if missing full signed tx
get_tx_height previously did not consider whether the walletDB has the full tx for
the corresponding txid, and could consider a tx even "mined" and spv-ed, even if
we were missing the raw tx.
Now if the full tx is missing or the tx in the db is partial,
get_tx_height considers it to be LOCAL.

In particular the txbatcher, in `run_iteration`,
- first saves a tx as local *unsigned* (to reserve UTXOs),
- then signs it and tries to broadcast it.

The history tx will later transition to local and signed,
after we get back the broadcasted tx via the Synchronizer dance.
In the meantime there is a race where we have an unsigned tx in the history,
but the txid could already transition to mempool or even to mined,
before we download the full raw tx from the server.
During that time window, it makes the adb state more consistent
to just consider the history tx to be local, as done here.
2025-05-26 16:57:51 +00:00
ThomasV
58480a69db TxBatcher: store fee policy names instead of fee descriptors
This allows to change the fee policy of batches dynamically.
Config.fee_policy is a mapping between policy names and descriptors.
2025-05-26 13:30:25 +02:00
ThomasV
ce8242c29c txbatcher: remove fixme 2025-05-25 09:47:36 +02:00
ThomasV
25dabf3105 txbatcher: if we raise NotEnoughFunds, remove
the largest output from the current tx and retry

In the unit test, this results in waiting until the current tx is mined.
2025-05-23 17:11:56 +02:00
ThomasV
6e3f173a71 SweepInfo: define csv_delay as property 2025-05-13 08:50:33 +02:00
ThomasV
0607a406ce Qt: add closing warning if we have an unconfirmed local commitment tx with htlcs
add htlc direction (offered, received) to the htlc sweep_info name
regtest: add test_reedeem_received_htlcs
2025-05-12 15:48:20 +02:00
ThomasV
7d6c21f233 txbatcher: fix wanted_height shown in GUI
if an input has both CSV and CLTV, we must display the highest value
2025-05-12 13:46:27 +02:00
ThomasV
148518a1f2 txbatcher: sanity check csv_delay
follow-up 8319a855a9
2025-05-12 13:04:30 +02:00
ThomasV
02914e444a txbatcher: add_info_from_wallet in _new_base_tx
37.23 | E | txbatcher.TxBatch | TxBatch error: AttributeError("'TxOutput' object has no attribute 'is_change'")
Traceback (most recent call last):
  File "/opt/electrum/electrum/txbatcher.py", line 248, in run
    await self.run_iteration()
  File "/opt/electrum/electrum/txbatcher.py", line 379, in run_iteration
    base_tx = self.find_base_tx()
  File "/opt/electrum/electrum/txbatcher.py", line 369, in find_base_tx
    self._new_base_tx(tx)
  File "/opt/electrum/electrum/json_db.py", line 48, in wrapper
    return func(self, *args, **kwargs)
  File "/opt/electrum/electrum/txbatcher.py", line 518, in _new_base_tx
    if tx.has_change():
  File "/opt/electrum/electrum/transaction.py", line 1276, in has_change
    return len(self.get_change_outputs()) > 0
  File "/opt/electrum/electrum/transaction.py", line 1273, in get_change_outputs
    return  [o for o in self._outputs if o.is_change]
  File "/opt/electrum/electrum/transaction.py", line 1273, in <listcomp>
    return  [o for o in self._outputs if o.is_change]
AttributeError: 'TxOutput' object has no attribute 'is_change'
2025-05-08 19:34:51 +02:00
ThomasV
7bcc7fb0c4 txbatcher: do not require password in memory
- if password is needed, await future and request it from GUI
 - run asyncio task for each TxBatch, so that batches can
   request the password concurrently
2025-05-06 13:04:19 +02:00
ThomasV
c6a5f4f084 txbatcher: do not sweep anchor outputs if ctx has been mined 2025-04-22 16:39:38 +02:00
ThomasV
5bea2c6f6c TxBatcher: detect if base tx has been replaced.
Alow user to bump fee of txbatcher transaction from GUI
2025-04-22 14:12:05 +02:00
ThomasV
22b3d78c9f txbatcher: fix add make_witness 2025-04-20 17:26:40 +02:00
f321x
03018fa218 make txbatcher wait for network connection 2025-04-04 11:43:24 +02:00
SomberNight
2807be08c8 tests/test_txbatcher.py: de-duplicate "create wallet" logic 2025-04-01 15:00:23 +00:00
SomberNight
977d8b1dd6 wallet: kill create_transaction 2025-03-14 17:19:41 +00:00
SomberNight
3c3778db9c wallet: towards killing create_transaction: rm "sign" arg 2025-03-14 16:44:46 +00:00
ThomasV
ba2e4ff99a txbatcher: set wanted height for future tx that has unconfirmed parent
also, do not unset it in the subsequent if statement
2025-03-14 09:05:21 +01:00
ThomasV
bdb7a82220 batch payment manager:
The class TxBatcher handles the creation, broadcast and replacement
of replaceable transactions. Callers (LNWatcher, SwapManager) use
methods add_payment_output and add_sweep_info. Transactions
created by TxBatcher may combine sweeps and outgoing payments.

Transactions created by TxBatcher will have their fee bumped
automatically (this was only the case for sweeps before).

TxBatcher manages several TxBatches. TxBatches are created
dynamically when needed.

The GUI does not touch txbatcher transactions:
  - wallet.get_candidates_for_batching excludes txbatcher
    transactions
  - RBF dialogs do not work with txbatcher transactions

wallet:
  - instead of reading config variables, make_unsigned_transaction
    takes new parameters: base_tx, send_change_to_lighting

tests:
  - unit tests in test_txbatcher.py (replaces test_sswaps.py)
  - force all regtests to use MPP, so that we sweep transactions
    with several HTLCs. This forces the payment manager to aggregate
    first-stage HTLC tx inputs. second-stage are not batched for now.
2025-03-13 10:17:10 +01:00