Add HyperLogLog support for COUNT (NIP-45)#181
Open
alltheseas wants to merge 3 commits intohoytech:masterfrom
Open
Add HyperLogLog support for COUNT (NIP-45)#181alltheseas wants to merge 3 commits intohoytech:masterfrom
alltheseas wants to merge 3 commits intohoytech:masterfrom
Conversation
Add HLL sketch (256 registers, precision 8) to COUNT responses for single-tag filters (#e, #p, etc.), enabling clients to merge counts from multiple relays without double-counting pubkeys. Algorithm is a mechanical port of go-nostr nip45/hyperloglog: extract 8 bytes from pubkey at a filter-derived offset, use first byte as register index, count leading zeros in remaining 56 bits. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Python oracle is an exact port of go-nostr nip45/hyperloglog used to generate test vectors. Standalone C++ test validates the HLL algorithm against those vectors (buildable without strfry deps). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Five test cases against a live strfry relay: #e tag HLL, #p tag HLL, non-eligible filter omits HLL, zero-result all-zeros HLL, and multi-tag filter omits HLL. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #178
Summary
#e,#p, etc.), enabling clients to merge counts from multiple relays without double-counting pubkeys"hll"field (512-char hex string) when the filter has exactly one tag with one valueFiles
src/HyperLogLog.haddPubkeyBytes,encodeHex,clz56)src/DBQuery.hhllOffset/hllfields,computeHllOffset(), update registers during scansrc/QueryScheduler.hhllHexstring throughonCompletecallbacksrc/apps/relay/RelayReqWorker.cpp"hll"field in COUNT JSON responsesrc/apps/relay/RelayNegentropy.cpponCompletesignature (ignore new param)test/hll_reference.pytest/hll_unit_test.cpptest/nip45_hll_test.pytest/cfgs/nip45HllTest.confReferences
Test plan
g++ -std=c++20 -I src test/hll_unit_test.cpp)makebuild on Linux🤖 Generated with Claude Code