Conversation
|
I asked @fiatjaf about his thoughts on this, and he's not convinced it's a generally useful feature. I'm somewhat inclined to agree, since we don't want to slide down the slippery slope of re-implementing a crappy version of SQL! Overall, my first impression of the diff is that the code looks reasonable, so I'm not necessarily opposed to this. However, I am a bit nervous about making such a significant change to the core filtering logic. |
Don't let this bother you, enough good developers support the general idea, and it's been implemented. See here: nostr-protocol/nips#1365
I don't want that either. There is the belief that adding this is a slippery slope into ranges, math operands, IS NULL, IS NOT NULL, etc). Which is why the NIP was intentionally written in a limiting way. Right now if I want all memes that are of a black cat I have to stream the entire haystack from a relay to make the intersection and find the needle; which people are doing right now for real cases like NIP-17. Not a single stakeholder wins from this:
This is why I have left it as a draft; I am honestly not certain my implementation is valid or good. |
NIP-91 AND tag filters
Intent
&<tag>keys while preserving existing OR behavior for#<tag>.Changes
src/filters.h:NostrFilterwithtagsAndto represent ANDed tag values and track unique tag keys across#and&.&<tag>keys, hex-decode&e/&p, and normalise values viaFilterSetBytes, de-duplicating overlaps so values present in&are removed from the corresponding#.indexOnlyScansso presence of any AND tag forces full-event scans and keeps the 3-tag-key limit based on the union of#and&keys.src/DBQuery.h:tagsortagsAnd, choosing the most selective tag key.src/ActiveMonitors.h:tagsAndalongsidetagsin the tag monitor index so subscription monitors receive events that satisfy AND tag filters.test/dumbFilter.pl:#e/#p/#tlogic with generic OR (#<tag>) and AND (&<tag>) handling to match the NostrFilter implementation, including ignoring values that appear in both AND and OR for the same tag key.test/filterFuzzTest.pl:&t,&eand&pso scan and monitor fuzz tests cover NIP-91 AND-tag semantics.Testing
From the project root:
make.test/README.md(for example, import the wellordered 500k dataset).perl test/filterFuzzTest.pl scan-limitperl test/filterFuzzTest.pl scanperl test/filterFuzzTest.pl monitor