Skip to content

Commit 58747b6

Browse files
committed
Fixup: Use the new txOut field to compute amounts
1 parent 8b5e5f7 commit 58747b6

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

eclair-core/src/main/scala/fr/acinq/eclair/channel/fund/InteractiveTxBuilder.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ object InteractiveTxBuilder {
286286
localInputs: List[Input.Local], remoteInputs: List[Input.Remote],
287287
localOutputs: List[Output.Local], remoteOutputs: List[Output.Remote],
288288
lockTime: Long) {
289-
val localAmountIn: MilliSatoshi = sharedInput_opt.map(_.localAmount).getOrElse(0 msat) + localInputs.map(i => i.previousTx.txOut(i.previousTxOutput.toInt).amount).sum
289+
val localAmountIn: MilliSatoshi = sharedInput_opt.map(_.localAmount).getOrElse(0 msat) + localInputs.map(i => i.txOut.amount).sum
290290
val remoteAmountIn: MilliSatoshi = sharedInput_opt.map(_.remoteAmount).getOrElse(0 msat) + remoteInputs.map(_.txOut.amount).sum
291291
val localAmountOut: MilliSatoshi = sharedOutput.localAmount + localOutputs.map(_.amount).sum
292292
val remoteAmountOut: MilliSatoshi = sharedOutput.remoteAmount + remoteOutputs.map(_.amount).sum
@@ -814,7 +814,7 @@ private class InteractiveTxBuilder(replyTo: ActorRef[InteractiveTxBuilder.Respon
814814
// Partially signed PSBT must include spent amounts for all inputs that were signed, and we can "trust" these amounts because they are included
815815
// in the hash that we signed (see BIP143). If our bitcoin node lied about them, then our signatures are invalid.
816816
val actualLocalAmountIn = ourWalletInputs.map(i => kmp2scala(response.psbt.getInput(i).getWitnessUtxo.amount)).sum
817-
val expectedLocalAmountIn = unsignedTx.localInputs.map(i => i.previousTx.txOut(i.previousTxOutput.toInt).amount).sum
817+
val expectedLocalAmountIn = unsignedTx.localInputs.map(i => i.txOut.amount).sum
818818
require(actualLocalAmountIn == expectedLocalAmountIn, s"local spent amount $actualLocalAmountIn does not match what we expect ($expectedLocalAmountIn): bitcoin core may be malicious")
819819
val actualLocalAmountOut = ourWalletOutputs.map(i => partiallySignedTx.txOut(i).amount).sum
820820
val expectedLocalAmountOut = unsignedTx.localOutputs.map {
@@ -888,9 +888,9 @@ object InteractiveTxSigningSession {
888888
private def shouldSignFirst(isInitiator: Boolean, channelParams: ChannelParams, tx: SharedTransaction): Boolean = {
889889
val sharedAmountIn = tx.sharedInput_opt.map(i => i.localAmount + i.remoteAmount + i.htlcAmount).getOrElse(0 msat).truncateToSatoshi
890890
val (localAmountIn, remoteAmountIn) = if (isInitiator) {
891-
(sharedAmountIn + tx.localInputs.map(i => i.previousTx.txOut(i.previousTxOutput.toInt).amount).sum, tx.remoteInputs.map(i => i.txOut.amount).sum)
891+
(sharedAmountIn + tx.localInputs.map(i => i.txOut.amount).sum, tx.remoteInputs.map(i => i.txOut.amount).sum)
892892
} else {
893-
(tx.localInputs.map(i => i.previousTx.txOut(i.previousTxOutput.toInt).amount).sum, sharedAmountIn + tx.remoteInputs.map(i => i.txOut.amount).sum)
893+
(tx.localInputs.map(i => i.txOut.amount).sum, sharedAmountIn + tx.remoteInputs.map(i => i.txOut.amount).sum)
894894
}
895895
if (localAmountIn == remoteAmountIn) {
896896
// When both peers contribute the same amount, the peer with the lowest pubkey must transmit its `tx_signatures` first.
@@ -932,7 +932,7 @@ object InteractiveTxSigningSession {
932932
}
933933
val previousOutputs = {
934934
val sharedOutput = fundingParams.sharedInput_opt.map(sharedInput => sharedInput.info.outPoint -> sharedInput.info.txOut).toMap
935-
val localOutputs = txWithSigs.tx.localInputs.map(i => i.outPoint -> i.previousTx.txOut(i.previousTxOutput.toInt)).toMap
935+
val localOutputs = txWithSigs.tx.localInputs.map(i => i.outPoint -> i.txOut).toMap
936936
val remoteOutputs = txWithSigs.tx.remoteInputs.map(i => i.outPoint -> i.txOut).toMap
937937
sharedOutput ++ localOutputs ++ remoteOutputs
938938
}

eclair-core/src/test/scala/fr/acinq/eclair/channel/states/b/WaitForDualFundingSignedStateSpec.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ class WaitForDualFundingSignedStateSpec extends TestKitBaseClass with FixtureAny
111111
val bobData = bob.stateData.asInstanceOf[DATA_WAIT_FOR_DUAL_FUNDING_CONFIRMED]
112112
assert(bobData.commitments.params.channelFeatures.hasFeature(Features.DualFunding))
113113
assert(bobData.latestFundingTx.sharedTx.isInstanceOf[PartiallySignedSharedTransaction])
114-
val foo = bobData.latestFundingTx.sharedTx
115-
println(foo)
116114
val fundingTxId = bobData.latestFundingTx.sharedTx.asInstanceOf[PartiallySignedSharedTransaction].txId
117115
assert(bob2blockchain.expectMsgType[WatchFundingConfirmed].txId == fundingTxId)
118116

0 commit comments

Comments
 (0)