Skip to content

fix(server): one shared rule for Heard By, direct (no 1-byte hop, TRACE, failed-signature advert, retired prefix) - #31

Merged
efiten merged 5 commits into
masterfrom
feat/direct-heard-shared-rule
Nov 13, 2026
Merged

efiten merged 5 commits into
masterfrom
feat/direct-heard-shared-rule

Conversation

@efiten

@efiten efiten commented Nov 12, 2026

Copy link
Copy Markdown
Owner

What

One rule decides which node an observation heard directly: packetpath.HeardKey (internal/packetpath/heard.go). The ingestor (client receptions, deriveHeardKey) and the server ("Heard By, direct" on the node page, directHeardNode) both use it.

The server rule gets stricter. These no longer credit a node as heard directly:

  1. A 1-byte last hop, even when exactly one known node has that byte. A node CoreScope does not know can share it, and 1 byte is the firmware default hop size.
  2. TRACE: its path bytes are per-hop SNR, not node hashes.
  3. A zero-hop ADVERT with signatureValid: false: the pubkey is not proven to be the transmitter's. An advert without the field still counts.
  4. A 2-byte or longer hop that a retired repeater shares (moved to inactive_nodes, may still relay), the same check uniqueHopPrefix already does for certain liveness (Node liveness (Last Heard, Active status, Notify-me) counts ambiguous 1-byte hops: a silent repeater shows "Active, last relayed 4m ago" Kpa-clawbot/CoreScope#2260).

Unchanged: flood last hop of 2 bytes or more with exactly one candidate, zero-hop adverts on flood and direct (sendZeroHop), direct routes with a path never attribute. The ingestor's behaviour is unchanged: TestDeriveHeardKey_MatchesPacketpath pins it to HeardKey, and the node-discover branch stays in the ingestor.

The node page tooltips ("Heard By, direct" title and its empty state) now say a 1-byte hop is not taken as proof.

This is PR 1 of the node analytics series (only what a node itself did). The analytics page itself is unchanged here.

Measured on staging

Same deployment, same config, two restarts about 10 minutes apart: old rule (staging/2391, e41bcfe) then this branch (staging/2391-dh, 80a600a). Each snapshot was taken once the packet store stopped growing (130,896 and 130,869 packets), from /api/nodes/<pk>/health for all 1932 nodes.

old rule this branch
nodes with at least one direct observer 302 298
direct observer rows 512 499
direct packets credited 945,144 801,783 (-15.2%)
relay-only observer count 20,828 20,771
  • 11 nodes lost direct observers, 0 gained, 4 went to zero.
  • The largest effect is on packets, not observers: an observer that really hears a repeater was also credited with traffic from other nodes sharing its 1-byte prefix. Example repeater 502a3b3f: 5 observers / 15,224 packets before, 3 / 550 after. Repeater 2f0942c8: 21,882 packets before, 825 after.
  • The snapshots do not say which of the four refusals caused each drop; the API does not expose that.
  • About 10 minutes of new traffic separate the two snapshots.

Browser check on staging: the node pages of 502a3b3f and f307fa08 render the direct table with the same rows and totals as the snapshot, and the new tooltip text.

Performance

directHeardNode runs for every observation on each recompute pass (about 3M on a large instance). Old and new test binaries run alternately, minimum ns/op:

  • BenchmarkBuildDirectHeardIndex (existing, 3M observations, 2-byte hops): 64.1 ms old, 68.0 ms new (with the retired check; its prefix map has no retired prefixes).
  • BenchmarkBuildDirectHeardIndex_MixedHops (new, 500k observations, 1/2/3-byte hops, 5% zero-hop adverts): 42.9 ms old, 39.4 ms new. 1-byte hops now stop before the map lookup.

The signature check runs only for ADVERTs, so a zero-hop message does not parse its decoded JSON in this pass (TestDirectHeardNode_ZeroHopNonAdvertLeavesDecodedCacheCold).

Tests

  • go test ./... in internal/packetpath, cmd/ingestor and cmd/server: ok on this branch. On the fork staging base the three suites passed for the first four commits; after the retired commit only go vet and the DirectHeard|Certain tests ran there. Skipped locally: TestSaveGeoFilterPreservesFileMode and TestWriteStatsAtomic_SymlinkAtDestIsReplaced (Windows-only failures, unrelated).
  • node tests/unit/test-direct-rf-heard-by.js (10 passed), node tests/unit/test-frontend-helpers.js (809 passed).
  • New: TestHeardKey (11 cases), TestDeriveHeardKey_MatchesPacketpath, 5 new TestDirectHeardNode cases, TestDirectHeardNode_RetiredPrefixCreditsNobody, the cache test above, and an empty-state title assertion.

Not done

  • No upstream PR yet: the node analytics series goes to the fork first, by decision.
  • The ingestor still accepts a zero-hop advert with a failed signature for client receptions (the companion app verifies signatures itself); this PR keeps ingestor behaviour unchanged on purpose.
  • The coredrive-rx port of this rule (src/meshpacket.js) is not updated; separate repo.
  • Branch base is v3.17.0, so it can go upstream as is.

…TRACE, no failed-signature advert

directHeardNode now goes through packetpath.HeardKey, the rule the ingestor
already uses for client receptions. Three cases no longer credit a node:

- a 1-byte last hop, even with a single known candidate: a node CoreScope
  does not know can share the byte;
- TRACE, whose path bytes are per-hop SNR;
- a zero-hop ADVERT with signatureValid false. An advert without the
  field still credits the advertiser.

A 2-byte or longer hop still resolves through relayCandidates and still
needs exactly one candidate.

Benchmarks (go test -bench BuildDirectHeardIndex, old and new test
binaries run alternately, 3 rounds x 2, minimum ns/op, noisy machine):
- BuildDirectHeardIndex (3M observations, 2-byte last hop):
  old 67.9 ms, new 66.6 ms
- BuildDirectHeardIndex_MixedHops (new, 500k observations, 1/2/3-byte
  hops, 5% zero-hop adverts): old 42.9 ms, new 39.4 ms
A first version that looked the key up through relayCandidates lowered
the case twice and measured 30-40% slower; the lookup now uses the
already lower-cased key directly.

The Heard By titles on the node page say a 1-byte hop is never taken as
proof of who transmitted.
…s 1-byte hops

Review follow-up on the shared heard rule:

- directHeardNode checked signatureFailed for every empty-path
  observation before the ADVERT test. signatureFailed scans the decoded
  JSON and parses it when it holds a \u escape, so a zero-hop message
  could warm the decoded cache in the pass over all observations. The
  advert test now runs first. TestDirectHeardNode_ZeroHopNonAdvertLeaves
  DecodedCacheCold pins it.
- The empty-state title of "Heard By, direct" (nodes.js, full page and
  side pane) now says a 1-byte hop is left unattributed too, the most
  common reason a node shows no direct observer since this rule.
…shares

A repeater that retention moved to inactive_nodes is no resolver
candidate, but it may still relay on its prefix. uniqueHopPrefix already
refuses such a prefix as certain evidence (Kpa-clawbot#2260); directHeardNode now
does the same, so a 2-byte or longer hop shared with a retired repeater
credits nobody.

Benchmark BuildDirectHeardIndex (3M observations), old and new test
binaries alternated, 7 rounds x 2, minimum: old 64.1 ms, new 68.0 ms.
The benchmark's prefix map has no retired prefixes; with a populated
set the check is one map lookup per observation with a 2-byte or longer
last hop.
@efiten
efiten merged commit 9da1330 into master Nov 13, 2026
7 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant