Skip to content

Commit

Permalink
lnwallet: sort sig jobs after err handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jharveyb committed Sep 8, 2024
1 parent 157b103 commit ee97c4a
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lnwallet/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"errors"
"fmt"
"math"
"sort"
"slices"
"sync"

"github.com/btcsuite/btcd/blockchain"
Expand Down Expand Up @@ -4686,18 +4686,8 @@ func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
}
}

// We'll need to send over the signatures to the remote party in the
// order as they appear on the commitment transaction after BIP 69
// sorting.
sort.Slice(sigBatch, func(i, j int) bool {
return sigBatch[i].OutputIndex < sigBatch[j].OutputIndex
})
sort.Slice(auxSigBatch, func(i, j int) bool {
return auxSigBatch[i].OutputIndex < auxSigBatch[j].OutputIndex
})

// With the jobs sorted, we'll now iterate through all the responses to
// gather each of the signatures in order.
// Iterate through all the responses to gather each of the signatures
// in the order they were submitted.
htlcSigs = make([]lnwire.Sig, 0, len(sigBatch))
auxSigs := make([]fn.Option[tlv.Blob], 0, len(auxSigBatch))
for i := range sigBatch {
Expand Down Expand Up @@ -4740,6 +4730,16 @@ func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
auxSigs = append(auxSigs, auxJobResp.SigBlob)
}

// We'll need to send over the signatures to the remote party in the
// order as they appear on the commitment transaction after BIP 69
// sorting.
slices.SortFunc(sigBatch, func(i, j SignJob) int {
return int(i.OutputIndex - j.OutputIndex)
})
slices.SortFunc(auxSigBatch, func(i, j AuxSigJob) int {
return int(i.OutputIndex - j.OutputIndex)
})

// As we're about to proposer a new commitment state for the remote
// party, we'll write this pending state to disk before we exit, so we
// can retransmit it if necessary.
Expand Down

0 comments on commit ee97c4a

Please sign in to comment.