-
Notifications
You must be signed in to change notification settings - Fork 179
docs: Add otter state generation doc #21798
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
70 changes: 70 additions & 0 deletions
70
platform-sdk/consensus-otter-tests/docs/generating-saved-states.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # Generating Saved States for Otter Tests | ||
|
|
||
| ## Overview | ||
|
|
||
| Saved states allow tests to bootstrap from a previously generated network state rather than starting from genesis. This is useful for migration testing and scenarios where you want to start from a specific network configuration. | ||
|
|
||
| ## Generating a State | ||
|
|
||
| Use the `GenerateStateTool` command-line tool to create a new saved state: | ||
|
|
||
| ```bash | ||
| ./gradlew :consensus-otter-tests:run --args="org.hiero.otter.fixtures.tools.GenerateStateTool" | ||
| ``` | ||
|
|
||
| This tool: | ||
| 1. Creates a 4-node network using a deterministic seed | ||
| 2. Runs the network for 10 seconds | ||
| 3. Freezes the network to create a consistent snapshot | ||
| 4. Cleans up unnecessary files (keeping only the latest round and PCES directory) | ||
| 5. Moves the state to `platform-sdk/consensus-otter-tests/saved-states/previous-version-state` | ||
|
|
||
| The generated state is a **freeze state**, making it safe for: | ||
| - Migration tests that load a state from a previous software version | ||
| - Tests that make roster changes (node additions/removals) | ||
| - Any test requiring a known starting state with existing rounds | ||
|
|
||
| ## Using a Saved State in Tests | ||
|
|
||
| Reference the saved state directory in your test: | ||
|
|
||
| ```java | ||
| @OtterTest | ||
| @OtterSpecs(randomNodeIds = false) | ||
| void myTest(@NonNull final TestEnvironment env) { | ||
| final Network network = env.network(); | ||
|
|
||
| network.addNodes(numberOfNodes); | ||
| network.savedStateDirectory(Path.of("previous-version-state")); | ||
| network.version(targetVersion); | ||
poulok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| network.start(); | ||
|
|
||
| // ... test assertions | ||
| } | ||
| ``` | ||
|
|
||
| The network automatically handles: | ||
| - Loading the saved state from `saved-states/previous-version-state` | ||
| - Synchronizing FakeTime to the state's WALL_CLOCK_TIME + 1 hour if running in the Turtle environment to ensure time does not go backwards | ||
| - Managing roster changes if the test uses different node counts | ||
|
|
||
| ## Git Management | ||
|
|
||
| The `.gitignore` at the repository root ignores all `.swh` files: | ||
|
|
||
| ``` | ||
| *.swh | ||
| ``` | ||
|
|
||
| After generating a new state, **manually `git add` the `.swh` file** to include it in version control: | ||
|
|
||
| ```bash | ||
| cd platform-sdk/consensus-otter-tests/saved-states/previous-version-state | ||
| git add -f OtterApp/0/hiero/*/SignedState.swh | ||
| ``` | ||
|
|
||
| The `-f` flag is required because the file matches the gitignore pattern. | ||
|
|
||
| ## Migration Testing | ||
|
|
||
| > TODO: Document migration testing workflow when we have tests that load states generated from previous software versions. Include version handling and any specific considerations for testing state format compatibility. | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.