Skip to content

Commit

Permalink
fixup! Check funding confirmation in offline
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bast committed Aug 18, 2022
1 parent d5d0e36 commit f49116a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1114,12 +1114,14 @@ class Channel(val nodeParams: NodeParams, val wallet: OnChainChannelFunder, val
val localCommitPublished = Closing.LocalClose.claimCommitTxOutputs(keyManager, commitments1, commitTx, nodeParams.currentBlockHeight, nodeParams.onChainFeeConf)
val d1 = DATA_CLOSING(commitments1, None, d.waitingSince, alternativeCommitments = Nil, mutualCloseProposed = Nil, localCommitPublished = Some(localCommitPublished))
stay() using d1 storing() calling doPublish(localCommitPublished, commitments1)
case None if d.commitments.commitInput.outPoint.txid == w.tx.txid =>
// The best funding tx candidate has been confirmed, we can forget alternative commitments.
stay() using d.copy(alternativeCommitments = Nil)
case None =>
log.warning("an unknown funding tx with txid={} got confirmed, this should not happen", w.tx.txid)
stay()
if (d.commitments.commitInput.outPoint.txid == w.tx.txid) {
// The best funding tx candidate has been confirmed, we can forget alternative commitments.
stay() using d.copy(alternativeCommitments = Nil) storing()
} else {
log.warning("an unknown funding tx with txid={} got confirmed, this should not happen", w.tx.txid)
stay()
}
}

case Event(WatchFundingSpentTriggered(tx), d: DATA_CLOSING) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
package fr.acinq.eclair.channel.fsm

import akka.actor.typed.scaladsl.adapter.{ClassicActorContextOps, actorRefAdapter}
import fr.acinq.bitcoin.ScriptFlags
import fr.acinq.bitcoin.scalacompat.{SatoshiLong, Script, Transaction}
import fr.acinq.bitcoin.scalacompat.{SatoshiLong, Script}
import fr.acinq.eclair.blockchain.bitcoind.ZmqWatcher._
import fr.acinq.eclair.channel.Helpers.Funding
import fr.acinq.eclair.channel.InteractiveTxBuilder.{FullySignedSharedTransaction, InteractiveTxParams, PartiallySignedSharedTransaction}
Expand All @@ -30,7 +29,6 @@ import fr.acinq.eclair.wire.protocol._
import fr.acinq.eclair.{Features, RealShortChannelId}

import scala.concurrent.duration.DurationInt
import scala.util.{Failure, Success, Try}

/**
* Created by t-bast on 19/04/2022.
Expand Down Expand Up @@ -389,20 +387,13 @@ trait ChannelOpenDualFunded extends DualFundingHandlers with ErrorHandlers {
val allFundingTxs = DualFundingTx(d.fundingTx, d.commitments) +: d.previousFundingTxs
allFundingTxs.find(_.commitments.commitInput.outPoint.txid == confirmedTx.txid) match {
case Some(DualFundingTx(_, commitments)) =>
Try(Transaction.correctlySpends(commitments.fullySignedLocalCommitTx(keyManager).tx, Seq(confirmedTx), ScriptFlags.STANDARD_SCRIPT_VERIFY_FLAGS)) match {
case Success(_) =>
log.info(s"channelId=${commitments.channelId} was confirmed at blockHeight=$blockHeight txIndex=$txIndex with funding txid=${commitments.commitInput.outPoint.txid}")
watchFundingTx(commitments)
context.system.eventStream.publish(TransactionConfirmed(commitments.channelId, remoteNodeId, confirmedTx))
val realScidStatus = RealScidStatus.Temporary(RealShortChannelId(blockHeight, txIndex, commitments.commitInput.outPoint.index.toInt))
val (shortIds, channelReady) = acceptFundingTx(commitments, realScidStatus = realScidStatus)
d.deferred.foreach(self ! _)
goto(WAIT_FOR_DUAL_FUNDING_READY) using DATA_WAIT_FOR_DUAL_FUNDING_READY(commitments, shortIds, channelReady) storing() sending channelReady
case Failure(t) =>
log.error(t, s"rejecting channel with invalid funding tx: ${confirmedTx.bin}")
allFundingTxs.foreach(f => wallet.rollback(f.fundingTx.tx.buildUnsignedTx()))
goto(CLOSED)
}
log.info(s"channelId=${commitments.channelId} was confirmed at blockHeight=$blockHeight txIndex=$txIndex with funding txid=${commitments.commitInput.outPoint.txid}")
watchFundingTx(commitments)
context.system.eventStream.publish(TransactionConfirmed(commitments.channelId, remoteNodeId, confirmedTx))
val realScidStatus = RealScidStatus.Temporary(RealShortChannelId(blockHeight, txIndex, commitments.commitInput.outPoint.index.toInt))
val (shortIds, channelReady) = acceptFundingTx(commitments, realScidStatus = realScidStatus)
d.deferred.foreach(self ! _)
goto(WAIT_FOR_DUAL_FUNDING_READY) using DATA_WAIT_FOR_DUAL_FUNDING_READY(commitments, shortIds, channelReady) storing() sending channelReady
case None =>
log.error(s"internal error: the funding tx that confirmed doesn't match any of our funding txs: ${confirmedTx.bin}")
allFundingTxs.foreach(f => wallet.rollback(f.fundingTx.tx.buildUnsignedTx()))
Expand Down

0 comments on commit f49116a

Please sign in to comment.