From a2e795f2a6648bf81b317ccbaad8d18064ad9d97 Mon Sep 17 00:00:00 2001 From: you Date: Mon, 23 Mar 2026 16:33:39 +0000 Subject: [PATCH] fix: hash_size uses max across all adverts, not just newest Some nodes emit adverts with varying path byte values (e.g. 0x00 and 0x40). Taking the first/newest was unreliable. Now takes the maximum hash_size seen across all adverts for each node. --- server.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index e13a5dec..1368ba4b 100644 --- a/server.js +++ b/server.js @@ -47,15 +47,18 @@ const _hashSizeMap = new Map(); function _rebuildHashSizeMap() { _hashSizeMap.clear(); // Pass 1: from ADVERT packets (most authoritative — path byte bits 7-6) - // packets array is sorted newest-first, so first-match = newest ADVERT + // Take the MAXIMUM hash_size seen across all adverts (nodes can change config) for (const p of pktStore.packets) { if (p.payload_type === 4 && p.raw_hex) { try { const d = JSON.parse(p.decoded_json || '{}'); const pk = d.pubKey || d.public_key; - if (pk && !_hashSizeMap.has(pk)) { + if (pk) { const pathByte = parseInt(p.raw_hex.slice(2, 4), 16); - _hashSizeMap.set(pk, ((pathByte >> 6) & 0x3) + 1); + const hs = ((pathByte >> 6) & 0x3) + 1; + if (!_hashSizeMap.has(pk) || hs > _hashSizeMap.get(pk)) { + _hashSizeMap.set(pk, hs); + } } } catch {} }