@@ -647,15 +647,15 @@ func (lc *LightningChannel) diskCommitToMemCommit(
647647 // haven't yet received a responding commitment from the remote party.
648648 var commitKeys lntypes.Dual [* CommitmentKeyRing ]
649649 if localCommitPoint != nil {
650- commitKeys .SetForParty (lntypes .Local , DeriveCommitmentKeys (
650+ commitKeys .SetForParty (lntypes .Local , lc . deriveCommitmentKeys (
651651 localCommitPoint , lntypes .Local ,
652652 lc .channelState .ChanType ,
653653 & lc .channelState .LocalChanCfg ,
654654 & lc .channelState .RemoteChanCfg ,
655655 ))
656656 }
657657 if remoteCommitPoint != nil {
658- commitKeys .SetForParty (lntypes .Remote , DeriveCommitmentKeys (
658+ commitKeys .SetForParty (lntypes .Remote , lc . deriveCommitmentKeys (
659659 remoteCommitPoint , lntypes .Remote ,
660660 lc .channelState .ChanType ,
661661 & lc .channelState .LocalChanCfg ,
@@ -864,6 +864,10 @@ type channelOpts struct {
864864 // standard sig.Verify method is used.
865865 sigVerifier SigVerifier
866866
867+ // commitKeyDeriver is an optional override for DeriveCommitmentKeys.
868+ // When nil, the real secp256k1-based function is used.
869+ commitKeyDeriver CommitKeyDeriverFunc
870+
867871 skipNonceInit bool
868872}
869873
@@ -942,6 +946,25 @@ func (lc *LightningChannel) verifySig(sig input.Signature, sigHash []byte,
942946 return sig .Verify (sigHash , pubKey )
943947}
944948
949+ // deriveCommitmentKeys calls the injected CommitKeyDeriverFunc if one is set,
950+ // otherwise falls back to the real secp256k1-based DeriveCommitmentKeys.
951+ func (lc * LightningChannel ) deriveCommitmentKeys (commitPoint * btcec.PublicKey ,
952+ whoseCommit lntypes.ChannelParty , chanType channeldb.ChannelType ,
953+ localChanCfg , remoteChanCfg * channeldb.ChannelConfig ) * CommitmentKeyRing { //nolint:ll
954+
955+ if lc .opts .commitKeyDeriver != nil {
956+ return lc .opts .commitKeyDeriver (
957+ commitPoint , whoseCommit , chanType ,
958+ localChanCfg , remoteChanCfg ,
959+ )
960+ }
961+
962+ return DeriveCommitmentKeys (
963+ commitPoint , whoseCommit , chanType ,
964+ localChanCfg , remoteChanCfg ,
965+ )
966+ }
967+
945968// NewLightningChannel creates a new, active payment channel given an
946969// implementation of the chain notifier, channel database, and the current
947970// settled channel state. Throughout state transitions, then channel will
@@ -1565,7 +1588,7 @@ func (lc *LightningChannel) restoreCommitState(
15651588
15661589 // We'll also re-create the set of commitment keys needed to
15671590 // fully re-derive the state.
1568- pendingRemoteKeyChain = DeriveCommitmentKeys (
1591+ pendingRemoteKeyChain = lc . deriveCommitmentKeys (
15691592 pendingCommitPoint , lntypes .Remote ,
15701593 lc .channelState .ChanType ,
15711594 & lc .channelState .LocalChanCfg ,
@@ -4164,7 +4187,7 @@ func (lc *LightningChannel) SignNextCommitment(
41644187 // Grab the next commitment point for the remote party. This will be
41654188 // used within fetchCommitmentView to derive all the keys necessary to
41664189 // construct the commitment state.
4167- keyRing := DeriveCommitmentKeys (
4190+ keyRing := lc . deriveCommitmentKeys (
41684191 commitPoint , lntypes .Remote , lc .channelState .ChanType ,
41694192 & lc .channelState .LocalChanCfg , & lc .channelState .RemoteChanCfg ,
41704193 )
@@ -5365,7 +5388,7 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
53655388 return err
53665389 }
53675390 commitPoint := input .ComputeCommitmentPoint (commitSecret [:])
5368- keyRing := DeriveCommitmentKeys (
5391+ keyRing := lc . deriveCommitmentKeys (
53695392 commitPoint , lntypes .Local , lc .channelState .ChanType ,
53705393 & lc .channelState .LocalChanCfg , & lc .channelState .RemoteChanCfg ,
53715394 )
@@ -8901,7 +8924,7 @@ func (lc *LightningChannel) NewAnchorResolutions() (*AnchorResolutions,
89018924 return nil , err
89028925 }
89038926 localCommitPoint := input .ComputeCommitmentPoint (revocation [:])
8904- localKeyRing := DeriveCommitmentKeys (
8927+ localKeyRing := lc . deriveCommitmentKeys (
89058928 localCommitPoint , lntypes .Local , lc .channelState .ChanType ,
89068929 & lc .channelState .LocalChanCfg , & lc .channelState .RemoteChanCfg ,
89078930 )
@@ -8915,7 +8938,7 @@ func (lc *LightningChannel) NewAnchorResolutions() (*AnchorResolutions,
89158938 resolutions .Local = localRes
89168939
89178940 // Add anchor for remote commitment tx, if any.
8918- remoteKeyRing := DeriveCommitmentKeys (
8941+ remoteKeyRing := lc . deriveCommitmentKeys (
89198942 lc .channelState .RemoteCurrentRevocation , lntypes .Remote ,
89208943 lc .channelState .ChanType , & lc .channelState .LocalChanCfg ,
89218944 & lc .channelState .RemoteChanCfg ,
@@ -8936,7 +8959,7 @@ func (lc *LightningChannel) NewAnchorResolutions() (*AnchorResolutions,
89368959 }
89378960
89388961 if remotePendingCommit != nil {
8939- pendingRemoteKeyRing := DeriveCommitmentKeys (
8962+ pendingRemoteKeyRing := lc . deriveCommitmentKeys (
89408963 lc .channelState .RemoteNextRevocation , lntypes .Remote ,
89418964 lc .channelState .ChanType , & lc .channelState .LocalChanCfg ,
89428965 & lc .channelState .RemoteChanCfg ,
0 commit comments