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.
This commit is contained in:
you
2026-03-23 16:33:39 +00:00
parent 4353f71f4a
commit a2e795f2a6
+6 -3
View File
@@ -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 {}
}