@@ -633,6 +633,49 @@ func (lc *LightningChannel) extractPayDescs(feeRate chainfee.SatPerKWeight,
633633 return incomingHtlcs , outgoingHtlcs , nil
634634}
635635
636+ // initialCommitmentKeyRing derives the key ring for the initial commitment
637+ // state at height 0. This is distinct from the live key ring after
638+ // channel_ready, which already moved on to the next per-commitment point.
639+ // If the initial commitment point can't be derived, then nil is returned and
640+ // the caller should fall back to the live key ring.
641+ func initialCommitmentKeyRingFromState (chanState * channeldb.OpenChannel ,
642+ whoseCommit lntypes.ChannelParty ) * CommitmentKeyRing {
643+
644+ switch {
645+ case whoseCommit .IsLocal ():
646+ revocation , err := chanState .RevocationProducer .AtIndex (0 )
647+ if err != nil {
648+ return nil
649+ }
650+
651+ commitPoint := input .ComputeCommitmentPoint (revocation [:])
652+ return DeriveCommitmentKeys (
653+ commitPoint , lntypes .Local , chanState .ChanType ,
654+ & chanState .LocalChanCfg , & chanState .RemoteChanCfg ,
655+ )
656+
657+ case whoseCommit .IsRemote ():
658+ if chanState .RemoteCurrentRevocation == nil {
659+ return nil
660+ }
661+
662+ return DeriveCommitmentKeys (
663+ chanState .RemoteCurrentRevocation , lntypes .Remote ,
664+ chanState .ChanType , & chanState .LocalChanCfg ,
665+ & chanState .RemoteChanCfg ,
666+ )
667+
668+ default :
669+ return nil
670+ }
671+ }
672+
673+ func (lc * LightningChannel ) initialCommitmentKeyRing (
674+ whoseCommit lntypes.ChannelParty ) * CommitmentKeyRing {
675+
676+ return initialCommitmentKeyRingFromState (lc .channelState , whoseCommit )
677+ }
678+
636679// diskCommitToMemCommit converts the on-disk commitment format to our
637680// in-memory commitment format which is needed in order to properly resume
638681// channel operations after a restart.
@@ -8539,8 +8582,11 @@ func NewLocalForceCloseSummary(chanState *channeldb.OpenChannel,
85398582 ContractPoint : commitResolution .SelfOutPoint ,
85408583 SignDesc : commitResolution .SelfOutputSignDesc ,
85418584 KeyRing : keyRing ,
8542- CsvDelay : csvTimeout ,
8543- CommitFee : chanState .LocalCommitment .CommitFee ,
8585+ InitialKeyRing : initialCommitmentKeyRingFromState (
8586+ chanState , lntypes .Local ,
8587+ ),
8588+ CsvDelay : csvTimeout ,
8589+ CommitFee : chanState .LocalCommitment .CommitFee ,
85448590 })
85458591 },
85468592 )
0 commit comments