small refactor

This commit is contained in:
Andre Staltz 2024-02-21 10:07:56 +02:00
parent f862c2de62
commit 46a8d8889c
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
1 changed files with 13 additions and 2 deletions

View File

@ -129,6 +129,16 @@ function initGoals(peer, config) {
const watch = Obz()
/**
* @param {Range} range
* @returns {boolean}
*/
function isEmptyRange(range) {
const [min, max] = range
return min > max
}
/**
* Determine the range of msg depths that are goalful for this given tangle.
* @private
* @param {Goal} goal
* @param {Tangle} tangle
@ -226,8 +236,9 @@ function initGoals(peer, config) {
if (goal.type === 'none') break asRoot
const tangle = peer.db.getTangle(msgID)
if (!tangle) break asRoot
const [min, max] = crossGoalWithTangle(goal, tangle)
if (min > max) break asRoot
const range = crossGoalWithTangle(goal, tangle)
if (isEmptyRange(range)) break asRoot
const [min] = range
if (min === 0) return ['goal']
if (min > 0) servesAsTrail = true
}