stackrstaterollback-cli
v1.0.1
Published
A CLI Tool for Snapshotting and Rollbacking states of a Stackr Micro-rollup.
Downloads
6
Readme
Stackr State Rollback CLI
A CLI Tool for Snaphotting and Rollbacking states of a Stackr Micro-rollup.
Introduction
Micro-rollup are basically state machines that are responsible for preserving and updating state of a system. However, evaluating state transitions and ensuring a system operates as expected in specific states often lacks dedicated tools.
The Stackr State Rollback CLI addresses this gap by offering the ability to capture a snapshot of a state and subsequently roll back to it. It is a developer friendly CLI tool particularly made for enhancing the testing and debugging process a micro-rollup.
Features and Benefits
In case of server closure due to errors, developers can seamlessly resume testing by rolling back to a previously snapshotted state. This ensures continuity in the testing process
Provides a convenient mechanism for developers to document the state of their systems at specific points in time, aiding in comprehensive testing and debugging.
Enables quick and seamless transitions between different system states, facilitating efficient testing and debugging workflows.
Offers developers a detailed rollback history, enabling thorough analysis of state transitions, complete with action and block details.
Installation
Install stackrstaterollback-cli from CLI , in your project's root directory.
npm install stackrstaterollback-cli
Usage
After installing the package :
- run the command from your project's root directory
npx stackrstaterollback-cli
This will prompt for two questions:
a. Enter the micro-rollup is running on?
Type the port you are running the app on, you can find it in src/index.ts
b. Enter the current state variable:
Type the name of the variable you are using it to send the current state of the app. You can find it in src/index.ts
.
For example if your function looks like this:
app.get("/", (req: Request, res: Response) => {
res.send({
currentCount: state.get().state.getState(),
});
});
type currentCount
as your response fo the question.
Also make sure your endpoint is "/"
for both: getting current state and for performing action.
- Add the following code in
src/state.ts
:
a. import * as rollback from "../rollbackconfig.json";
b. Add a type in Action Input as "rollback"
for example :
interface CounterActionInput {
type: "increment" | "decrement" | "rollback";
}
c. Add a else if statement for input type of "rollback" in the STF function.
for example:
else if (inputs.type === "rollback") {
newState = Number(rollback.desiredState);
}
Note: Here, the StateVariable is a Number, the tool works on the presumption that
rollback.desiredState
is converted into the type of the StateVariable.
Now run the micro-rollup server from the command:
bun run src/index.ts
Run
Note: Make sure the server is running.
To run the Tool, run the command
npx stackrstaterollback-cli
you will get 5 options to select from :
- Snapshot current state
- List the snapshotted states
- Rollback to a snapshotted state
- List the Rollback History
- update port and current state variable
Example Responses
Example response of selecting List the snapshotted states
| State | Timestamp | Comment | |-------|-------------------------|-------------------------------------| | 0 | 2024-02-05 14:27:06 | Initial state of DEX1 | | 1 | 2024-02-05 14:28:03 | State of DEX where server stopped |
Example response of selecting List the Rollback History
| Params | Values | |--------------------|----------------------------------------------------------------------------------------------------| | previousState | 1 | | newState | 0 | | actionHash | 0x35904d82998dc2a6f3c97b9948682424aca03486076204e37265cadccc3a3c98 | | currentHeight | 91 | | operatorSignature | 0x23bf00e3c31155afda014f1d7379675f669c023cbc9f0d55a04b9b52ba16c1ef280239427ac06... | | blockHash | 0x6a3d41e492a6cf3f3f151919485b9d19bd43f0e50d2c95347c9aaa551e136e43 | | parentHash | 0xaf936fd63ee69f605c321befec7bea3d4b5043a7f43720dee775a78c29cb01a5 | | acknowledgementRoot| 0x33451cff0eb1bd1f89f6e27172d7093f55a1d421dbc09b729ca21244ec58fad1 |
Appendix
This is like the v0 of the package, it needs some enhancement to make it modular.
Authors
contact : [email protected]