Skip to content

Commit 0baddd9

Browse files
authored
Only store txs spending our commit outputs (#3188)
Instead of storing every transaction spending the commit tx (which potentially included remote anchor transactions, which we aren't interested in), we explicitly store only the transactions that spend outputs of the commit tx we're interested in. This is more verbose than the previous code, but avoids unintended side-effects such as storing remote transactions.
1 parent 409c7c1 commit 0baddd9

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,14 +1643,11 @@ object Helpers {
16431643
// even if our txs only have one input, maybe our counterparty uses a different scheme so we need to iterate
16441644
// over all of them to check if they are relevant
16451645
val relevantOutpoints = tx.txIn.map(_.outPoint).filter(outPoint => {
1646-
// is this the commit tx itself? (we could do this outside of the loop...)
16471646
val isCommitTx = localCommitPublished.commitTx.txid == tx.txid
1648-
// does the tx spend an output of the local commitment tx (other than the anchor output)?
1649-
val spendsTheCommitTx = localCommitPublished.commitTx.txid == outPoint.txid && !localCommitPublished.anchorOutput_opt.contains(outPoint)
1650-
// is the tx one of our 3rd stage delayed txs? (a 3rd stage tx is a tx spending the output of an htlc tx, which
1651-
// is itself spending the output of the commitment tx)
1652-
val is3rdStageDelayedTx = localCommitPublished.htlcDelayedOutputs.contains(outPoint)
1653-
isCommitTx || spendsTheCommitTx || is3rdStageDelayedTx
1647+
val isMainTx = localCommitPublished.localOutput_opt.contains(outPoint)
1648+
val isHtlcTx = localCommitPublished.htlcOutputs.contains(outPoint)
1649+
val isHtlcDelayedTx = localCommitPublished.htlcDelayedOutputs.contains(outPoint)
1650+
isCommitTx || isMainTx || isHtlcTx || isHtlcDelayedTx
16541651
})
16551652
// then we add the relevant outpoints to the map keeping track of which txid spends which outpoint
16561653
localCommitPublished.copy(irrevocablySpent = localCommitPublished.irrevocablySpent ++ relevantOutpoints.map(o => o -> tx).toMap)
@@ -1670,11 +1667,10 @@ object Helpers {
16701667
// even if our txs only have one input, maybe our counterparty uses a different scheme so we need to iterate
16711668
// over all of them to check if they are relevant
16721669
val relevantOutpoints = tx.txIn.map(_.outPoint).filter(outPoint => {
1673-
// is this the commit tx itself? (we could do this outside of the loop...)
16741670
val isCommitTx = remoteCommitPublished.commitTx.txid == tx.txid
1675-
// does the tx spend an output of the remote commitment tx (other than the anchor output)?
1676-
val spendsTheCommitTx = remoteCommitPublished.commitTx.txid == outPoint.txid && !remoteCommitPublished.anchorOutput_opt.contains(outPoint)
1677-
isCommitTx || spendsTheCommitTx
1671+
val isMainTx = remoteCommitPublished.localOutput_opt.contains(outPoint)
1672+
val isHtlcTx = remoteCommitPublished.htlcOutputs.contains(outPoint)
1673+
isCommitTx || isMainTx || isHtlcTx
16781674
})
16791675
// then we add the relevant outpoints to the map keeping track of which txid spends which outpoint
16801676
remoteCommitPublished.copy(irrevocablySpent = remoteCommitPublished.irrevocablySpent ++ relevantOutpoints.map(o => o -> tx).toMap)
@@ -1694,14 +1690,12 @@ object Helpers {
16941690
// even if our txs only have one input, maybe our counterparty uses a different scheme so we need to iterate
16951691
// over all of them to check if they are relevant
16961692
val relevantOutpoints = tx.txIn.map(_.outPoint).filter(outPoint => {
1697-
// is this the commit tx itself? (we could do this outside of the loop...)
16981693
val isCommitTx = revokedCommitPublished.commitTx.txid == tx.txid
1699-
// does the tx spend an output of the remote commitment tx (other than the anchor output)?
1700-
val spendsTheCommitTx = revokedCommitPublished.commitTx.txid == outPoint.txid && !revokedCommitPublished.anchorOutput_opt.contains(outPoint)
1701-
// is the tx one of our 3rd stage delayed txs? (a 3rd stage tx is a tx spending the output of an htlc tx, which
1702-
// is itself spending the output of the commitment tx)
1703-
val is3rdStageDelayedTx = revokedCommitPublished.htlcDelayedOutputs.contains(outPoint)
1704-
isCommitTx || spendsTheCommitTx || is3rdStageDelayedTx
1694+
val isMainTx = revokedCommitPublished.localOutput_opt.contains(outPoint)
1695+
val isMainPenaltyTx = revokedCommitPublished.remoteOutput_opt.contains(outPoint)
1696+
val isHtlcPenaltyTx = revokedCommitPublished.htlcOutputs.contains(outPoint)
1697+
val isHtlcDelayedPenaltyTx = revokedCommitPublished.htlcDelayedOutputs.contains(outPoint)
1698+
isCommitTx || isMainTx || isMainPenaltyTx || isHtlcPenaltyTx || isHtlcDelayedPenaltyTx
17051699
})
17061700
// then we add the relevant outpoints to the map keeping track of which txid spends which outpoint
17071701
revokedCommitPublished.copy(irrevocablySpent = revokedCommitPublished.irrevocablySpent ++ relevantOutpoints.map(o => o -> tx).toMap)

0 commit comments

Comments
 (0)