Skip to content

Commit

Permalink
Remove reserve checks for splice if contribution is positive (#522)
Browse files Browse the repository at this point in the history
If the contribution is positive, we should skip the reserve requirement, because the splice will increase the reserve, even if the post-splice level stays below the target (it may actually worsens if the other side is adding funds at the same time, but that's not remote's fault).

This applies to both local and remote.
  • Loading branch information
pm47 authored Aug 28, 2023
1 parent 63a488b commit 68a0e64
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/commonMain/kotlin/fr/acinq/lightning/channel/InteractiveTx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,17 @@ data class InteractiveTxSession(
val sharedOutput = sharedOutputs.first()

val sharedInput = fundingParams.sharedInput?.let {
// To compute the remote reserve, we discard the local contribution. It's okay if they go below reserve because
// we added capacity to the channel with a splice-in.
val remoteReserve = ((fundingParams.fundingAmount - fundingParams.localContribution) / 100).max(fundingParams.dustLimit)
if (sharedOutput.remoteAmount < remoteReserve && remoteOnlyOutputs.isNotEmpty()) {
return InteractiveTxSessionAction.InvalidTxBelowReserve(fundingParams.channelId, sharedOutput.remoteAmount.truncateToSatoshi(), remoteReserve)
if (fundingParams.remoteContribution >= 0.sat) {
// If remote has a positive contribution, we do not check their post-splice reserve level, because they are improving
// their situation, even if they stay below the requirement. Note that if local splices-in some funds in the same
// operation, remote post-splice reserve may actually be worse than before, but that's not their fault.
} else {
// To compute the remote reserve, we discard the local contribution. It's okay if they go below reserve because
// we added capacity to the channel with a splice-in.
val remoteReserve = ((fundingParams.fundingAmount - fundingParams.localContribution) / 100).max(fundingParams.dustLimit)
if (sharedOutput.remoteAmount < remoteReserve && remoteOnlyOutputs.isNotEmpty()) {
return InteractiveTxSessionAction.InvalidTxBelowReserve(fundingParams.channelId, sharedOutput.remoteAmount.truncateToSatoshi(), remoteReserve)
}
}
if (sharedInputs.size != 1) {
return InteractiveTxSessionAction.InvalidTxSharedInput(fundingParams.channelId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ data class Normal(
localOutputs = cmd.spliceOutputs,
targetFeerate = cmd.feerate
)
if (parentCommitment.localCommit.spec.toLocal + fundingContribution.toMilliSatoshi() < 0.msat) {
if (fundingContribution < 0.sat && parentCommitment.localCommit.spec.toLocal + fundingContribution.toMilliSatoshi() < parentCommitment.localChannelReserve(commitments.params)) {
logger.warning { "cannot do splice: insufficient funds" }
cmd.replyTo.complete(ChannelCommand.Commitment.Splice.Response.Failure.InsufficientFunds)
Pair(this@Normal, emptyList())
Expand Down

0 comments on commit 68a0e64

Please sign in to comment.