lnwallet: fix bug in extractHtlcResolutions, ensure slice is contiguous
This commit fixes an existing bug within extractHtlcResolutions. The prior code would use an index to assign the returned OutgoingHtlcResolutions into a single slice. However, this is invalid as there are two cases where an HTLC might be skipped: if it’s an incoming HTLC, or if the HLTC itself is dust from the PoV of the commitment chain. To fix this, we now instead use append to add items to the slice. This ensure that we don’t have any “empty” items in between fully populated items.
This commit is contained in:
parent
2141b481ef
commit
dc764c992c
@ -3521,8 +3521,8 @@ func extractHtlcResolutions(feePerKw btcutil.Amount, ourCommit bool,
|
||||
csvDelay = localChanCfg.CsvDelay
|
||||
}
|
||||
|
||||
htlcResolutions := make([]OutgoingHtlcResolution, len(htlcs))
|
||||
for i, htlc := range htlcs {
|
||||
htlcResolutions := make([]OutgoingHtlcResolution, 0, len(htlcs))
|
||||
for _, htlc := range htlcs {
|
||||
// Skip any incoming HTLC's, as unless we have the pre-image to
|
||||
// spend them, they'll eventually be swept by the party that
|
||||
// offered the HTLC after the timeout.
|
||||
@ -3548,7 +3548,7 @@ func extractHtlcResolutions(feePerKw btcutil.Amount, ourCommit bool,
|
||||
}
|
||||
|
||||
// TODO(roasbeef): needs to point to proper amount including
|
||||
htlcResolutions[i] = *ohr
|
||||
htlcResolutions = append(htlcResolutions, *ohr)
|
||||
}
|
||||
|
||||
return htlcResolutions, localKey, nil
|
||||
|
Loading…
Reference in New Issue
Block a user