swaps: SWAP_TX_SIZE: add longer explanation (comment)
What changed, and why it matters
This commit only adds a detailed code comment explaining how a constant named SWAP_TX_SIZE is used to estimate Bitcoin mining fees for submarine swaps. No program logic, numbers, or behavior were changed. It is purely documentation.
No action needed. This is a documentation-only change with no security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds an 11-line comment block above the existing SWAP_TX_SIZE = 150 constant in electrum/submarine_swaps.py. It clarifies that the constant is used for both swap directions, notes a future TODO about asymmetric fees, and explains how tx_batcher independently re-estimates transaction sizes and why advertised base mining fees can be insufficient in edge cases. No executable code was modified.
Changed components
electrum/submarine_swaps.pyInspect captured patch +11 / −0
diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py
index f297497..e26f834 100644
--- a/electrum/submarine_swaps.py
+++ b/electrum/submarine_swaps.py
@@ -61,6 +61,17 @@ if TYPE_CHECKING:
SWAP_TX_SIZE = 150 # default tx size, used for mining fee estimation
+# ^ used for both swap directions. TODO if we had asymmetric fees, the base fee should also be asymmetric.
+# - client-forward-swap: needs to cover server paying for claim_tx
+# - client-reverse-swap: 2x of this needs to cover server paying for funding_tx + potential timeout refund tx
+# (Hence 2x is used for prepayment. But only 1x is added to overall total,
+# as in the happy case, the server only needs to pay for the funding_tx,
+# and the user pays for the claim_tx out-of-pocket.)
+# This is the budget tx_batcher will have to fund/claim/timeout TXOs, however tx_batcher
+# will independently re-estimate tx sizes instead of using this constant. If tx_batcher e.g. creates
+# a large tx consolidating many UTXOs or claiming/funding multiple swaps, it can end up paying more
+# on-chain fees than the nostr-advertised base mining fees. In some cases swap profits can go negative
+# for a server for a given swap (high mempool feerates AND low swap value AND tx_batcher creates tx with many inputs).
MIN_SWAP_AMOUNT_SAT = 20_000
MIN_LOCKTIME_DELTA = 60
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.