Add CLI tool to fix persistent frontier's root discrepancy #18116
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.
Problem
Frontier persisting is fundamentally broken.
Persistent frontier is managed by an on-disk database coupled with a file containing the latest root hash. While the root file is updated immediately after the in-memory frontier switched from one root to another, storing of the transitions on disk (in the transitions database) comes with up to 9 blocks delay.
This setup allows for better efficiency, but when the Mina node starts, it detects that the root as present in the file is not equal to the root from the database, and treats the whole on-disk persistence as corrupt, removing frontier entirely. This discrepancy between root file and transition database can occur easily, e.g. on the Mina node exiting abruptly (unsure whether it's the case when node is finished with a stop command sent via client).
Solution
Tool that is introduced in this PR allows to fix the state of the persistent frontier's database by removing some transitions fromt he database until the root read from the file becomes a root of the database as well. Removing is performed by executing part of the regular root-moving routine.
In future we must consider embedding this recovery mechanism into Mina node itself, but as the first step it's good to be able to deliver it wrapped in a CLI tool.
Commit structure
PR contains a few straightforward commits exposing some functions across the codebase:
transitionfun from root dataWith the final commit introducing the new tool:
Testing
Explain how you tested your changes:
Checklist