nostr-protocol / nips

Nostr Implementation Possibilities
2.4k stars 583 forks source link

Add `pow` field to filter JSON object #1514

Open yukibtc opened 2 months ago

yukibtc commented 2 months ago

Add pow field to filter JSON object to allow query of events with a certain difficulty.

Read here

smolgrrr commented 2 months ago

i suppose in the future it would be nice if some relays chose to index the difficulty in the nonce tag e.g. ["nonce", "12345", "21"], and then you use a filter like this: ["REQ", <subscription_id>, {"#nonce": 21, ...}] (?) however instead of returning matches, it returns events where the difficulty specified in the nonce tag is greater than or equal to the REQ difficulty. PoW can then be verified on the client side as it should be.

obviously tag filtering only looks for matches at the moment, and it's also the actual nonce that follows the tag name not the difficulty, so it would be different logic to the standard way tag filtering works which isn't nice and is needless complexity.

alexgleason commented 2 months ago

NIP-13 should have put the difficulty in the tag value and the nonce in the third position. Then it could at least be worked around by querying every integer below your target value, which honestly isn't even that bad. Introducing a new filter because of an issue with a tag seems wrong. I want to deprecate the "nonce" tag and replace it with a "pow" tag, but that would break too much stuff. This filter would make more sense as a NIP-50 search extension.

pablof7z commented 2 months ago

cNACK -- I would rather see prefix REQs come back rather than have an explicit filter for pow.

kehiy commented 1 month ago

cnack. im not sure where we need to query based on pow, but if it's really needed, adding a pow tag and querying based on it is a better way to add a new field to filter objects.

yukibtc commented 1 month ago

im not sure where we need to query based on pow

The use case is to reduce bandwidth and resources usage for apps that want to get only events with a certain POW (for spam reasons).

but if it's really needed, adding a pow tag and querying based on it is a better way to add a new field to filter objects.

Filter support only single letter tag: https://github.com/nostr-protocol/nips/blob/a736e629be5c4c9125d98bdb4965851d8110c483/01.md?plain=1#L127

Re-add prefix REQs would break things: https://github.com/nostr-protocol/nips/blob/a736e629be5c4c9125d98bdb4965851d8110c483/01.md?plain=1#L138

The same for adding support to non-single letter tags and changing NIP-13 tag (this will not allow to query old POW events).

I think that add the pow field to Filter is the solution that will not break things.