Skip to content

Commit 645b950

Browse files
committed
tapchannel: add HtlcIndex to allocation sort
This fixes a bug where the order of the HTLCs would not be deterministic between two peers if they were identical due to them being shards of the same MPP payment. By adding the HTLC index as a further sort argument, the order is again stable and deterministic.
1 parent 53e8997 commit 645b950

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tapchannel/allocation_sort.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (s sortableAllocationSlice) Swap(i, j int) {
4343
}
4444

4545
// Less is a modified BIP69 output comparison, that sorts based on value, then
46-
// pkScript, then CLTV value.
46+
// pkScript, then CLTV value and finally HtlcIndex.
4747
//
4848
// NOTE: Part of the sort.Interface interface.
4949
func (s sortableAllocationSlice) Less(i, j int) bool {
@@ -60,5 +60,9 @@ func (s sortableAllocationSlice) Less(i, j int) bool {
6060
return pkScriptCmp < 0
6161
}
6262

63-
return allocI.CLTV < allocJ.CLTV
63+
if allocI.CLTV < allocJ.CLTV {
64+
return true
65+
}
66+
67+
return allocI.HtlcIndex < allocJ.HtlcIndex
6468
}

0 commit comments

Comments
 (0)