From 848ac2b6b372fe1dedbc601cde10178a354ffc5e Mon Sep 17 00:00:00 2001 From: pm47 Date: Tue, 23 Feb 2021 19:12:50 +0100 Subject: [PATCH] call isTransactionOutputSpendable before checking hints --- .../blockchain/bitcoind/ZmqWatcher.scala | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/eclair-core/src/main/scala/fr/acinq/eclair/blockchain/bitcoind/ZmqWatcher.scala b/eclair-core/src/main/scala/fr/acinq/eclair/blockchain/bitcoind/ZmqWatcher.scala index 0d1776f5ff..91b887e707 100644 --- a/eclair-core/src/main/scala/fr/acinq/eclair/blockchain/bitcoind/ZmqWatcher.scala +++ b/eclair-core/src/main/scala/fr/acinq/eclair/blockchain/bitcoind/ZmqWatcher.scala @@ -144,20 +144,21 @@ class ZmqWatcher(chainHash: ByteVector32, blockCount: AtomicLong, client: Extend // first let's see if the parent tx was published or not client.getTxConfirmations(txid).collect { case Some(_) => - // if we know some potential spending txs, we try to fetch them directly - Future.sequence(hints.map(txid => client.getTransaction(txid).map(Some(_)).recover { case _ => None })) - .map(_ - .flatten // filter out errors - .find(tx => tx.txIn.exists(i => i.outPoint.txid == txid && i.outPoint.index == outputIndex)) match { - case Some(spendingTx) => - // there can be only one spending tx for an utxo - log.info(s"$txid:$outputIndex has already been spent by a tx provided in hints: txid=${spendingTx.txid}") - self ! NewTransaction(spendingTx) - case None => - // no luck, we have to do it the hard way... - // parent tx was published, we need to make sure this particular output has not been spent - client.isTransactionOutputSpendable(txid, outputIndex, includeMempool = true).collect { - case false => + // parent tx was published, we need to make sure this particular output has not been spent + client.isTransactionOutputSpendable(txid, outputIndex, includeMempool = true).collect { + case false => + // the output has been spent, let's find the spending tx + // if we know some potential spending txs, we try to fetch them directly + Future.sequence(hints.map(txid => client.getTransaction(txid).map(Some(_)).recover { case _ => None })) + .map(_ + .flatten // filter out errors + .find(tx => tx.txIn.exists(i => i.outPoint.txid == txid && i.outPoint.index == outputIndex)) match { + case Some(spendingTx) => + // there can be only one spending tx for an utxo + log.info(s"$txid:$outputIndex has already been spent by a tx provided in hints: txid=${spendingTx.txid}") + self ! NewTransaction(spendingTx) + case None => + // no luck, we have to do it the hard way... log.info(s"$txid:$outputIndex has already been spent, looking for the spending tx in the mempool") client.getMempool().map { mempoolTxs => mempoolTxs.filter(tx => tx.txIn.exists(i => i.outPoint.txid == txid && i.outPoint.index == outputIndex)) match { @@ -172,9 +173,8 @@ class ZmqWatcher(chainHash: ByteVector32, blockCount: AtomicLong, client: Extend txs.foreach(tx => self ! NewTransaction(tx)) } } - } - } - ) + }) + } } Keep