-
Notifications
You must be signed in to change notification settings - Fork 51
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
Refactoring light-base/src/json_rpc_service.rs
#291
Comments
cc #284 which was the first step |
I'm leaning towards the second solution, as the lack of mutexes seems more clean to me. |
This was referenced Mar 15, 2023
The last step would be to refactor |
This was referenced Mar 21, 2023
Done after #793 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code in
json_rpc_service.rs
is way too cumbersome and complicated, and more functionalities should be added to therequest_subscriptions
state machine in order to make it more simple.Unfortunately, the logic of this code is inherently complicated. When a
chainHead_unstable_body
for example is called, we need to look up in the corresponding follow subscription to check whether the block is still pinned.I can see two ways of making it work:
request_subscriptions
could store, for each subscription, a task and a user data. When the user wants to unsubscribe, we ask therequest_subscriptions
to abort the task (after examining the user data, to be sure that the type of the subscription matches). The user data is behind aMutex
and would store, in the case of a follow subscription, theFollowSubscription
struct that currently exists. This solution is pretty similar to what already is done in the code.request_subscriptions
could store, for each subscription, a task and a channel that can send messages to that task. The channel would be provided by therequest_subscriptions
rather than done manually in order to add some safety around lockingMutex
es. When the user wants to unsubscribe, we send a message to the subscription in question which then politely shuts down. When the user calls for examplechainHead_unstable_body
, we send a message to the subscription in question as well, which then starts the body request subscriptions. The existingFollowSubscription
would be a local variable in the task of the follow subscription.The latter is more safe in terms of
Mutex
locking, as it would prevent all accidental deadlocks, but maybe also a bit more complicated.The text was updated successfully, but these errors were encountered: