From dc764c992c36e8378304060694781ae5ef3fbf6c Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 29 Sep 2017 14:32:11 -0700 Subject: [PATCH] lnwallet: fix bug in extractHtlcResolutions, ensure slice is contiguous MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lnwallet/channel.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index dad73d07..3f6bcfba 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -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