lnwallet: in NewBreachRetribution create the htlcRetributions slice to capacity, not length
In this commit, we fix an existing bug in the NewBreachRetribution method. Rather than creating the slice to the proper length, we instead now create it to the proper _capacity_. As we'll now properly filter out any dust HTLCs, before this commit, even if no HTLCs were added, then the slice would still have a full length, meaning callers could actually interact with _blank_ HtlcRetribution structs. The fix is simple: create the slice with the proper capacity, and append to the end of it.
This commit is contained in:
parent
c393475d39
commit
f79af461d3
@ -1969,8 +1969,8 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||
// With the commitment outputs located, we'll now generate all the
|
||||
// retribution structs for each of the HTLC transactions active on the
|
||||
// remote commitment transaction.
|
||||
htlcRetributions := make([]HtlcRetribution, len(revokedSnapshot.Htlcs))
|
||||
for i, htlc := range revokedSnapshot.Htlcs {
|
||||
htlcRetributions := make([]HtlcRetribution, 0, len(revokedSnapshot.Htlcs))
|
||||
for _, htlc := range revokedSnapshot.Htlcs {
|
||||
var (
|
||||
htlcScript []byte
|
||||
err error
|
||||
@ -2023,7 +2023,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||
}
|
||||
}
|
||||
|
||||
htlcRetributions[i] = HtlcRetribution{
|
||||
htlcRetributions = append(htlcRetributions, HtlcRetribution{
|
||||
SignDesc: SignDescriptor{
|
||||
KeyDesc: chanState.LocalChanCfg.RevocationBasePoint,
|
||||
DoubleTweak: commitmentSecret,
|
||||
@ -2039,7 +2039,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||
},
|
||||
SecondLevelWitnessScript: secondLevelWitnessScript,
|
||||
IsIncoming: htlc.Incoming,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Finally, with all the necessary data constructed, we can create the
|
||||
|
Loading…
Reference in New Issue
Block a user