From 4768ba608eeb6c9a3501353981a512d40242862d Mon Sep 17 00:00:00 2001 From: Pierre-Marie Padiou Date: Mon, 8 Jan 2024 13:45:11 +0100 Subject: [PATCH] Filter out txs that are too big for swap-in (#580) There is a 65000 bytes limit for transactions, because they must fit in Lightning messages during interactive-tx negotiation. --- .../fr/acinq/lightning/blockchain/electrum/SwapInManager.kt | 4 +++- .../kotlin/fr/acinq/lightning/channel/InteractiveTx.kt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/commonMain/kotlin/fr/acinq/lightning/blockchain/electrum/SwapInManager.kt b/src/commonMain/kotlin/fr/acinq/lightning/blockchain/electrum/SwapInManager.kt index 2c652d922..3cfc32aab 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/blockchain/electrum/SwapInManager.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/blockchain/electrum/SwapInManager.kt @@ -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 @@ -38,7 +40,7 @@ class SwapInManager(private var reservedUtxos: Set, 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}" } diff --git a/src/commonMain/kotlin/fr/acinq/lightning/channel/InteractiveTx.kt b/src/commonMain/kotlin/fr/acinq/lightning/channel/InteractiveTx.kt index 301f4aa7f..22c1aedca 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/channel/InteractiveTx.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/channel/InteractiveTx.kt @@ -255,7 +255,7 @@ data class FundingContributions(val inputs: List, 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, localOutputs: List): Int {