mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-02-10 03:46:36 +00:00
* Remove support for pushing state to IPFS * Move job handlers for state creation to util * Rename state creation related methods and objects * Update mock indexer used in graph-node testing * Fetch and merge diffs in batches while creating a state checkpoint * Fix timing logs while for state checkpoint creation * Refactor method to get state query result to util * Accept contracts for state verification in compare CLI config * Make method to update state status map synchronous
63 lines
1.5 KiB
Handlebars
63 lines
1.5 KiB
Handlebars
//
|
|
// Copyright 2022 Vulcanize, Inc.
|
|
//
|
|
|
|
import debug from 'debug';
|
|
|
|
import { getConfig } from '@cerc-io/util';
|
|
|
|
import { Database } from '../../database';
|
|
|
|
const log = debug('vulcanize:reset-state');
|
|
|
|
export const command = 'state';
|
|
|
|
export const desc = 'Reset State to a given block number';
|
|
|
|
export const builder = {
|
|
blockNumber: {
|
|
type: 'number'
|
|
}
|
|
};
|
|
|
|
export const handler = async (argv: any): Promise<void> => {
|
|
const { blockNumber } = argv;
|
|
const config = await getConfig(argv.configFile);
|
|
|
|
// Initialize database
|
|
const db = new Database(config.database);
|
|
await db.init();
|
|
|
|
// Create a DB transaction
|
|
const dbTx = await db.createTransactionRunner();
|
|
|
|
console.time('time:reset-state');
|
|
try {
|
|
// Delete all State entries in the given range
|
|
await db.removeStatesAfterBlock(dbTx, blockNumber);
|
|
|
|
// Reset the stateSyncStatus.
|
|
const stateSyncStatus = await db.getStateSyncStatus();
|
|
|
|
if (stateSyncStatus) {
|
|
if (stateSyncStatus.latestIndexedBlockNumber > blockNumber) {
|
|
await db.updateStateSyncStatusIndexedBlock(dbTx, blockNumber, true);
|
|
}
|
|
|
|
if (stateSyncStatus.latestCheckpointBlockNumber > blockNumber) {
|
|
await db.updateStateSyncStatusCheckpointBlock(dbTx, blockNumber, true);
|
|
}
|
|
}
|
|
|
|
dbTx.commitTransaction();
|
|
} catch (error) {
|
|
await dbTx.rollbackTransaction();
|
|
throw error;
|
|
} finally {
|
|
await dbTx.release();
|
|
}
|
|
console.timeEnd('time:reset-state');
|
|
|
|
log(`Reset State successfully to block ${blockNumber}`);
|
|
};
|