diff --git a/packages/bootstrap/source/bootstrapper.ts b/packages/bootstrap/source/bootstrapper.ts index b4333a890..c5c56c836 100644 --- a/packages/bootstrap/source/bootstrapper.ts +++ b/packages/bootstrap/source/bootstrapper.ts @@ -67,6 +67,7 @@ export class Bootstrapper { } await this.#setGenesisCommit(); + await this.#checkStoredGenesisCommit(); await this.#storeGenesisCommit(); await this.#restoreStateSnapshot(); @@ -99,6 +100,17 @@ export class Bootstrapper { this.#store.setGenesisCommit(genesisBlock); } + async #checkStoredGenesisCommit(): Promise { + const genesisBlock = await this.databaseService.getBlock(0); + + if (!genesisBlock) { + return; + } + + if (this.#store.getGenesisCommit().block.data.id !== genesisBlock.data.id) { + throw new Error("Block from crypto.json doesn't match stored genesis block"); + } + } async #storeGenesisCommit(): Promise { if (!(await this.databaseService.getLastBlock())) {