Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import fr.acinq.lightning.channel.Helpers.watchConfirmedIfNeeded
import fr.acinq.lightning.channel.Helpers.watchSpentIfNeeded
import fr.acinq.lightning.crypto.KeyManager
import fr.acinq.lightning.logging.LoggingContext
import fr.acinq.lightning.transactions.Scripts
import fr.acinq.lightning.transactions.Transactions.TransactionWithInputInfo.*
import fr.acinq.lightning.utils.toMilliSatoshi

Expand Down Expand Up @@ -70,7 +69,7 @@ data class LocalCommitPublished(
// is the commitment tx buried? (we need to check this because we may not have any outputs)
val isCommitTxConfirmed = confirmedTxs.contains(commitTx.txid)
// is our main output confirmed (if we have one)?
val isMainOutputConfirmed = claimMainDelayedOutputTx?.let { irrevocablySpent.contains(it.input.outPoint) } ?: true
val isMainOutputConfirmed = claimMainDelayedOutputTx == null || irrevocablySpent.contains(claimMainDelayedOutputTx.input.outPoint)
// are all htlc outputs from the commitment tx spent (we need to check them all because we may receive preimages later)?
val allHtlcsSpent = (htlcTxs.keys - irrevocablySpent.keys).isEmpty()
// are all outputs from htlc txs spent?
Expand All @@ -86,22 +85,6 @@ data class LocalCommitPublished(
return irrevocablySpent.values.any { it.txid == commitTx.txid } || irrevocablySpent.keys.any { it.txid == commitTx.txid }
}

fun isHtlcTimeout(tx: Transaction): Boolean {
return tx.txIn
.filter { htlcTxs[it.outPoint] is HtlcTx.HtlcTimeoutTx }
.map { it.witness }
.mapNotNull(Scripts.extractPaymentHashFromHtlcTimeout())
.isNotEmpty()
}

fun isHtlcSuccess(tx: Transaction): Boolean {
return tx.txIn
.filter { htlcTxs[it.outPoint] is HtlcTx.HtlcSuccessTx }
.map { it.witness }
.mapNotNull(Scripts.extractPreimageFromHtlcSuccess())
.isNotEmpty()
}

internal fun LoggingContext.doPublish(nodeParams: NodeParams, channelId: ByteVector32): List<ChannelAction> {
val publishQueue = buildList {
add(ChannelAction.Blockchain.PublishTx(commitTx, ChannelAction.Blockchain.PublishTx.Type.CommitTx))
Expand Down Expand Up @@ -183,7 +166,7 @@ data class RemoteCommitPublished(
// is the commitment tx buried? (we need to check this because we may not have any outputs)
val isCommitTxConfirmed = confirmedTxs.contains(commitTx.txid)
// is our main output confirmed (if we have one)?
val isMainOutputConfirmed = claimMainOutputTx?.let { irrevocablySpent.contains(it.input.outPoint) } ?: true
val isMainOutputConfirmed = claimMainOutputTx == null || irrevocablySpent.contains(claimMainOutputTx.input.outPoint)
// are all htlc outputs from the commitment tx spent (we need to check them all because we may receive preimages later)?
val allHtlcsSpent = (claimHtlcTxs.keys - irrevocablySpent.keys).isEmpty()
return isCommitTxConfirmed && isMainOutputConfirmed && allHtlcsSpent
Expand All @@ -193,22 +176,6 @@ data class RemoteCommitPublished(
return irrevocablySpent.values.any { it.txid == commitTx.txid } || irrevocablySpent.keys.any { it.txid == commitTx.txid }
}

fun isClaimHtlcTimeout(tx: Transaction): Boolean {
return tx.txIn
.filter { claimHtlcTxs[it.outPoint] is ClaimHtlcTx.ClaimHtlcTimeoutTx }
.map { it.witness }
.mapNotNull(Scripts.extractPaymentHashFromClaimHtlcTimeout())
.isNotEmpty()
}

fun isClaimHtlcSuccess(tx: Transaction): Boolean {
return tx.txIn
.filter { claimHtlcTxs[it.outPoint] is ClaimHtlcTx.ClaimHtlcSuccessTx }
.map { it.witness }
.mapNotNull(Scripts.extractPreimageFromClaimHtlcSuccess())
.isNotEmpty()
}

internal fun LoggingContext.doPublish(nodeParams: NodeParams, channelId: ByteVector32): List<ChannelAction> {
val publishQueue = buildList {
claimMainOutputTx?.let { add(ChannelAction.Blockchain.PublishTx(it)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ data class FundingTxSpent (override val channelId: Byte
data class HtlcsTimedOutDownstream (override val channelId: ByteVector32, val htlcs: Set<UpdateAddHtlc>) : ChannelException(channelId, "one or more htlcs timed out downstream: ids=${htlcs.map { it.id } .joinToString(",")}")
data class FulfilledHtlcsWillTimeout (override val channelId: ByteVector32, val htlcs: Set<UpdateAddHtlc>) : ChannelException(channelId, "one or more htlcs that should be fulfilled are close to timing out: ids=${htlcs.map { it.id }.joinToString()}")
data class HtlcOverriddenByLocalCommit (override val channelId: ByteVector32, val htlc: UpdateAddHtlc) : ChannelException(channelId, "htlc ${htlc.id} was overridden by local commit")
data class HtlcOverriddenByRemoteCommit (override val channelId: ByteVector32, val htlc: UpdateAddHtlc) : ChannelException(channelId, "htlc ${htlc.id} was overridden by remote commit")
data class FeerateTooSmall (override val channelId: ByteVector32, val remoteFeeratePerKw: FeeratePerKw) : ChannelException(channelId, "remote fee rate is too small: remoteFeeratePerKw=${remoteFeeratePerKw.toLong()}")
data class FeerateTooDifferent (override val channelId: ByteVector32, val localFeeratePerKw: FeeratePerKw, val remoteFeeratePerKw: FeeratePerKw) : ChannelException(channelId, "local/remote feerates are too different: remoteFeeratePerKw=${remoteFeeratePerKw.toLong()} localFeeratePerKw=${localFeeratePerKw.toLong()}")
data class InvalidCommitmentSignature (override val channelId: ByteVector32, val txId: TxId) : ChannelException(channelId, "invalid commitment signature: txId=$txId")
Expand Down
Loading