diff --git a/lnwallet/channel.go b/lnwallet/channel.go index d86ec4a5..6dc8b4c0 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -2304,7 +2304,7 @@ func genRemoteHtlcSigJobs(commitPoint *btcec.PublicKey, // decrements the available revocation window by 1. After a successful method // call, the remote party's commitment chain is extended by a new commitment // which includes all updates to the HTLC log prior to this method invocation. -// The first return parameter it he signature for the commitment transaction +// The first return parameter is the signature for the commitment transaction // itself, while the second parameter is a slice of all HTLC signatures (if // any). The HTLC signatures are sorted according to the BIP 69 order of the // HTLC's on the commitment transaction. @@ -2329,7 +2329,7 @@ func (lc *LightningChannel) SignNextCommitment() (*btcec.Signature, []*btcec.Sig return nil, nil, err } - // Grab the next commitment point for the remote party. This well be + // Grab the next commitment point for the remote party. This will be // used within fetchCommitmentView to derive all the keys necessary to // construct the commitment state. commitPoint := lc.channelState.RemoteNextRevocation @@ -2390,13 +2390,14 @@ func (lc *LightningChannel) SignNextCommitment() (*btcec.Signature, []*btcec.Sig // 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. - sortedSigs := sortableSignBatch(sigBatch) - sort.Sort(sortedSigs) + sort.Slice(sigBatch, func(i, j int) bool { + return sigBatch[i].outputIndex < sigBatch[j].outputIndex + }) // With the jobs sorted, we'll now iterate through all the responses to // gather each of the signatures in order. htlcSigs := make([]*btcec.Signature, 0, len(sigBatch)) - for _, htlcSigJob := range sortedSigs { + for _, htlcSigJob := range sigBatch { jobResp := <-htlcSigJob.resp // If an error occurred, then we'll cancel any other active diff --git a/lnwallet/sigpool.go b/lnwallet/sigpool.go index 2c7ce0d6..bc0c659e 100644 --- a/lnwallet/sigpool.go +++ b/lnwallet/sigpool.go @@ -83,29 +83,6 @@ type signJob struct { resp chan signJobResp } -// sortableSignBatch is a type wrapper around a slice of signJobs which is able -// to sort each job according to tis outputs index. Such sorting is necessary -// as when creating a new commitment state, we need to send over all the HTLC -// signatures (if any) in the exact order the appears on the commitment -// transaction after BIP 69 sorting. -type sortableSignBatch []signJob - -// Len returns the number of items sortable batch of sign jobs. It is part of -// the sort.Interface implementation. -func (s sortableSignBatch) Len() int { return len(s) } - -// Less returns whether the item in the batch with index i should sort before -// the item with index j. It is part of the sort.Interface implementation. -func (s sortableSignBatch) Less(i, j int) bool { - return s[i].outputIndex < s[j].outputIndex -} - -// Swap swaps the items at the passed indices in the priority queue. It is part -// of the sort.Interface implementation. -func (s sortableSignBatch) Swap(i, j int) { - s[i], s[j] = s[j], s[i] -} - // signJobResp is the response to a sign job. Both channels are to be read in // order to ensure no unnecessary goroutine blocking occurs. Additionally, both // channels should be buffered.