Skip to content

txbatcher: don't spend anchors if ctx fee is already sufficient#10093

Merged
SomberNight merged 2 commits intospesmilo:masterfrom
f321x:anchor_output_sweeping_lower_fee
Feb 28, 2026
Merged

txbatcher: don't spend anchors if ctx fee is already sufficient#10093
SomberNight merged 2 commits intospesmilo:masterfrom
f321x:anchor_output_sweeping_lower_fee

Conversation

@f321x
Copy link
Member

@f321x f321x commented Jul 31, 2025

If the tx fee of the ctx is already higher than the required target it is not useful to spend the anchor so instead it is skipped.

As a side effect the closing tx is not shown in the history anymore until any output got claimed, only the lightning part of the closing group is shown, but the closing tx can be found in the channel details:
image
This is because sweep_commitment_transaction only adds the anchor and to_local outputs to the accounting addresses once there is a (nonlocal) spending tx, so it is missed by get_onchain_history(), same issue(?) for SRK channels. However only declaring them "accounting address" after the sweep seems intentional:

self._accounting_addresses = set() # addresses counted as ours after successful sweep

@f321x f321x force-pushed the anchor_output_sweeping_lower_fee branch 2 times, most recently from 5a65984 to bcea3eb Compare August 4, 2025 14:58
@f321x f321x force-pushed the anchor_output_sweeping_lower_fee branch from bcea3eb to 27603e9 Compare September 1, 2025 10:12
@f321x f321x changed the title txbatcher: don't spend anchors if ctx fee is sufficient already txbatcher: don't spend anchors if ctx fee is already sufficient Sep 24, 2025
@f321x f321x force-pushed the anchor_output_sweeping_lower_fee branch 2 times, most recently from 7549a43 to 531feb1 Compare October 31, 2025 15:21
self.logger.info(f"anchor not needed {prevout}")
self.batch_inputs.pop(prevout) # note: if the input is already in a batch tx, this will trigger assert error
continue
prev_tx_current_fee = self.wallet.adb.get_tx_fee(prev_txid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: I believe currently it just so happens that this does not occur here, but adb.get_tx_fee in some cases trusts the electrum server for the fee instead of calculating it itself.
Atm this does not seem to be the case as all the addresses watched by lnwatcher count as adb.is_mine and this includes the anchor outputs.

If the tx fee of the ctx is already higher than the required target it
is not useful to spend the anchor with a lower fee (the current target),
so instead it is skipped.
Adds unittest for `TxBatch._to_sweep_after()` anchor claiming part.
@f321x f321x force-pushed the anchor_output_sweeping_lower_fee branch from 531feb1 to 04a034e Compare February 27, 2026 16:18
@SomberNight SomberNight merged commit ff44d4b into spesmilo:master Feb 28, 2026
10 of 16 checks passed
@f321x f321x deleted the anchor_output_sweeping_lower_fee branch February 28, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants