Skip to content
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

Merged
merged 1 commit into from
Oct 24, 2023

Conversation

joewagner
Copy link
Contributor

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.

Copy link
Contributor Author

@joewagner joewagner left a 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();
Copy link
Contributor Author

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(" _________");
Copy link
Contributor Author

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();
Copy link
Contributor Author

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

@joewagner joewagner marked this pull request as ready for review October 12, 2023 18:40
@joewagner joewagner force-pushed the joe/enable-chainsnapshot branch from c253979 to 786e4c9 Compare October 24, 2023 08:18
Copy link
Contributor

@avichalp avichalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Copy link
Member

@sanderpick sanderpick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@joewagner joewagner merged commit 03f4002 into main Oct 24, 2023
4 checks passed
@joewagner joewagner deleted the joe/enable-chainsnapshot branch October 24, 2023 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants