Skip to content

Commit ee18883

Browse files
committed
Use Commitment properties to build the correct SharedInput instance
1 parent f0e0a20 commit ee18883

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

eclair-core/src/main/scala/fr/acinq/eclair/channel/fsm/Channel.scala

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,10 +1024,7 @@ class Channel(val nodeParams: NodeParams, val wallet: OnChainChannelFunder with
10241024
val parentCommitment = d.commitments.latest.commitment
10251025
val localFundingPubKey = nodeParams.channelKeyManager.fundingPublicKey(d.commitments.params.localParams.fundingKeyPath, parentCommitment.fundingTxIndex + 1).publicKey
10261026
val fundingScript = Funding.makeFundingPubKeyScript(localFundingPubKey, msg.fundingPubKey, d.commitments.latest.params.commitmentFormat)
1027-
val sharedInput = d.commitments.latest.commitInput match {
1028-
case _: Transactions.InputInfo.TaprootInput => Musig2Input(parentCommitment)
1029-
case _ => Multisig2of2Input(parentCommitment)
1030-
}
1027+
val sharedInput = SharedFundingInput(parentCommitment)
10311028
LiquidityAds.validateRequest(nodeParams.privateKey, d.channelId, fundingScript, msg.feerate, isChannelCreation = false, msg.requestFunding_opt, nodeParams.liquidityAdsConfig.rates_opt, msg.useFeeCredit_opt) match {
10321029
case Left(t) =>
10331030
log.warning("rejecting splice request with invalid liquidity ads: {}", t.getMessage)
@@ -1085,10 +1082,7 @@ class Channel(val nodeParams: NodeParams, val wallet: OnChainChannelFunder with
10851082
case SpliceStatus.SpliceRequested(cmd, spliceInit) =>
10861083
log.info("our peer accepted our splice request and will contribute {} to the funding transaction", msg.fundingContribution)
10871084
val parentCommitment = d.commitments.latest.commitment
1088-
val sharedInput = d.commitments.latest.commitInput match {
1089-
case _: Transactions.InputInfo.TaprootInput => Musig2Input(parentCommitment)
1090-
case _ => Multisig2of2Input(parentCommitment)
1091-
}
1085+
val sharedInput = SharedFundingInput(parentCommitment)
10921086
val fundingParams = InteractiveTxParams(
10931087
channelId = d.channelId,
10941088
isInitiator = true,
@@ -1169,7 +1163,7 @@ class Channel(val nodeParams: NodeParams, val wallet: OnChainChannelFunder with
11691163
isInitiator = false,
11701164
localContribution = fundingContribution,
11711165
remoteContribution = msg.fundingContribution,
1172-
sharedInput_opt = Some(Multisig2of2Input(rbf.parentCommitment)),
1166+
sharedInput_opt = Some(SharedFundingInput(rbf.parentCommitment)),
11731167
remoteFundingPubKey = rbf.latestFundingTx.fundingParams.remoteFundingPubKey,
11741168
localOutputs = rbf.latestFundingTx.fundingParams.localOutputs,
11751169
lockTime = msg.lockTime,
@@ -1222,7 +1216,7 @@ class Channel(val nodeParams: NodeParams, val wallet: OnChainChannelFunder with
12221216
isInitiator = true,
12231217
localContribution = txInitRbf.fundingContribution,
12241218
remoteContribution = msg.fundingContribution,
1225-
sharedInput_opt = Some(Multisig2of2Input(rbf.parentCommitment)),
1219+
sharedInput_opt = Some(SharedFundingInput(rbf.parentCommitment)),
12261220
remoteFundingPubKey = rbf.latestFundingTx.fundingParams.remoteFundingPubKey,
12271221
localOutputs = rbf.latestFundingTx.fundingParams.localOutputs,
12281222
lockTime = txInitRbf.lockTime,
@@ -3258,7 +3252,7 @@ class Channel(val nodeParams: NodeParams, val wallet: OnChainChannelFunder with
32583252
val targetFeerate = nodeParams.onChainFeeConf.getFundingFeerate(nodeParams.currentFeeratesForFundingClosing)
32593253
val fundingContribution = InteractiveTxFunder.computeSpliceContribution(
32603254
isInitiator = true,
3261-
sharedInput = Multisig2of2Input(parentCommitment),
3255+
sharedInput = SharedFundingInput(parentCommitment),
32623256
spliceInAmount = cmd.additionalLocalFunding,
32633257
spliceOut = cmd.spliceOutputs,
32643258
targetFeerate = targetFeerate)

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ object InteractiveTxBuilder {
109109
// @formatter:on
110110
}
111111

112+
object SharedFundingInput {
113+
def apply(commitment: Commitment): SharedFundingInput = commitment.commitInput match {
114+
case inputInfo: InputInfo.SegwitInput => Multisig2of2Input(inputInfo, commitment.fundingTxIndex, commitment.remoteFundingPubKey)
115+
case inputInfo: InputInfo.TaprootInput => Musig2Input(inputInfo, commitment.fundingTxIndex, commitment.remoteFundingPubKey, commitment.localCommit.index)
116+
}
117+
}
118+
112119
case class Multisig2of2Input(info: InputInfo, fundingTxIndex: Long, remoteFundingPubkey: PublicKey) extends SharedFundingInput {
113120
override val weight: Int = 388
114121

@@ -118,29 +125,12 @@ object InteractiveTxBuilder {
118125
}
119126
}
120127

121-
object Multisig2of2Input {
122-
def apply(commitment: Commitment): Multisig2of2Input = Multisig2of2Input(
123-
info = commitment.commitInput,
124-
fundingTxIndex = commitment.fundingTxIndex,
125-
remoteFundingPubkey = commitment.remoteFundingPubKey
126-
)
127-
}
128-
129128
case class Musig2Input(info: InputInfo, fundingTxIndex: Long, remoteFundingPubkey: PublicKey, commitIndex: Long) extends SharedFundingInput {
130129
override val weight: Int = 234
131130

132131
override def sign(keyManager: ChannelKeyManager, params: ChannelParams, tx: Transaction): ByteVector64 = ByteVector64.Zeroes
133132
}
134-
135-
object Musig2Input {
136-
def apply(commitment: Commitment): Musig2Input = Musig2Input(
137-
info = commitment.commitInput,
138-
fundingTxIndex = commitment.fundingTxIndex,
139-
remoteFundingPubkey = commitment.remoteFundingPubKey,
140-
commitIndex = commitment.localCommit.index
141-
)
142-
}
143-
133+
144134
/**
145135
* @param channelId id of the channel.
146136
* @param isInitiator true if we initiated the protocol, in which case we will pay fees for the shared parts of the transaction.

eclair-core/src/test/scala/fr/acinq/eclair/channel/InteractiveTxBuilderSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ class InteractiveTxBuilderSpec extends TestKitBaseClass with AnyFunSuiteLike wit
8686
}
8787

8888
private def sharedInputs(commitmentA: Commitment, commitmentB: Commitment): (SharedFundingInput, SharedFundingInput) = {
89-
val sharedInputA = Multisig2of2Input(commitmentA)
90-
val sharedInputB = Multisig2of2Input(commitmentB)
89+
val sharedInputA = SharedFundingInput(commitmentA)
90+
val sharedInputB = SharedFundingInput(commitmentB)
9191
(sharedInputA, sharedInputB)
9292
}
9393

0 commit comments

Comments
 (0)