mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-08 16:54:08 +00:00
Update ipld-status table in reset and fill state CLI (#193)
This commit is contained in:
@@ -120,10 +120,10 @@ export class Database implements IPLDDatabaseInterface {
|
||||
await this._baseDatabase.removeIPLDBlocks(repo, blockNumber, kind);
|
||||
}
|
||||
|
||||
async removeIPLDBlocksInRange (dbTx: QueryRunner, startBlock: number, endBlock: number): Promise<void> {
|
||||
async removeIPLDBlocksAfterBlock (dbTx: QueryRunner, blockNumber: number): Promise<void> {
|
||||
const repo = dbTx.manager.getRepository(IPLDBlock);
|
||||
|
||||
await this._baseDatabase.removeIPLDBlocksInRange(repo, startBlock, endBlock);
|
||||
await this._baseDatabase.removeIPLDBlocksAfterBlock(repo, blockNumber);
|
||||
}
|
||||
|
||||
async getIPLDStatus (): Promise<IpldStatus | undefined> {
|
||||
|
||||
@@ -15,21 +15,13 @@ export const command = 'ipld-state';
|
||||
export const desc = 'Reset IPLD state in the given range';
|
||||
|
||||
export const builder = {
|
||||
startBlock: {
|
||||
type: 'number'
|
||||
},
|
||||
endBlock: {
|
||||
blockNumber: {
|
||||
type: 'number'
|
||||
}
|
||||
};
|
||||
|
||||
export const handler = async (argv: any): Promise<void> => {
|
||||
const { startBlock, endBlock } = argv;
|
||||
if (startBlock > endBlock) {
|
||||
log('endBlock should be greater than or equal to startBlock');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const { blockNumber } = argv;
|
||||
const config = await getConfig(argv.configFile);
|
||||
|
||||
// Initialize database
|
||||
@@ -39,9 +31,27 @@ export const handler = async (argv: any): Promise<void> => {
|
||||
// Create a DB transaction
|
||||
const dbTx = await db.createTransactionRunner();
|
||||
|
||||
console.time('time:reset-ipld-state');
|
||||
try {
|
||||
// Delete all IPLDBlock entries in the given range
|
||||
await db.removeIPLDBlocksInRange(dbTx, startBlock, endBlock);
|
||||
await db.removeIPLDBlocksAfterBlock(dbTx, blockNumber);
|
||||
|
||||
// Reset the IPLD status.
|
||||
const ipldStatus = await db.getIPLDStatus();
|
||||
|
||||
if (ipldStatus) {
|
||||
if (ipldStatus.latestHooksBlockNumber > blockNumber) {
|
||||
await db.updateIPLDStatusHooksBlock(dbTx, blockNumber, true);
|
||||
}
|
||||
|
||||
if (ipldStatus.latestCheckpointBlockNumber > blockNumber) {
|
||||
await db.updateIPLDStatusCheckpointBlock(dbTx, blockNumber, true);
|
||||
}
|
||||
|
||||
if (ipldStatus.latestIPFSBlockNumber > blockNumber) {
|
||||
await db.updateIPLDStatusIPFSBlock(dbTx, blockNumber, true);
|
||||
}
|
||||
}
|
||||
|
||||
dbTx.commitTransaction();
|
||||
} catch (error) {
|
||||
@@ -50,6 +60,7 @@ export const handler = async (argv: any): Promise<void> => {
|
||||
} finally {
|
||||
await dbTx.release();
|
||||
}
|
||||
console.timeEnd('time:reset-ipld-state');
|
||||
|
||||
log(`Reset ipld-state successfully for range [${startBlock}, ${endBlock}]`);
|
||||
log(`Reset ipld-state successfully to block ${blockNumber}`);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user