lnwallet/channel: populate htlc indexes from disk commit
We currently write each HTLCs OutputIndex to disk, but we don't use it when restoring. The restoration is modified to use these directly, since we will have lost access to the sorting of CLTVs after the initial signing process.
This commit is contained in:
parent
c14d99f05d
commit
97761833d2
@ -766,7 +766,8 @@ func (c *commitment) toDiskCommit(ourCommit bool) *channeldb.ChannelCommitment {
|
||||
// restart a channel session.
|
||||
func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
|
||||
commitHeight uint64, htlc *channeldb.HTLC, localCommitKeys,
|
||||
remoteCommitKeys *CommitmentKeyRing) (PaymentDescriptor, error) {
|
||||
remoteCommitKeys *CommitmentKeyRing, isLocal bool) (PaymentDescriptor,
|
||||
error) {
|
||||
|
||||
// The proper pkScripts for this PaymentDescriptor must be
|
||||
// generated so we can easily locate them within the commitment
|
||||
@ -811,6 +812,19 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
|
||||
}
|
||||
}
|
||||
|
||||
// Reconstruct the proper local/remote output indexes from the HTLC's
|
||||
// persisted output index depending on whose commitment we are
|
||||
// generating.
|
||||
var (
|
||||
localOutputIndex int32
|
||||
remoteOutputIndex int32
|
||||
)
|
||||
if isLocal {
|
||||
localOutputIndex = htlc.OutputIndex
|
||||
} else {
|
||||
remoteOutputIndex = htlc.OutputIndex
|
||||
}
|
||||
|
||||
// With the scripts reconstructed (depending on if this is our commit
|
||||
// vs theirs or a pending commit for the remote party), we can now
|
||||
// re-create the original payment descriptor.
|
||||
@ -822,6 +836,8 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
|
||||
HtlcIndex: htlc.HtlcIndex,
|
||||
LogIndex: htlc.LogIndex,
|
||||
OnionBlob: htlc.OnionBlob,
|
||||
localOutputIndex: localOutputIndex,
|
||||
remoteOutputIndex: remoteOutputIndex,
|
||||
ourPkScript: ourP2WSH,
|
||||
ourWitnessScript: ourWitnessScript,
|
||||
theirPkScript: theirP2WSH,
|
||||
@ -837,7 +853,8 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
|
||||
// for each side.
|
||||
func (lc *LightningChannel) extractPayDescs(commitHeight uint64,
|
||||
feeRate chainfee.SatPerKWeight, htlcs []channeldb.HTLC, localCommitKeys,
|
||||
remoteCommitKeys *CommitmentKeyRing) ([]PaymentDescriptor, []PaymentDescriptor, error) {
|
||||
remoteCommitKeys *CommitmentKeyRing, isLocal bool) ([]PaymentDescriptor,
|
||||
[]PaymentDescriptor, error) {
|
||||
|
||||
var (
|
||||
incomingHtlcs []PaymentDescriptor
|
||||
@ -855,6 +872,7 @@ func (lc *LightningChannel) extractPayDescs(commitHeight uint64,
|
||||
payDesc, err := lc.diskHtlcToPayDesc(
|
||||
feeRate, commitHeight, &htlc,
|
||||
localCommitKeys, remoteCommitKeys,
|
||||
isLocal,
|
||||
)
|
||||
if err != nil {
|
||||
return incomingHtlcs, outgoingHtlcs, err
|
||||
@ -905,6 +923,7 @@ func (lc *LightningChannel) diskCommitToMemCommit(isLocal bool,
|
||||
diskCommit.CommitHeight,
|
||||
chainfee.SatPerKWeight(diskCommit.FeePerKw),
|
||||
diskCommit.Htlcs, localCommitKeys, remoteCommitKeys,
|
||||
isLocal,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -934,13 +953,6 @@ func (lc *LightningChannel) diskCommitToMemCommit(isLocal bool,
|
||||
commit.dustLimit = lc.channelState.RemoteChanCfg.DustLimit
|
||||
}
|
||||
|
||||
// Finally, we'll re-populate the HTLC index for this state so we can
|
||||
// properly locate each HTLC within the commitment transaction.
|
||||
err = commit.populateHtlcIndexes(lc.channelState.ChanType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return commit, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user