Skip to content

Commit

Permalink
Filter out txs that are too big for swap-in (#580)
Browse files Browse the repository at this point in the history
There is a 65000 bytes limit for transactions, because they must fit in
Lightning messages during interactive-tx negotiation.
  • Loading branch information
pm47 authored Jan 8, 2024
1 parent 82c6b82 commit 4768ba6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package fr.acinq.lightning.blockchain.electrum

import fr.acinq.bitcoin.OutPoint
import fr.acinq.bitcoin.Transaction
import fr.acinq.bitcoin.TxId
import fr.acinq.lightning.Lightning
import fr.acinq.lightning.SwapInParams
import fr.acinq.lightning.channel.FundingContributions.Companion.stripInputWitnesses
import fr.acinq.lightning.channel.LocalFundingStatus
import fr.acinq.lightning.channel.RbfStatus
import fr.acinq.lightning.channel.SignedSharedTransaction
Expand Down Expand Up @@ -38,7 +40,7 @@ class SwapInManager(private var reservedUtxos: Set<OutPoint>, private val logger
val utxos = buildSet {
// some utxos may be used for swap-in even if they are not confirmed, for example when migrating from the legacy phoenix android app
addAll(availableWallet.all.filter { cmd.trustedTxs.contains(it.outPoint.txid) })
addAll(availableWallet.deeplyConfirmed)
addAll(availableWallet.deeplyConfirmed.filter { Transaction.write(it.previousTx.stripInputWitnesses()).size < 65_000 })
}.toList()
if (utxos.balance > 0.sat) {
logger.info { "swap-in wallet: requesting channel using ${utxos.size} utxos with balance=${utxos.balance}" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ data class FundingContributions(val inputs: List<InteractiveTxInput.Outgoing>, v
}

/** Strip input witnesses to save space (there is a max size on txs due to lightning message limits). */
private fun Transaction.stripInputWitnesses(): Transaction = copy(txIn = txIn.map { it.updateWitness(ScriptWitness.empty) })
fun Transaction.stripInputWitnesses(): Transaction = copy(txIn = txIn.map { it.updateWitness(ScriptWitness.empty) })

/** Compute the weight we need to pay on-chain fees for. */
private fun computeWeightPaid(isInitiator: Boolean, sharedInput: SharedFundingInput?, sharedOutputScript: ByteVector, walletInputs: List<WalletState.Utxo>, localOutputs: List<TxOut>): Int {
Expand Down

0 comments on commit 4768ba6

Please sign in to comment.