feat: epoch fsm implementation#906
Draft
amimart wants to merge 15 commits into
Draft
Conversation
|
The latest Buf updates on your PR. Results from workflow Buf Linter / buf (pull_request).
|
Contributor
|
The epoch lifecycle as defined here is a linear pipeline, each state has exactly one forward transition, and |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose of Changes and their Description
This PR aims to set the base structure of the integration of epoch lifecycle with the
x/schedulermodule. It is not functional but will serve as a base to iterate upon in the integration.♻️ Epoch Lifecycle
The
Epochtype has been designed as a state machine whose lifecycle is explicitly defined as a set of states and transitions, the core logic related to each transitions is not in the scope of this PR.To ease its management a Finite State Machine abstraction is implemented under the
fsmpackage. The emissionsKeeperholds theFSMEngineinstance carrying the epoch's state machine definition, in order to perform a transition on an epoch theKeeper#applyEpochTransitionwill be used leveraging the dedicated fsm engine.Changes in the API are additive only as a temporary measure in order to make this PR more readable, next changes should be introduced in
v10.⏰ Epoch Scheduling
Wiring of the
x/schedulerhas been setup in thex/emissionsmodule, which now exposes task handlers related to epoch lifecycle transitions:emissions:open_epoch_worker_window: Open worker window;emissions:close_epoch_worker_window: Close worker window and compute network inference;emissions:open_epoch_reputer_window: Open reputer window;emissions:close_epoch_reputer_window: Close reputer window;emissions:complete_epoch: Compute loss, distribute rewards, and prune epoch data;Each handler has the previous handler as a dependency to ensure execution order in case of execution in the same block.
The
Keeper#StartEpochpublic func allows the creation and scheduling of a new epoch for a topic.💾 Epoch Storage
A new
Nonceformat has been introduced has auint64type alias whose first byte contains the nonce version, making it retro-compatible with block height based nonces. This new type is currently namedNonceV2to avoid the large API refactor but will replace the current type.An
Epochis identified in aTopicby itsNonce, and uniquely identified by the[TopicId; Nonce]pair. It is stored as anIndexedMap, whose underlying map store epochs by their unique keys:[TopicId; Nonce] => Epoch. It exposes the following indexes:ByState: Allows to filter epochs by a specific state (e.g.WORKER_SUBMISSION,REPUTER_SUBMISSION, etc...);ByStateAndTopic: Allows to filter epochs by both state and topic id;This way we can easily query global or per topic opened worker/reputer submission windows, and expose these capabilities through a single rpc query, maximising the system's observability.
Are these changes tested and documented?
Unreleasedsection ofCHANGELOG.md?