Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 650d06f

Browse files
committed
Fix tip selection to select corrent number of unique tips.
1 parent 1d52744 commit 650d06f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pkg/protocol/engine/tipselection/v1/tip_selection.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func (t *TipSelection) likedInsteadReferences(likedConflicts ds.Set[iotago.Trans
214214
return references, updatedLikedConflicts, nil
215215
}
216216

217-
// collectReferences collects tips from a tip selector (and calls the callback for each tip) until the amount of
217+
// collectReferences collects tips from a tip selector (and calls the callback for each tip) until the number of
218218
// references of the given type is reached.
219219
func (t *TipSelection) collectReferences(callback func(tipmanager.TipMetadata), tipSelectorsAmount ...*types.Tuple[func(optAmount ...int) []tipmanager.TipMetadata, int]) {
220220
seenTips := ds.NewSet[iotago.BlockID]()
@@ -236,9 +236,14 @@ func (t *TipSelection) collectReferences(callback func(tipmanager.TipMetadata),
236236
return uniqueTips
237237
}
238238

239-
// We select the desired amount of tips from all given tip selectors, respectively.
239+
accumulatedTipAmount := 0
240+
// We select the desired number of tips from all given tip selectors, respectively.
240241
for _, tipSelectorAmount := range tipSelectorsAmount {
241-
for tipCandidates := selectUniqueTips(tipSelectorAmount.A, tipSelectorAmount.B); len(tipCandidates) != 0; tipCandidates = selectUniqueTips(tipSelectorAmount.A, tipSelectorAmount.B) {
242+
// Make sure we select the total number of unique tips and not just the number of tips from the given tip pool,
243+
// because of how selectUniqueTips works.
244+
accumulatedTipAmount += tipSelectorAmount.B
245+
246+
for tipCandidates := selectUniqueTips(tipSelectorAmount.A, accumulatedTipAmount); len(tipCandidates) != 0; tipCandidates = selectUniqueTips(tipSelectorAmount.A, accumulatedTipAmount) {
242247
for _, tip := range tipCandidates {
243248
callback(tip)
244249
}

0 commit comments

Comments
 (0)