-
Notifications
You must be signed in to change notification settings - Fork 148
State sync worker should be only responsible for initializing and syncing the state #6308
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
base: master
Are you sure you want to change the base?
State sync worker should be only responsible for initializing and syncing the state #6308
Conversation
Also rename node to worker, to avoid confusion. Ideally, the parent package (storage) would have runtime as a prefix to make it clearer this is a runtime worker.
Previously, genesis checkpoint was created right after the state may be initialized from the runtime descriptor. If this is not the case it is first fetched from the peers. Thus, we should force the genesis checkpoint only after checkpoint sync finishes.
This is desirable, so that worker that initilize a new checkpointer don't require accepting context, but instead the lifetime and initialization of checkpointer is handled by the worker's Serve method.
This also serves as step towards passing the context explicitly.
Previously if the context was not canceled the fetcher might be sending the diffs on a channel that cannot be emptied, since we are already out of the main for loop, resulting in wg.Wait to never complete.
In addition, statesync worker now implements the Service interface. The corresponding BackgroundService methods (already not used) have been removed. Similarly, the storage worker was internally refactored to Service interface to ease eventual removal of the BackgroundService. Note that semantic changed slightly: Previously storage worker would wait for all state sync workers to finish. Now it will terminate when the first one finishes. Technically, this was already the case if the storage worker panicked.
Additionally, observe that the parent (storage worker) is registered as background service, thus upon error inside state sync worker there is no need to manually request the node shutdown.
Synced is a synonim for last finalized round inside the state sync worker. This change should made the code more readable. Eventually, we should ideally use either sync or finalized. Finally, the metrics use synced as last fully applied, but this would be breaking to change.
✅ Deploy Preview for oasisprotocol-oasis-core canceled.
|
42886b7 to
a53d9d0
Compare
a53d9d0 to
55970b7
Compare
This worker will be responsible for orchestrating storage operations for the given runtime. This includes: 1. Registering availability 2. Creating checkpoints if configured 3. Pruning state 4. Syncing state (internally init, checkpoint sync and diff sync) Subsequent commit will do the outlined refactor above.
7cd6a91 to
867ed87
Compare
This method is needed so that other worker (checkpointer, availability nudger) will be able to react.
867ed87 to
fde0e1d
Compare
|
On one hand I like granular packages, so that I can reuse simple words On the other hand having workers nested under single package, I can make them private, and thus they are not seen in a documentation, which in this context is probably a good thing. update: Not true, as documentation should then be moved to the worker orchestrating... Finally, all this packages should be under If we decide to go with the latter approach, then The good point it is relatively easy to refactor between any of the approaches. Finally, this PR reinforced that State sync worker should be only responsible for initializing and syncing the state so factoring out checkpointer and availability nudger after #6306 is the right step to do. |
Generally this worker should be tested explicitly. For this checkpointer worker should probably take finalizedCh instead of the whole state sync worker, waiting for the storage initialization should be moved to the parent worker. Finally, instead of the full common worker we should accept interface to ease mocking. Technically this worker does two things, creates and notifies. I am open to moving checkpointer creation to the parent worker, and notify there in the separate goroutine. This way this worker is only responsible for creating checkpoints. I have kept it this way as this way all the code relevant for checkpoint creation or checkpointer functionality is encapsulated together.
Same issues as with checkpointer. Possibly we would want to accept WatchFinalizedRounds as part of an interface. Co-authored-by: Peter Nose <[email protected]>
6548fb6 to
8bc3c32
Compare
WIP
Follow-up of #6306, inspired by #6299 (comment), part of the #6307.
After that we will refactor state sync worker into smaller workers (#6307) = #6299.
Finally, we will have simple PR that optimizes things.
TODO:
End goal:
Runtime storage worker should orchestrate workers, implement hooks and be responsible for the status:
This way all workers that actually do work can be easily tested in isolation.