lnwallet: replace sort.Sort with sort.Slice in channel.go

Use sort.Slice in SignNextCommitment function in lnwallet/channel.go,
as part of the move to use new language features. Remove
sortableSignBatch type wrapper for slice of signJobs since it is
no longer needed to sort jobs according to their output indices.
Also fix a few minor typos in channel.go and sigpool.go.
This commit is contained in:
flaurida 2017-09-03 18:38:36 -04:00 committed by Olaoluwa Osuntokun
parent 685e09c904
commit e106cfdef1
2 changed files with 6 additions and 28 deletions

View File

@ -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

View File

@ -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.