Skip to content

Commit

Permalink
feat(cosmic-swingset): wire snapshot restoring in chain-main
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Mar 31, 2023
1 parent 4b8e650 commit e8a87ab
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/cosmic-swingset/src/chain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { resolve as pathResolve } from 'path';
import v8 from 'node:v8';
import process from 'node:process';
import fs from 'node:fs';
import fsPromises from 'node:fs/promises';
import { performance } from 'perf_hooks';
import { resolve as importMetaResolve } from 'import-meta-resolve';
import tmpfs from 'tmp';
Expand Down Expand Up @@ -37,6 +38,7 @@ import { launch } from './launch-chain.js';
import { getTelemetryProviders } from './kernel-stats.js';
import { makeProcessValue } from './helpers/process-value.js';
import { spawnSwingStoreExport } from './export-kernel-db.js';
import { performStateSyncImport } from './import-kernel-db.js';

// eslint-disable-next-line no-unused-vars
let whenHellFreezesOver = null;
Expand Down Expand Up @@ -462,8 +464,18 @@ export default async function main(progname, args, { env, homedir, agcc }) {
return blockingSend;
}

async function handleCosmosSnapshot(blockHeight, request, _requestArgs) {
async function handleCosmosSnapshot(blockHeight, request, requestArgs) {
switch (request) {
case 'restore': {
const exportDir = requestArgs[0];
if (typeof exportDir !== 'string') {
throw Fail`Invalid exportDir argument ${q(exportDir)}`;
}
return performStateSyncImport(
{ exportDir, stateDir: stateDBDir, blockHeight },
{ fs: { ...fs, ...fsPromises }, pathResolve },
);
}
case 'initiate': {
!stateSyncExport ||
Fail`Snapshot already in progress for ${stateSyncExport.blockHeight}`;
Expand Down

0 comments on commit e8a87ab

Please sign in to comment.