1
0
Fork 0
mirror of https://github.com/ACINQ/eclair.git synced 2025-02-23 06:35:11 +01:00

Ignore 'tx already in block chain' errors when publishing a tx (#441)

And set more reasonable log levels in `ZmqWatcher`.
This commit is contained in:
Pierre-Marie Padiou 2018-02-16 17:22:03 +01:00 committed by GitHub
parent 57e4f54d3e
commit 82803cab1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -96,18 +96,17 @@ class ZmqWatcher(client: ExtendedBitcoinClient)(implicit ec: ExecutionContext =
// parent tx was published, we need to make sure this particular output has not been spent
client.isTransactionOutputSpendable(txid.toString(), outputIndex, true).collect {
case false =>
log.warning(s"output=$outputIndex of txid=$txid has already been spent")
log.warning(s"looking first in the mempool")
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 {
case Nil =>
log.warning(s"couldn't find spending tx in the mempool, looking into blocks...")
log.warning(s"$txid:$outputIndex has already been spent, spending tx not in the mempool, looking in the blockchain...")
client.lookForSpendingTx(None, txid.toString(), outputIndex).map { tx =>
log.warning(s"found the spending tx in the blockchain: txid=${tx.txid}")
log.warning(s"found the spending tx of $txid:$outputIndex in the blockchain: txid=${tx.txid}")
self ! NewTransaction(tx)
}
case txs =>
log.warning(s"found ${txs.size} spending txs in the mempool: txids=${txs.map(_.txid).mkString(",")}")
log.info(s"found ${txs.size} txs spending $txid:$outputIndex in the mempool: txids=${txs.map(_.txid).mkString(",")}")
txs.foreach(tx => self ! NewTransaction(tx))
}
}
@ -170,7 +169,8 @@ class ZmqWatcher(client: ExtendedBitcoinClient)(implicit ec: ExecutionContext =
def publish(tx: Transaction, isRetry: Boolean = false): Unit = {
log.info(s"publishing tx (isRetry=$isRetry): txid=${tx.txid} tx=$tx")
client.publishTransaction(tx)(singleThreadExecutionContext).recover {
case t: Throwable if t.getMessage.contains("-25") && !isRetry => // we retry only once
case t: Throwable if t.getMessage.contains("(code: -27)") => () // 'transaction already in block chain' isn't an error
case t: Throwable if t.getMessage.contains("(code: -25)") && !isRetry => // we retry only once
import akka.pattern.after
import scala.concurrent.duration._