Skip to content

Commit 0746763

Browse files
committed
lnwallet: surface initial commitment key ring for force close
1 parent e8b7542 commit 0746763

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

lnwallet/aux_resolutions.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ type ResolutionReq struct {
9494
// KeyRing is the key ring for the channel.
9595
KeyRing *CommitmentKeyRing
9696

97+
// InitialKeyRing is the key ring for the initial commitment state at
98+
// height 0. This lets downstream resolvers distinguish "just opened"
99+
// commitment outputs from later states that use the post-channel_ready
100+
// commitment point.
101+
InitialKeyRing *CommitmentKeyRing
102+
97103
// CsvDelay is the CSV delay for the local output for this commitment.
98104
CsvDelay uint32
99105

lnwallet/channel.go

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)