@@ -1786,7 +1786,7 @@ data class Normal(
17861786 logger.info { " c:$channelId adding paymentHash=${it.paymentHash} cltvExpiry=${it.cltvExpiry} to htlcs db for commitNumber=$nextCommitNumber " }
17871787 ChannelAction .Storage .HtlcInfo (channelId, nextCommitNumber, it.paymentHash, it.cltvExpiry)
17881788 }
1789- val nextState = this .copy(commitments = result.value.first )
1789+ val nextState = this .copy(commitments = commitments1 )
17901790 val actions = listOf (
17911791 ChannelAction .Storage .StoreHtlcInfos (htlcInfos),
17921792 ChannelAction .Storage .StoreState (nextState),
@@ -2195,8 +2195,21 @@ data class ShuttingDown(
21952195 is Either .Left -> handleCommandError(event.command, result.value)
21962196 is Either .Right -> {
21972197 val commitments1 = result.value.first
2198+ val nextRemoteCommit = commitments1.remoteNextCommitInfo.left!! .nextRemoteCommit
2199+ val nextCommitNumber = nextRemoteCommit.index
2200+ // we persist htlc data in order to be able to claim htlc outputs in case a revoked tx is published by our
2201+ // counterparty, so only htlcs above remote's dust_limit matter
2202+ val trimmedHtlcs = Transactions .trimOfferedHtlcs(commitments.remoteParams.dustLimit, nextRemoteCommit.spec) + Transactions .trimReceivedHtlcs(commitments.remoteParams.dustLimit, nextRemoteCommit.spec)
2203+ val htlcInfos = trimmedHtlcs.map { it.add }.map {
2204+ logger.info { " c:$channelId adding paymentHash=${it.paymentHash} cltvExpiry=${it.cltvExpiry} to htlcs db for commitNumber=$nextCommitNumber " }
2205+ ChannelAction .Storage .HtlcInfo (channelId, nextCommitNumber, it.paymentHash, it.cltvExpiry)
2206+ }
21982207 val nextState = this .copy(commitments = commitments1)
2199- val actions = listOf (ChannelAction .Storage .StoreState (nextState), ChannelAction .Message .Send (result.value.second))
2208+ val actions = listOf (
2209+ ChannelAction .Storage .StoreHtlcInfos (htlcInfos),
2210+ ChannelAction .Storage .StoreState (nextState),
2211+ ChannelAction .Message .Send (result.value.second)
2212+ )
22002213 Pair (nextState, actions)
22012214 }
22022215 }
0 commit comments