From e394fb12ca320e0f82c1a36dc895a598139827b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Tkaczy=C5=84ski?= Date: Thu, 7 Nov 2024 21:17:32 +0100 Subject: [PATCH] fix: clear blocks on reset (#323) When we reset we will visit old blocks again so we need to clear previously stored ones to avoid conflicts. --- package.json | 2 +- src/checkpoint.ts | 1 + src/stores/checkpoints.ts | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4a498c1..4e69864 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@snapshot-labs/checkpoint", - "version": "0.1.0-beta.42", + "version": "0.1.0-beta.43", "license": "MIT", "bin": { "checkpoint": "dist/src/bin/index.js" diff --git a/src/checkpoint.ts b/src/checkpoint.ts index ccba51b..ae60c94 100644 --- a/src/checkpoint.ts +++ b/src/checkpoint.ts @@ -202,6 +202,7 @@ export default class Checkpoint { await this.store.createStore(); await this.store.setMetadata(MetadataId.LastIndexedBlock, 0); await this.store.setMetadata(MetadataId.SchemaVersion, SCHEMA_VERSION); + await this.store.removeBlocks(); await this.entityController.createEntityStores(this.knex); } diff --git a/src/stores/checkpoints.ts b/src/stores/checkpoints.ts index d7cf2a6..38b8af2 100644 --- a/src/stores/checkpoints.ts +++ b/src/stores/checkpoints.ts @@ -170,6 +170,10 @@ export class CheckpointsStore { await this.createStore(); } + public async removeBlocks(): Promise { + return this.knex(Table.Blocks).del(); + } + public async getBlockHash(blockNumber: number): Promise { const blocks = await this.knex .select(Fields.Blocks.Hash)