Skip to content

Commit

Permalink
Use shared input's txOut in shouldSignFirst (#724)
Browse files Browse the repository at this point in the history
When deciding who must send `tx_signatures` first for a splice, we
compute how much each node contributes to the splice transaction by
adding the amount of the `tx_add_input` they have sent.

For the shared input (current channel output), instead of using the
`txOut` amount, we previously summed the balance of each node in the
channel. The result is the same when there are no pending HTLCs, but
when there are pending HTLCs, it underestimates the amount of this
input.

This is hard to reproduce (and test) because it requires both nodes to
contribute to the splice while having large pending HTLCs that tilt the
balance in favor of the wrong side.
  • Loading branch information
t-bast authored Oct 24, 2024
1 parent a7e4dad commit 0537e61
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ data class InteractiveTxSigningSession(
}

fun shouldSignFirst(isInitiator: Boolean, channelParams: ChannelParams, tx: SharedTransaction): Boolean {
val sharedAmountIn = tx.sharedInput?.let { it.localAmount + it.remoteAmount } ?: 0.msat
val sharedAmountIn = tx.sharedInput?.txOut?.amount?.toMilliSatoshi() ?: 0.msat
val localAmountIn = tx.localInputs.map { it.txOut.amount }.sum().toMilliSatoshi() + if (isInitiator) sharedAmountIn else 0.msat
val remoteAmountIn = tx.remoteInputs.map { it.txOut.amount }.sum().toMilliSatoshi() + if (isInitiator) 0.msat else sharedAmountIn
return if (localAmountIn == remoteAmountIn) {
Expand Down

0 comments on commit 0537e61

Please sign in to comment.