Skip to content

Commit 2a5f89f

Browse files
committed
Fixup: use a map for wallet utxos, remember wallet utxo for funded txs we want to bump
1 parent cd74ecc commit 2a5f89f

File tree

14 files changed

+132
-179
lines changed

14 files changed

+132
-179
lines changed

eclair-core/src/main/scala/fr/acinq/eclair/SpendFromChannelAddress.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ trait SpendFromChannelAddress {
4949
localFundingPubkey,
5050
TxOwner.Local, // unused
5151
DefaultCommitmentFormat, // unused
52-
Nil
52+
Map.empty
5353
)
5454
witness = Scripts.witness2of2(localSig, remoteSig, localFundingPubkey.publicKey, remoteFundingPubkey)
5555
signedTx = unsignedTx.updateWitness(0, witness)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ object LocalCommit {
218218
case class RemoteCommit(index: Long, spec: CommitmentSpec, txid: TxId, remotePerCommitmentPoint: PublicKey) {
219219
def sign(keyManager: ChannelKeyManager, params: ChannelParams, fundingTxIndex: Long, remoteFundingPubKey: PublicKey, commitInput: InputInfo): CommitSig = {
220220
val (remoteCommitTx, htlcTxs) = Commitment.makeRemoteTxs(keyManager, params.channelConfig, params.channelFeatures, index, params.localParams, params.remoteParams, fundingTxIndex, remoteFundingPubKey, commitInput, remotePerCommitmentPoint, spec)
221-
val sig = keyManager.sign(remoteCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex), TxOwner.Remote, params.commitmentFormat, Nil)
221+
val sig = keyManager.sign(remoteCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex), TxOwner.Remote, params.commitmentFormat, Map.empty)
222222
val channelKeyPath = keyManager.keyPath(params.localParams, params.channelConfig)
223223
val sortedHtlcTxs = htlcTxs.sortBy(_.input.outPoint.index)
224-
val htlcSigs = sortedHtlcTxs.map(keyManager.sign(_, keyManager.htlcPoint(channelKeyPath), remotePerCommitmentPoint, TxOwner.Remote, params.commitmentFormat, Nil))
224+
val htlcSigs = sortedHtlcTxs.map(keyManager.sign(_, keyManager.htlcPoint(channelKeyPath), remotePerCommitmentPoint, TxOwner.Remote, params.commitmentFormat, Map.empty))
225225
CommitSig(params.channelId, sig, htlcSigs.toList)
226226
}
227227
}
@@ -622,11 +622,11 @@ case class Commitment(fundingTxIndex: Long,
622622
// remote commitment will include all local proposed changes + remote acked changes
623623
val spec = CommitmentSpec.reduce(remoteCommit.spec, changes.remoteChanges.acked, changes.localChanges.proposed)
624624
val (remoteCommitTx, htlcTxs) = Commitment.makeRemoteTxs(keyManager, params.channelConfig, params.channelFeatures, remoteCommit.index + 1, params.localParams, params.remoteParams, fundingTxIndex, remoteFundingPubKey, commitInput, remoteNextPerCommitmentPoint, spec)
625-
val sig = keyManager.sign(remoteCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex), TxOwner.Remote, params.commitmentFormat, Nil)
625+
val sig = keyManager.sign(remoteCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex), TxOwner.Remote, params.commitmentFormat, Map.empty)
626626

627627
val sortedHtlcTxs: Seq[TransactionWithInputInfo] = htlcTxs.sortBy(_.input.outPoint.index)
628628
val channelKeyPath = keyManager.keyPath(params.localParams, params.channelConfig)
629-
val htlcSigs = sortedHtlcTxs.map(keyManager.sign(_, keyManager.htlcPoint(channelKeyPath), remoteNextPerCommitmentPoint, TxOwner.Remote, params.commitmentFormat, Nil))
629+
val htlcSigs = sortedHtlcTxs.map(keyManager.sign(_, keyManager.htlcPoint(channelKeyPath), remoteNextPerCommitmentPoint, TxOwner.Remote, params.commitmentFormat, Map.empty))
630630

631631
// NB: IN/OUT htlcs are inverted because this is the remote commit
632632
log.info(s"built remote commit number=${remoteCommit.index + 1} toLocalMsat=${spec.toLocal.toLong} toRemoteMsat=${spec.toRemote.toLong} htlc_in={} htlc_out={} feeratePerKw=${spec.commitTxFeerate} txid=${remoteCommitTx.tx.txid} fundingTxId=$fundingTxId", spec.htlcs.collect(DirectedHtlc.outgoing).map(_.id).mkString(","), spec.htlcs.collect(DirectedHtlc.incoming).map(_.id).mkString(","))
@@ -659,7 +659,7 @@ case class Commitment(fundingTxIndex: Long,
659659
/** Return a fully signed commit tx, that can be published as-is. */
660660
def fullySignedLocalCommitTx(params: ChannelParams, keyManager: ChannelKeyManager): CommitTx = {
661661
val unsignedCommitTx = localCommit.commitTxAndRemoteSig.commitTx
662-
val localSig = keyManager.sign(unsignedCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex), TxOwner.Local, params.commitmentFormat, Nil)
662+
val localSig = keyManager.sign(unsignedCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex), TxOwner.Local, params.commitmentFormat, Map.empty)
663663
val RemoteSignature.FullSignature(remoteSig) = localCommit.commitTxAndRemoteSig.remoteSig
664664
val commitTx = addSigs(unsignedCommitTx, keyManager.fundingPublicKey(params.localParams.fundingKeyPath, fundingTxIndex).publicKey, remoteFundingPubKey, localSig, remoteSig)
665665
// We verify the remote signature when receiving their commit_sig, so this check should always pass.

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ object Helpers {
701701
log.debug("making closing tx with closing fee={} and commitments:\n{}", closingFees.preferred, commitment.specs2String)
702702
val dustLimit = commitment.localParams.dustLimit.max(commitment.remoteParams.dustLimit)
703703
val closingTx = Transactions.makeClosingTx(commitment.commitInput, localScriptPubkey, remoteScriptPubkey, commitment.localParams.paysClosingFees, dustLimit, closingFees.preferred, commitment.localCommit.spec)
704-
val localClosingSig = keyManager.sign(closingTx, keyManager.fundingPublicKey(commitment.localParams.fundingKeyPath, commitment.fundingTxIndex), TxOwner.Local, commitment.params.commitmentFormat, Nil)
704+
val localClosingSig = keyManager.sign(closingTx, keyManager.fundingPublicKey(commitment.localParams.fundingKeyPath, commitment.fundingTxIndex), TxOwner.Local, commitment.params.commitmentFormat, Map.empty)
705705
val closingSigned = ClosingSigned(commitment.channelId, closingFees.preferred, localClosingSig, TlvStream(ClosingSignedTlv.FeeRange(closingFees.min, closingFees.max)))
706706
log.debug(s"signed closing txid=${closingTx.tx.txid} with closing fee=${closingSigned.feeSatoshis}")
707707
log.debug(s"closingTxid=${closingTx.tx.txid} closingTx=${closingTx.tx}}")
@@ -741,9 +741,9 @@ object Helpers {
741741
}
742742
val localFundingPubKey = keyManager.fundingPublicKey(commitment.localParams.fundingKeyPath, commitment.fundingTxIndex)
743743
val closingComplete = ClosingComplete(commitment.channelId, localScriptPubkey, remoteScriptPubkey, closingFee.fee, currentBlockHeight.toLong, TlvStream(Set(
744-
closingTxs.localAndRemote_opt.map(tx => ClosingTlv.CloserAndCloseeOutputs(keyManager.sign(tx, localFundingPubKey, TxOwner.Local, commitment.params.commitmentFormat, Nil))),
745-
closingTxs.localOnly_opt.map(tx => ClosingTlv.CloserOutputOnly(keyManager.sign(tx, localFundingPubKey, TxOwner.Local, commitment.params.commitmentFormat, Nil))),
746-
closingTxs.remoteOnly_opt.map(tx => ClosingTlv.CloseeOutputOnly(keyManager.sign(tx, localFundingPubKey, TxOwner.Local, commitment.params.commitmentFormat, Nil))),
744+
closingTxs.localAndRemote_opt.map(tx => ClosingTlv.CloserAndCloseeOutputs(keyManager.sign(tx, localFundingPubKey, TxOwner.Local, commitment.params.commitmentFormat, Map.empty))),
745+
closingTxs.localOnly_opt.map(tx => ClosingTlv.CloserOutputOnly(keyManager.sign(tx, localFundingPubKey, TxOwner.Local, commitment.params.commitmentFormat, Map.empty))),
746+
closingTxs.remoteOnly_opt.map(tx => ClosingTlv.CloseeOutputOnly(keyManager.sign(tx, localFundingPubKey, TxOwner.Local, commitment.params.commitmentFormat, Map.empty))),
747747
).flatten[ClosingTlv]))
748748
Right(closingTxs, closingComplete)
749749
}
@@ -774,7 +774,7 @@ object Helpers {
774774
closingTxsWithSigs.headOption match {
775775
case Some((closingTx, remoteSig, sigToTlv)) =>
776776
val localFundingPubKey = keyManager.fundingPublicKey(commitment.localParams.fundingKeyPath, commitment.fundingTxIndex)
777-
val localSig = keyManager.sign(closingTx, localFundingPubKey, TxOwner.Local, commitment.params.commitmentFormat, Nil)
777+
val localSig = keyManager.sign(closingTx, localFundingPubKey, TxOwner.Local, commitment.params.commitmentFormat, Map.empty)
778778
val signedClosingTx = Transactions.addSigs(closingTx, localFundingPubKey.publicKey, commitment.remoteFundingPubKey, localSig, remoteSig)
779779
Transactions.checkSpendable(signedClosingTx) match {
780780
case Failure(_) => Left(InvalidCloseSignature(commitment.channelId, signedClosingTx.tx.txid))
@@ -800,7 +800,7 @@ object Helpers {
800800
closingTxsWithSig.headOption match {
801801
case Some((closingTx, remoteSig)) =>
802802
val localFundingPubKey = keyManager.fundingPublicKey(commitment.localParams.fundingKeyPath, commitment.fundingTxIndex)
803-
val localSig = keyManager.sign(closingTx, localFundingPubKey, TxOwner.Local, commitment.params.commitmentFormat, Nil)
803+
val localSig = keyManager.sign(closingTx, localFundingPubKey, TxOwner.Local, commitment.params.commitmentFormat, Map.empty)
804804
val signedClosingTx = Transactions.addSigs(closingTx, localFundingPubKey.publicKey, commitment.remoteFundingPubKey, localSig, remoteSig)
805805
Transactions.checkSpendable(signedClosingTx) match {
806806
case Failure(_) => Left(InvalidCloseSignature(commitment.channelId, signedClosingTx.tx.txid))
@@ -882,7 +882,7 @@ object Helpers {
882882
// first we will claim our main output as soon as the delay is over
883883
val mainDelayedTx = withTxGenerationLog("local-main-delayed") {
884884
Transactions.makeClaimLocalDelayedOutputTx(tx, commitment.localParams.dustLimit, localRevocationPubkey, commitment.remoteParams.toSelfDelay, localDelayedPubkey, finalScriptPubKey, feeratePerKwDelayed).map(claimDelayed => {
885-
val sig = keyManager.sign(claimDelayed, keyManager.delayedPaymentPoint(channelKeyPath), localPerCommitmentPoint, TxOwner.Local, commitment.params.commitmentFormat, Nil)
885+
val sig = keyManager.sign(claimDelayed, keyManager.delayedPaymentPoint(channelKeyPath), localPerCommitmentPoint, TxOwner.Local, commitment.params.commitmentFormat, Map.empty)
886886
Transactions.addSigs(claimDelayed, sig)
887887
})
888888
}
@@ -945,7 +945,7 @@ object Helpers {
945945
if (hash2Preimage.contains(paymentHash)) {
946946
// incoming htlc for which we have the preimage: we can spend it immediately
947947
Some(txInfo.input.outPoint -> withTxGenerationLog("htlc-success") {
948-
val localSig = keyManager.sign(txInfo, keyManager.htlcPoint(channelKeyPath), localPerCommitmentPoint, TxOwner.Local, commitment.params.commitmentFormat, Nil)
948+
val localSig = keyManager.sign(txInfo, keyManager.htlcPoint(channelKeyPath), localPerCommitmentPoint, TxOwner.Local, commitment.params.commitmentFormat, Map.empty)
949949
Right(Transactions.addSigs(txInfo, localSig, remoteSig, hash2Preimage(paymentHash), commitment.params.commitmentFormat))
950950
})
951951
} else if (failedIncomingHtlcs.contains(txInfo.htlcId)) {
@@ -962,7 +962,7 @@ object Helpers {
962962
case HtlcTxAndRemoteSig(txInfo: HtlcTimeoutTx, remoteSig) =>
963963
// outgoing htlc: they may or may not have the preimage, the only thing to do is try to get back our funds after timeout
964964
Some(txInfo.input.outPoint -> withTxGenerationLog("htlc-timeout") {
965-
val localSig = keyManager.sign(txInfo, keyManager.htlcPoint(channelKeyPath), localPerCommitmentPoint, TxOwner.Local, commitment.params.commitmentFormat, Nil)
965+
val localSig = keyManager.sign(txInfo, keyManager.htlcPoint(channelKeyPath), localPerCommitmentPoint, TxOwner.Local, commitment.params.commitmentFormat, Map.empty)
966966
Right(Transactions.addSigs(txInfo, localSig, remoteSig, commitment.params.commitmentFormat))
967967
})
968968
}.flatten.toMap
@@ -983,7 +983,7 @@ object Helpers {
983983
val localDelayedPubkey = Generators.derivePubKey(keyManager.delayedPaymentPoint(channelKeyPath).publicKey, localPerCommitmentPoint)
984984
val htlcDelayedTx = withTxGenerationLog("htlc-delayed") {
985985
Transactions.makeHtlcDelayedTx(tx, commitment.localParams.dustLimit, localRevocationPubkey, commitment.remoteParams.toSelfDelay, localDelayedPubkey, finalScriptPubKey, feeratePerKwDelayed).map(claimDelayed => {
986-
val sig = keyManager.sign(claimDelayed, keyManager.delayedPaymentPoint(channelKeyPath), localPerCommitmentPoint, TxOwner.Local, commitment.params.commitmentFormat, Nil)
986+
val sig = keyManager.sign(claimDelayed, keyManager.delayedPaymentPoint(channelKeyPath), localPerCommitmentPoint, TxOwner.Local, commitment.params.commitmentFormat, Map.empty)
987987
Transactions.addSigs(claimDelayed, sig)
988988
})
989989
}
@@ -1065,13 +1065,13 @@ object Helpers {
10651065
params.commitmentFormat match {
10661066
case DefaultCommitmentFormat => withTxGenerationLog("remote-main") {
10671067
Transactions.makeClaimP2WPKHOutputTx(tx, params.localParams.dustLimit, localPubkey, finalScriptPubKey, feeratePerKwMain).map(claimMain => {
1068-
val sig = keyManager.sign(claimMain, keyManager.paymentPoint(channelKeyPath), remotePerCommitmentPoint, TxOwner.Local, params.commitmentFormat, Nil)
1068+
val sig = keyManager.sign(claimMain, keyManager.paymentPoint(channelKeyPath), remotePerCommitmentPoint, TxOwner.Local, params.commitmentFormat, Map.empty)
10691069
Transactions.addSigs(claimMain, localPubkey, sig)
10701070
})
10711071
}
10721072
case _: AnchorOutputsCommitmentFormat => withTxGenerationLog("remote-main-delayed") {
10731073
Transactions.makeClaimRemoteDelayedOutputTx(tx, params.localParams.dustLimit, localPaymentPoint, finalScriptPubKey, feeratePerKwMain).map(claimMain => {
1074-
val sig = keyManager.sign(claimMain, keyManager.paymentPoint(channelKeyPath), TxOwner.Local, params.commitmentFormat, Nil)
1074+
val sig = keyManager.sign(claimMain, keyManager.paymentPoint(channelKeyPath), TxOwner.Local, params.commitmentFormat, Map.empty)
10751075
Transactions.addSigs(claimMain, sig)
10761076
})
10771077
}
@@ -1114,7 +1114,7 @@ object Helpers {
11141114
if (hash2Preimage.contains(add.paymentHash)) {
11151115
// incoming htlc for which we have the preimage: we can spend it immediately
11161116
Some(claimHtlcTx.input.outPoint -> withTxGenerationLog("claim-htlc-success") {
1117-
val sig = keyManager.sign(claimHtlcTx, keyManager.htlcPoint(channelKeyPath), remoteCommit.remotePerCommitmentPoint, TxOwner.Local, commitment.params.commitmentFormat, Nil)
1117+
val sig = keyManager.sign(claimHtlcTx, keyManager.htlcPoint(channelKeyPath), remoteCommit.remotePerCommitmentPoint, TxOwner.Local, commitment.params.commitmentFormat, Map.empty)
11181118
Right(Transactions.addSigs(claimHtlcTx, sig, hash2Preimage(add.paymentHash)))
11191119
})
11201120
} else if (failedIncomingHtlcs.contains(add.id)) {
@@ -1133,7 +1133,7 @@ object Helpers {
11331133
Transactions.makeClaimHtlcTimeoutTx(remoteCommitTx.tx, outputs, commitment.localParams.dustLimit, localHtlcPubkey, remoteHtlcPubkey, remoteRevocationPubkey, finalScriptPubKey, add, feeratePerKwHtlc, commitment.params.commitmentFormat)
11341134
}.map(claimHtlcTx => {
11351135
Some(claimHtlcTx.input.outPoint -> withTxGenerationLog("claim-htlc-timeout") {
1136-
val sig = keyManager.sign(claimHtlcTx, keyManager.htlcPoint(channelKeyPath), remoteCommit.remotePerCommitmentPoint, TxOwner.Local, commitment.params.commitmentFormat, Nil)
1136+
val sig = keyManager.sign(claimHtlcTx, keyManager.htlcPoint(channelKeyPath), remoteCommit.remotePerCommitmentPoint, TxOwner.Local, commitment.params.commitmentFormat, Map.empty)
11371137
Right(Transactions.addSigs(claimHtlcTx, sig))
11381138
})
11391139
})
@@ -1201,13 +1201,13 @@ object Helpers {
12011201
case ct => ct.commitmentFormat match {
12021202
case DefaultCommitmentFormat => withTxGenerationLog("remote-main") {
12031203
Transactions.makeClaimP2WPKHOutputTx(commitTx, localParams.dustLimit, localPaymentPubkey, finalScriptPubKey, feerateMain).map(claimMain => {
1204-
val sig = keyManager.sign(claimMain, keyManager.paymentPoint(channelKeyPath), remotePerCommitmentPoint, TxOwner.Local, commitmentFormat, Nil)
1204+
val sig = keyManager.sign(claimMain, keyManager.paymentPoint(channelKeyPath), remotePerCommitmentPoint, TxOwner.Local, commitmentFormat, Map.empty)
12051205
Transactions.addSigs(claimMain, localPaymentPubkey, sig)
12061206
})
12071207
}
12081208
case _: AnchorOutputsCommitmentFormat => withTxGenerationLog("remote-main-delayed") {
12091209
Transactions.makeClaimRemoteDelayedOutputTx(commitTx, localParams.dustLimit, localPaymentPoint, finalScriptPubKey, feerateMain).map(claimMain => {
1210-
val sig = keyManager.sign(claimMain, keyManager.paymentPoint(channelKeyPath), TxOwner.Local, commitmentFormat, Nil)
1210+
val sig = keyManager.sign(claimMain, keyManager.paymentPoint(channelKeyPath), TxOwner.Local, commitmentFormat, Map.empty)
12111211
Transactions.addSigs(claimMain, sig)
12121212
})
12131213
}
@@ -1217,7 +1217,7 @@ object Helpers {
12171217
// then we punish them by stealing their main output
12181218
val mainPenaltyTx = withTxGenerationLog("main-penalty") {
12191219
Transactions.makeMainPenaltyTx(commitTx, localParams.dustLimit, remoteRevocationPubkey, finalScriptPubKey, localParams.toSelfDelay, remoteDelayedPaymentPubkey, feeratePenalty).map(txinfo => {
1220-
val sig = keyManager.sign(txinfo, keyManager.revocationPoint(channelKeyPath), remotePerCommitmentSecret, TxOwner.Local, commitmentFormat, Nil)
1220+
val sig = keyManager.sign(txinfo, keyManager.revocationPoint(channelKeyPath), remotePerCommitmentSecret, TxOwner.Local, commitmentFormat, Map.empty)
12211221
Transactions.addSigs(txinfo, sig)
12221222
})
12231223
}
@@ -1237,7 +1237,7 @@ object Helpers {
12371237
val htlcRedeemScript = htlcsRedeemScripts(txOut.publicKeyScript)
12381238
withTxGenerationLog("htlc-penalty") {
12391239
Transactions.makeHtlcPenaltyTx(commitTx, outputIndex, htlcRedeemScript, localParams.dustLimit, finalScriptPubKey, feeratePenalty).map(htlcPenalty => {
1240-
val sig = keyManager.sign(htlcPenalty, keyManager.revocationPoint(channelKeyPath), remotePerCommitmentSecret, TxOwner.Local, commitmentFormat, Nil)
1240+
val sig = keyManager.sign(htlcPenalty, keyManager.revocationPoint(channelKeyPath), remotePerCommitmentSecret, TxOwner.Local, commitmentFormat, Map.empty)
12411241
Transactions.addSigs(htlcPenalty, sig, remoteRevocationPubkey)
12421242
})
12431243
}
@@ -1293,7 +1293,7 @@ object Helpers {
12931293
val penaltyTxs = Transactions.makeClaimHtlcDelayedOutputPenaltyTxs(htlcTx, localParams.dustLimit, remoteRevocationPubkey, localParams.toSelfDelay, remoteDelayedPaymentPubkey, finalScriptPubKey, feeratePerKwPenalty).flatMap(claimHtlcDelayedOutputPenaltyTx => {
12941294
withTxGenerationLog("htlc-delayed-penalty") {
12951295
claimHtlcDelayedOutputPenaltyTx.map(htlcDelayedPenalty => {
1296-
val sig = keyManager.sign(htlcDelayedPenalty, keyManager.revocationPoint(channelKeyPath), remotePerCommitmentSecret, TxOwner.Local, commitmentFormat, Nil)
1296+
val sig = keyManager.sign(htlcDelayedPenalty, keyManager.revocationPoint(channelKeyPath), remotePerCommitmentSecret, TxOwner.Local, commitmentFormat, Map.empty)
12971297
val signedTx = Transactions.addSigs(htlcDelayedPenalty, sig)
12981298
// we need to make sure that the tx is indeed valid
12991299
Transaction.correctlySpends(signedTx.tx, Seq(htlcTx), ScriptFlags.STANDARD_SCRIPT_VERIFY_FLAGS)

0 commit comments

Comments
 (0)