From 46a8d8889c668cf291607963fd7301f21aa634b5 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Wed, 21 Feb 2024 10:07:56 +0200 Subject: [PATCH] small refactor --- lib/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index fd7f9a8..d229d68 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 }