Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: stale feed. Large contact list. #2194

Closed
2 tasks done
alltheseas opened this issue Apr 27, 2024 · 16 comments
Closed
2 tasks done

Bug: stale feed. Large contact list. #2194

alltheseas opened this issue Apr 27, 2024 · 16 comments
Assignees
Labels
bug Something is not working, or not working as intended Needs recreation Issues requires concrete steps for recreation perf relay technical

Comments

@alltheseas
Copy link
Collaborator

alltheseas commented Apr 27, 2024

Tracking Issus

These are steps needed to fix this issue

What happens
Feed seems stuck. Only hours long posts show.
Universe view is showing new posts. DMs work. Notifications work.

What I expect to happen
I dont expect to see a stale feed.

Link to noteID, npub

reported by elsat
npub1zafcms4xya5ap9zr7xxr0jlrtrattwlesytn2s42030lzu0dwlzqpd26k5

Screenshots/video recording
https://github.com/damus-io/damus/assets/64376233/95ae8255-4cfb-4be0-8cf0-b56124ebe0d4

a b
image image

** Versions **
Damus version: 1.9 (1) 90c68fe
Operating system version: iOS 17.4.1]
Device: e.g. iPhone 13 mini

Steps To Reproduce
Steps to reproduce the behavior:

Unclear.

@alltheseas alltheseas added bug Something is not working, or not working as intended Needs recreation Issues requires concrete steps for recreation labels Apr 27, 2024
@alltheseas
Copy link
Collaborator Author

For brief moments feed becomes real time - for instance after not having used the app for an hour.

After app close, and open feed is stale oncemore.

@alltheseas
Copy link
Collaborator Author

Stale feed problem persists

image

universe view is real time

image

@jb55
Copy link
Collaborator

jb55 commented May 2, 2024 via email

@alltheseas
Copy link
Collaborator Author

reduced relays - does not change stale feed

@alltheseas
Copy link
Collaborator Author

Turned on damus on old phone - same issue present

@alltheseas
Copy link
Collaborator Author

If yall log in with my npub are you able to recreate?

@jb55
Copy link
Collaborator

jb55 commented May 5, 2024 via email

@alltheseas alltheseas changed the title Bug: stale feed Bug: stale feed. Large contact list. May 5, 2024
@alltheseas alltheseas moved this to Backlog in Damus Roadmap 🛣️ May 5, 2024
@alltheseas
Copy link
Collaborator Author

Potential additional test case:

note1v2uzw8f488y29mhuafwjrkn45ss79sx2fydn3sedtxkca46rnjcq6u3g74

npub1vwymuey3u7mf860ndrkw3r7dz30s0srg6tqmhtjzg7umtm6rn5eq2qzugd

@alltheseas
Copy link
Collaborator Author

Screenshot 2024-05-06 at 11 49 05 AM

@alltheseas
Copy link
Collaborator Author

Potential test case:

note18mq7htp6dr8qthtdlppeyru9zesxpldxpdsr7evswaxe2wy3qhysmyqmsk

npub1nje4ghpkjsxe5thcd4gdt3agl2usxyxv3xxyx39ul3xgytl5009q87l02j

https://v.nostr.build/LeOaQ.mp4

@danieldaquino
Copy link
Contributor

Reproduced this issue on my end

Device: iPhone 15 simulator
iOS: 17.4
Damus: 1.9 (3) (0d9954290a674e1520164c08050bcfb9291fdd05)
Steps:

  1. Login with Elsat's npub
  2. Check the home feed. There should be fresh notes.

Results: No fresh notes, most recent post is from several hours ago (Feed is stale)


Already working on investigating the root cause.

@danieldaquino
Copy link
Contributor

After several minutes (between 5–10) fresh notes get loaded. I will inspect network traffic and logs

@danieldaquino
Copy link
Contributor

Your contact list is large and contains lots of hashtags and pubkeys. This may have something to do with it.
(...)
Relays may reject large subscriptions like this, leading to empty feeds.

These items seem to be part of the root cause. I am getting several log messages like these ones:

failed to decode event ["NOTICE","ERROR: bad req: total filter items too large"]
failed to parse '["NOTICE","ERROR: bad req: total filter items too large"]'

Relays are rejecting subscription queries for being too large.

I will look deeper to see if there other problems beyond relay rejection

@danieldaquino
Copy link
Contributor

I will look deeper to see if there other problems beyond relay rejection

As far as I can tell:

  1. The relay rejection is there and seems to be there and likely the biggest cause of the issue.
  2. The stalling due to the large size of the filter might be there as well, but we will be able to better measure it once we fix problem (1)
  3. Damus seems to be formatting the contact list filter well, it includes all 2076 people that Elsat is following
  4. I believe the actual sending of this contact list filter data is probably working as well, since the relay actively rejects it mentioning too many items.

I will focus on fixing (1) for now. If there are residual issues left after it, those will likely become evident.

@danieldaquino
Copy link
Contributor

@jb55 @alltheseas iteration 1 of the fix is ready. It's a 100% "clean refined solution", but it does seem to resolve the stale feed issue.

Here is a summary of the fix:

Chunk home filter subscriptions to avoid hitting max filter limits

When a user is following several accounts on their follow list, they may
get a stale feed caused by subscriptions being rejected by relays (due to max filter item limits).

This commit creates a temporary fix that gets around the issue by
creating several subscriptions for the home feed, chunking them into
filters with a max of 500 contacts.

Testing:

Procedure:
1. Login with Elsat's npub (Or some account that follows about 2K people, and connected to about 8 relays)
2. Check the home feed. There should be fresh notes.

Fix test details
Device: iPhone 15 simulator
iOS: 17.4
Damus: This new commit
Results:
- Fresh notes appear, most recent post is from a few seconds ago.
- However, profile images or names seem to take longer to load (I might need to chunk those metadata subscriptions as well

I will try to refine this fix on my second iteration:

  • I will try to do the same with metadata subscriptions to get profile pictures and names faster (I will do this to improve the experience)
  • I can also try to refine this to do something smarter: (I am not sure if this would be within the scope of this ticket or if we want to refine this later)
    • I can try to pull the contact lists from those friends, see which relays they are connected to, to try distributing the friends more intelligently across different relay subscriptions
    • I can try to randomize the distribution of friends across different relay subscriptions

@jb55 any thoughts or opinions on the first iteration of the fix, and the potential refinements?

Ideal solution

  • Look into a potential new NIP for relays. Relays already have your contact list, what if the query was simple as:

{ "authors": ["kind3:"] }

@jb55, I like this too, I think that solution would be nice. Perhaps one way we could generalize this solution further would be to add the ability to define Nostr filters as a Nostr Event, and then reference those filters via event IDs?

@danieldaquino danieldaquino moved this from Backlog to In Progress in Damus Roadmap 🛣️ May 11, 2024
@danieldaquino
Copy link
Contributor

Iteration 2 of the fix

  • Fixed stale profile metadata through a similar chunking mechanism
  • Made the chunking logic more reusable
  • Added automated tests around the chunking logic
  • Changed chunking of subscriptions into chunking of the filters themselves within the same subscription request
  • Did more thorough testing

Patch and all other details sent over email: https://groups.google.com/a/damus.io/g/patches/c/3zVnZPoOXhw

@jb55 please let me know if this needs further improvements or if this is good for pushing to master. Thanks!

@danieldaquino danieldaquino moved this from In Progress to In Review in Damus Roadmap 🛣️ May 11, 2024
@danieldaquino danieldaquino moved this from In Review to Done in Damus Roadmap 🛣️ May 13, 2024
@danieldaquino danieldaquino moved this from Done to Live in Damus Roadmap 🛣️ May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working, or not working as intended Needs recreation Issues requires concrete steps for recreation perf relay technical
Projects
Archived in project
Development

No branches or pull requests

3 participants