Skip to content

Commit

Permalink
Assert root valid only in dev env (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
grod220 authored Sep 28, 2023
1 parent 2c3cb09 commit 9f2fc3a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/block-processor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
base64ToUint8Array,
IndexedDbInterface,
isDevEnv,
NewNoteRecord,
uint8ArrayToBase64,
ViewServerInterface,
Expand Down Expand Up @@ -75,6 +76,8 @@ export class BlockProcessor {
await this.indexedDb.updateStateCommitmentTree(updates, height);
}

// Compares the locally stored, filtered SCT root with the actual one on chain. They should match.
// This is expensive to do every block, so should only be done in development.
private async assertRootValid(blockHeight: bigint): Promise<void> {
const sourceOfTruth = await this.querier.app.keyValue(`sct/anchor/${blockHeight}`);
const inMemoryRoot = this.viewServer.getNctRoot();
Expand Down Expand Up @@ -103,7 +106,9 @@ export class BlockProcessor {
await this.storeNewNotes(scanResult.new_notes);
await this.markNotesSpent(res.compactBlock.nullifiers, res.compactBlock.height);

await this.assertRootValid(res.compactBlock.height); // TODO: Put behind debug flag
if (isDevEnv()) {
await this.assertRootValid(res.compactBlock.height);
}

if (shouldStoreProgress(res.compactBlock, lastBlockHeight)) {
await this.saveSyncProgress(res.compactBlock.height);
Expand Down

0 comments on commit 9f2fc3a

Please sign in to comment.