-
Notifications
You must be signed in to change notification settings - Fork 1
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
Expose a Local Tableland method that restarts the validator #51
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carsonfarmer This is the change I came up with for the fix Dimo is asking for in Discord.
If this looks good/makes sense to you, I'll publish a pre version today so they can try it out.
@@ -165,6 +165,49 @@ class LocalTableland { | |||
); | |||
} | |||
|
|||
await this.#_startValidator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the validator initialization logic into a function that can be called multiple times.
if (this.silent as boolean) return; | ||
|
||
console.log("\n\n****** Tableland is running! ******"); | ||
console.log(" _________"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff here looks a bit weird because I moved the validator init code without changing it. Because of that this is added and removed.
@@ -273,6 +277,11 @@ class LocalTableland { | |||
return await prom; | |||
} | |||
|
|||
async restartValidator(): Promise<void> { | |||
await this.shutdownValidator(); | |||
await this.#_startValidator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already had a shutdownValidator
method, just needed to add the _startValidator
c253979
to
786e4c9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
Overview
Hardhat has an RPC API that contains methods to take a snapshot of the chain state, and then revert to a given state.
Docs are here: https://hardhat.org/hardhat-network/docs/reference#evm_snapshot
This is useful for testing contracts, but the local tableland network becomes out of sync when this happens because the tables materialized by the Validator are no longer valid.
This PR enables local tableland users who want to snapshot and revert to do so in a way that keeps the Validator up to date with the reverted chain state.
Details
The mechanism used here to re-sync the validator with the chain is to simple shutdown and restart the validator. The methods needed to accomplish that haven't been public, so this PR simply does a small refactor and exposes a new method called
restartValidator
.