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

Enhance WebSocket subscriptions with a "start height" option to replace sync (in most places) #2664

Open
corrideat opened this issue Feb 23, 2025 · 0 comments

Comments

@corrideat
Copy link
Member

Problem

Issues with sync

Calling sync on a contract is difficult to do correctly for a few reasons:

  1. It doesn't affect or take into account reference counts
  2. It's a one-off operation and it might fail

When the app starts, we also call sync to bootstrap it, but as documented in #2653, this leads to issues that interfere with saving data for notifications, implementing an offline PWA and implementing user-local snapshots, and potentially with other things.

Issues with WebSocket subscriptions

Subscribing to a channel gives the server information about the channel (contract) ID only. This means that a subscription will only receive events for future events, not for past events. In itself this isn't an issue, but it means that sometimes sync must be used (to receive past events).

Solution

We already, for the most part, receive events over the WebSocket, but need to use sync in certain situations, such as when our contract has fallen behind. In these situations, sync must be called, but, as mentioned, this can be challenging to do correctly and flexibly.

Instead, we can change the current way of subscribing to a contract so that we can also specify a height. If given, the height will act as a 'from' point, and the WS will behave similarly to using sync. This is advantageous because we already have logic in place to handle various error conditions and situations that arise in the WS, and this approach could allow the bootstrapping process to behave as if the app had never been closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant