Comments (7)
This should work for id 00
but not for 0
. The problem with 0
is that internally strfry (and I believe nostr-rs-relay too) do not store in the hexadecimal encoding, but instead of decoded bytes (which take up half the space).
Converting hex to bytes is ambiguous when the quantity of hex characters are odd. a
could decode to either 0a
(what most hex decoders would do) or a0
(which is likely what is intended here). However, note that the "length" of the prefix would need to be half a byte here, which strfry doesn't support. IMO supporting odd-length hexadecimal filters is not worth the trouble.
from strfry.
You can very granularly filter by PoW by enumerating the ID prefixes.
See https://github.com/rust-nostr/nostr/blob/master/crates/nostr/src/nips/nip13.rs#L386-L432
For example:
// 5 bits of PoW => 8 prefixes
assert_eq!(get_prefixes_for_difficulty(5), vec!["00", "01", "02", "03", "04", "05", "06", "07");
// 6 bits of PoW => 4 prefixes
assert_eq!(get_prefixes_for_difficulty(6), vec!["00", "01", "02", "03"]);
// 7 bits of PoW => 2 prefixes
assert_eq!(get_prefixes_for_difficulty(7), vec!["00", "01"]);
// 8 bits of PoW => 1 prefix
assert_eq!(get_prefixes_for_difficulty(8), vec!["00"]);
This can be generalized:
4k
bits of PoW => 1 prefix4k + 1
bits of PoW => 8 prefixes4k + 2
bits => 4 prefixes4k + 3
bits => 2 prefixes
So enumerating 1-8 prefixes can be enough to filter by any PoW.
from strfry.
created this issue also for rust relay scsibug/nostr-rs-relay#104
from strfry.
a
could decode to either0a
(what most hex decoders would do) ora0
(which is likely what is intended here)
IMO
filter: { ids: ["a"] }
is intended to mean
filter: { ids: ["a0", "a1", "a2", "a3", ..., "af"] }
Maybe exploding the odd-length prefixes this way is a good heuristic to avoid the ambiguity?
from strfry.
Yep, that could work. I'm not sure if it's worth doing the work for this though -- If you're querying IDs then why not just send an even number of hex digits?
from strfry.
POW can be much more granular than full byte. 0x0000...
is 256 times harder to achieve than 0x00...
. If you allow half bytes, you still go in increments of 16 from one difficulty to the next.
I think for POW, the prefix is not granular enough. You would need for example a range: pubkey < 0x000454ffffff...
.
from strfry.
00
is completely fine for me as my motivation was to reduce bandwidth when the user only wants to see notes with POW.
In the meantime I found out that rust relay supports it and that there was an issue in which now is fixed, see offbyn/nostr-tools@98ecacd
Reading the rest of the discussion about 'odd-length prefixes' I guess this should probably go into a nip (ideally also prefixes itself would be moved to its own nip so clients could ask relays if they support prefixes).
scsibug/nostr-rs-relay#104 (comment)
Closing this.
from strfry.
Related Issues (20)
- Compilation fails on alpine 3.19.1
- Add support for icon URL in NIP-11 document
- access reports HOT 1
- What happened to the Docker images? HOT 1
- SIGTERM
- Search by tag and tag substring returns no results
- A question regarding the sync command HOT 2
- Up-to-date docker image in dockerhub HOT 1
- Cron deletes events that are not expired HOT 1
- Importing events from another relay using .jsonl import HOT 4
- Feature: retention period HOT 5
- Feature request: NIP-45 Event Count HOT 6
- Build Error HOT 6
- Favicon for relay HOT 1
- Cryptic error messages returned in OK messages HOT 1
- logging controls not documented/working
- docker-compose not working HOT 4
- REQ limit is too low HOT 1
- strify crashes on start HOT 2
- OSX build error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strfry.