Skip to content

Commit

Permalink
feat(bootstrap): compare stored genesis block with config (#451)
Browse files Browse the repository at this point in the history
* Check stored commit

* Empty commit
  • Loading branch information
sebastijankuzner authored Feb 26, 2024
1 parent 5306586 commit f72fc66
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/bootstrap/source/bootstrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class Bootstrapper {
}

await this.#setGenesisCommit();
await this.#checkStoredGenesisCommit();
await this.#storeGenesisCommit();

await this.#restoreStateSnapshot();
Expand Down Expand Up @@ -99,6 +100,17 @@ export class Bootstrapper {

this.#store.setGenesisCommit(genesisBlock);
}
async #checkStoredGenesisCommit(): Promise<void> {
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<void> {
if (!(await this.databaseService.getLastBlock())) {
Expand Down

0 comments on commit f72fc66

Please sign in to comment.