Skip to content

Commit

Permalink
Merge 34d48ea into 42743ef
Browse files Browse the repository at this point in the history
  • Loading branch information
flaurida committed Sep 3, 2017
2 parents 42743ef + 34d48ea commit 7dea071
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 28 deletions.
11 changes: 6 additions & 5 deletions lnwallet/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2272,7 +2272,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.
Expand All @@ -2297,7 +2297,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
Expand Down Expand Up @@ -2358,13 +2358,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
Expand Down
23 changes: 0 additions & 23 deletions lnwallet/sigpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7dea071

Please sign in to comment.