Skip to content

Commit f4fbdce

Browse files
sstonet-bast
andauthored
Apply suggestions from code review
Refactor derivation of anchor keys. Co-authored-by: Bastien Teinturier <[email protected]>
1 parent 51fb974 commit f4fbdce

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

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

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,8 @@ object Helpers {
372372

373373
object Funding {
374374
def makeFundingPubKeyScript(localFundingKey: PublicKey, remoteFundingKey: PublicKey, commitmentFormat: CommitmentFormat): ByteVector = commitmentFormat match {
375-
case SimpleTaprootChannelCommitmentFormat =>
376-
write(Taproot.musig2FundingScript(localFundingKey, remoteFundingKey))
377-
case _ =>
378-
write(pay2wsh(multiSig2of2(localFundingKey, remoteFundingKey)))
375+
case DefaultCommitmentFormat | _: AnchorOutputsCommitmentFormat => write(pay2wsh(multiSig2of2(localFundingKey, remoteFundingKey)))
376+
case SimpleTaprootChannelCommitmentFormat => write(Taproot.musig2FundingScript(localFundingKey, remoteFundingKey))
379377
}
380378

381379
def makeFundingInputInfo(fundingTxId: TxId, fundingTxOutputIndex: Int, fundingSatoshis: Satoshi, fundingPubkey1: PublicKey, fundingPubkey2: PublicKey, commitmentFormat: CommitmentFormat): InputInfo = commitmentFormat match {
@@ -907,19 +905,18 @@ object Helpers {
907905

908906
def claimAnchors(keyManager: ChannelKeyManager, commitment: FullCommitment, lcp: LocalCommitPublished, confirmationTarget: ConfirmationTarget)(implicit log: LoggingAdapter): LocalCommitPublished = {
909907
if (shouldUpdateAnchorTxs(lcp.claimAnchorTxs, confirmationTarget)) {
910-
val localFundingPubKey = keyManager.fundingPublicKey(commitment.localParams.fundingKeyPath, commitment.fundingTxIndex).publicKey
911-
val localPaymentKey = commitment.params.commitmentFormat match {
908+
val (localAnchorKey, remoteAnchorKey) = commitment.params.commitmentFormat match {
909+
case DefaultCommitmentFormat | _: AnchorOutputsCommitmentFormat =>
910+
// The public keys used in this case are the channel funding public keys.
911+
val localFundingPubkey = keyManager.fundingPublicKey(commitment.localParams.fundingKeyPath, commitment.fundingTxIndex).publicKey
912+
(localFundingPubkey, commitment.remoteFundingPubKey)
912913
case SimpleTaprootChannelCommitmentFormat =>
914+
// The public keys used in this case are the payment public keys: we don't want to reveal individual
915+
// funding public keys since we're using musig2.
913916
val channelKeyPath = keyManager.keyPath(commitment.localParams, commitment.params.channelConfig)
914917
val localPerCommitmentPoint = keyManager.commitmentPoint(channelKeyPath, commitment.localCommit.index)
915918
val localDelayedPaymentPubkey = Generators.derivePubKey(keyManager.delayedPaymentPoint(channelKeyPath).publicKey, localPerCommitmentPoint)
916-
localDelayedPaymentPubkey
917-
case _ =>
918-
localFundingPubKey
919-
}
920-
val remotePaymentKey = commitment.params.commitmentFormat match {
921-
case SimpleTaprootChannelCommitmentFormat => commitment.remoteParams.paymentBasepoint
922-
case _ => commitment.remoteFundingPubKey
919+
(localDelayedPaymentPubkey, commitment.remoteParams.paymentBasepoint)
923920
}
924921
val claimAnchorTxs = List(
925922
withTxGenerationLog("local-anchor") {
@@ -1041,22 +1038,16 @@ object Helpers {
10411038

10421039
def claimAnchors(keyManager: ChannelKeyManager, commitment: FullCommitment, rcp: RemoteCommitPublished, confirmationTarget: ConfirmationTarget)(implicit log: LoggingAdapter): RemoteCommitPublished = {
10431040
if (shouldUpdateAnchorTxs(rcp.claimAnchorTxs, confirmationTarget)) {
1044-
val localFundingPubkey = keyManager.fundingPublicKey(commitment.localParams.fundingKeyPath, commitment.fundingTxIndex).publicKey
1045-
1046-
// taproot channels do not re-use the funding pubkeys for anchor outputs
1047-
val localPaymentKey = commitment.params.commitmentFormat match {
1041+
val (localAnchorKey, remoteAnchorKey) = commitment.params.commitmentFormat match {
1042+
case DefaultCommitmentFormat | _: AnchorOutputsCommitmentFormat =>
1043+
// The public keys used in this case are the channel funding public keys.
1044+
val localFundingPubkey = keyManager.fundingPublicKey(commitment.localParams.fundingKeyPath, commitment.fundingTxIndex).publicKey
1045+
(localFundingPubkey, commitment.remoteFundingPubKey)
10481046
case SimpleTaprootChannelCommitmentFormat =>
10491047
val channelKeyPath = keyManager.keyPath(commitment.localParams, commitment.params.channelConfig)
1050-
commitment.localParams.walletStaticPaymentBasepoint.getOrElse(keyManager.paymentPoint(channelKeyPath).publicKey)
1051-
case _ =>
1052-
localFundingPubkey
1053-
}
1054-
val remotePaymentKey = commitment.params.commitmentFormat match {
1055-
case SimpleTaprootChannelCommitmentFormat =>
1048+
val localPaymentPubkey = commitment.localParams.walletStaticPaymentBasepoint.getOrElse(keyManager.paymentPoint(channelKeyPath).publicKey)
10561049
val remoteDelayedPaymentPubkey = Generators.derivePubKey(commitment.remoteParams.delayedPaymentBasepoint, commitment.remoteCommit.remotePerCommitmentPoint)
1057-
remoteDelayedPaymentPubkey
1058-
case _ =>
1059-
commitment.remoteFundingPubKey
1050+
(localPaymentPubkey, remoteDelayedPaymentPubkey)
10601051
}
10611052
val claimAnchorTxs = List(
10621053
withTxGenerationLog("local-anchor") {

0 commit comments

Comments
 (0)