lbryio / lbry-desktop

A browser and wallet for LBRY, the decentralized, user-controlled content marketplace.
https://lbry.tech
MIT License
3.56k stars 414 forks source link

Subscriptions wiped. Investigation leads to JSON-RPC #4949

Closed CyberFoxHax closed 3 years ago

CyberFoxHax commented 3 years ago

No the problem is not the JSONRPC on it's own but rather the fact that all subscriptions transmitted on each request.

Say you open 10 channels in tabs and then ctrl+tab to quickly subscribe to all of them. After clicking follow 10 times on 10 different tabs, how many additional subscriptions will that result in? The answer is 1. The last page is the only subscription that stuck. My educated guess was that instead of "adding" it just "sets" the subscriptions.

So i did some tests in Postman.

request lifted from clicking "follow" a request POST is sent to https://api.lbry.tv/api/v1/proxy?m=preference_set

Original Payload:

{ "jsonrpc": "2.0", "method": "preference_set", "params": { "key": "shared", "value": "{\"type\":\"object\",\"version\":\"0.1\",\"value\":{\"tags\":[],\"subscriptions\":[\"lbry://@beneater#6c412e4afc8258ab65d83900b46289d68abc3872\",\"lbry://@GameDevMadeEasy#af48990b81e53fe37d41db49577a11256e4bedc0\",\"lbry://@gamefromscratch#199eba05b6ecccab919e26a0cb7dacd544f25700\",\"lbry://@InconvenientTruths#c1d55ae7b8a67e7a26d1511a462203173122e61d\",\"lbry://@johnstossel#70e56234217f30317c0e67fd0eede6e82b74aea0\",\"lbry://@JordanBPeterson#c5724e280283cd985186af9a62494aae377daabd\",\"lbry://@TheQuartering#113515e893b8186595595e594ecc410bae50c026\",\"lbry://@Thoughty2#b6e207c5f8c58e7c8362cd05a1501bf2f5b694f2\",\"lbry://@TimcastIRL#8954add966e59c9cba98a143a3387f788a36d7be\",\"lbry://@UpperEchelonGamers#3772507e49303f6db071f6361494deaafcbbf4cb\",\"lbry://@veritasium#fb364ef587872515f545a5b4b3182b58073f230f\",\"lbry://@ZoomingIn#69b3c0cae5d30be16423b931c4552ed050a244b0\"],\"blocked\":[],\"settings\":{\"automatic_dark_mode_enabled\":false,\"autoplay\":true,\"dark_mode_times\":{\"from\":{\"formattedTime\":\"21:00\",\"hour\":\"21\",\"min\":\"00\"},\"to\":{\"formattedTime\":\"8:00\",\"hour\":\"8\",\"min\":\"00\"}},\"floating_player\":true,\"hide_balance\":false,\"hide_reposts\":true,\"hide_splash_animation\":false,\"instant_purchase_enabled\":false,\"instant_purchase_max\":{\"amount\":0.1,\"currency\":\"LBC\"},\"show_mature\":false,\"theme\":\"dark\"},\"app_welcome_version\":0,\"sharing_3P\":false}}" }, "id": 1603763136383 } All my subscriptions remain intact. Nothing out of the ordinary.

Doctored Payload:

{ "jsonrpc": "2.0", "method": "preference_set", "params": { "key": "shared", "value": "{\"type\":\"object\",\"version\":\"0.1\",\"value\":{\"tags\":[],\"subscriptions\":[],\"blocked\":[],\"settings\":{\"automatic_dark_mode_enabled\":false,\"autoplay\":true,\"dark_mode_times\":{\"from\":{\"formattedTime\":\"21:00\",\"hour\":\"21\",\"min\":\"00\"},\"to\":{\"formattedTime\":\"8:00\",\"hour\":\"8\",\"min\":\"00\"}},\"floating_player\":true,\"hide_balance\":false,\"hide_reposts\":true,\"hide_splash_animation\":false,\"instant_purchase_enabled\":false,\"instant_purchase_max\":{\"amount\":0.1,\"currency\":\"LBC\"},\"show_mature\":false,\"theme\":\"dark\"},\"app_welcome_version\":0,\"sharing_3P\":false}}" }, "id": 1603763136383 } as expected, all my subscriptions disappeared.

Conclusion: You shouldn't send the entire state to the client and expect it to send it back flawlessly. You need to change to "adding" instead of "setting".

Note: This was tested on Odysee.

tzarebczan commented 3 years ago

Thanks for opening the issue and sorry to hear about the subs getting lost! Shoot us an email at hello@lbry.com with your email and we'll see if we can get them looked up on our end.

This is a known limitation at this time if you open 10 separate tabs and subscribe separately on each of them. We plan to make a few improvements with https://github.com/lbryio/lbry-desktop/issues/4830 to handle more cases and will make sure to note this one as well

CyberFoxHax commented 3 years ago

Done and done, thanks for the hard work!