diff --git a/src/libs/helpers/state-manipulator/state-manager.ts b/src/libs/helpers/state-manipulator/state-manager.ts index 52e569e..8aefd5f 100644 --- a/src/libs/helpers/state-manipulator/state-manager.ts +++ b/src/libs/helpers/state-manipulator/state-manager.ts @@ -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(", ")}`); @@ -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(); @@ -164,6 +167,7 @@ export async function downloadExportedState( onStart && onStart( parseInt(headerStrings[headerStrings.findIndex((h) => h == "Content-Length") + 1]), + stateFileName ); return true; }, diff --git a/src/tools/run-moonbeam-fork.ts b/src/tools/run-moonbeam-fork.ts index 5d88861..38364c8 100644 --- a/src/tools/run-moonbeam-fork.ts +++ b/src/tools/run-moonbeam-fork.ts @@ -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", @@ -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,