Skip to content

Commit

Permalink
adds support for '--state-date'
Browse files Browse the repository at this point in the history
  • Loading branch information
crystalin committed Jun 27, 2024
1 parent e04d2b8 commit 08f69e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/libs/helpers/state-manipulator/state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,20 @@ export interface DownloadOptions {

// Prefers clean state (without heavy contract, 80% smaller on moonbeam)
useCleanState?: boolean;

// Will download the state of the given date or the latest if not provided
stateDate?: string;
}

// Downloads the exported state from s3. Only if the xxx-chain-info.json file hasn't changed
// 2 files are created:
export async function downloadExportedState(
options: DownloadOptions,
onStart?: (size: number) => void,
onStart?: (size: number, filename: string) => void,
onProgress?: (bytes: number) => void,
onComplete?: () => void,
): Promise<{ stateFile: string; stateInfo: StateInfo }> {
const { network, outPath, checkLatest, useCleanState } = options;
const { network, outPath, checkLatest, useCleanState, stateDate } = options;

if (!STORAGE_NAMES[network]) {
console.warn(`Invalid network ${network}, expecting ${Object.keys(STORAGE_NAMES).join(", ")}`);
Expand Down Expand Up @@ -113,7 +116,7 @@ export async function downloadExportedState(
const client = new Client(`http://states.kaki.dev`);
const downloadedStateInfo: StateInfo = await (
await client.request({
path: `/${network}-state.info.json`,
path: `/${network}-state${stateDate ? `-${stateDate}` : ""}.info.json`,
method: "GET",
})
).body.json();
Expand Down Expand Up @@ -164,6 +167,7 @@ export async function downloadExportedState(
onStart &&
onStart(
parseInt(headerStrings[headerStrings.findIndex((h) => h == "Content-Length") + 1]),
stateFileName
);
return true;
},
Expand Down
9 changes: 7 additions & 2 deletions src/tools/run-moonbeam-fork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const argv = yargs(process.argv.slice(2))
description: "Downloads the smaller state version (without super heavy contracts)",
default: true,
},
"state-date": {
type: "string",
description: "Specify the date of the state to download (default to latest available) ",
},
sealing: {
type: "string",
alias: "s",
Expand Down Expand Up @@ -297,9 +301,10 @@ const main = async () => {
outPath: argv["base-path"],
checkLatest: argv.latest,
useCleanState: argv["smaller-state"],
stateDate: argv["state-date"],
},
(length) => {
process.stdout.write(`${chalk.yellow(`Downloading`)}\n`);
(length, filename) => {
process.stdout.write(`${chalk.yellow(`Downloading ${filename}...`)}\n`);
progressBar = new SingleBar({
etaAsynchronousUpdate: true,
fps: 5,
Expand Down

0 comments on commit 08f69e9

Please sign in to comment.