Skip to content

Commit 7eb7817

Browse files
committed
trying to debug calldata hash mismatch
1 parent 7eda8a4 commit 7eb7817

File tree

1 file changed

+31
-2
lines changed
  • yarn-project/aztec-node/src/aztec-node

1 file changed

+31
-2
lines changed

yarn-project/aztec-node/src/aztec-node/server.ts

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Archiver } from '@aztec/archiver';
22
import {
3+
AppendOnlyTreeSnapshot,
34
CONTRACT_TREE_HEIGHT,
45
CircuitsWasm,
56
EthAddress,
@@ -88,7 +89,7 @@ export class AztecNodeService implements AztecNode {
8889
const p2pClient = await createP2PClient(config, new InMemoryTxPool(), archiver);
8990

9091
// now create the merkle trees and the world state syncher
91-
const merkleTreeDB = await MerkleTrees.new(levelup(createMemDown()), await CircuitsWasm.get());
92+
const merkleTreeDB = await AztecNodeService.createMerkleTreeDB();
9293
const worldStateConfig: WorldStateConfig = getWorldStateConfig();
9394
const worldStateSynchroniser = new ServerWorldStateSynchroniser(merkleTreeDB, archiver, worldStateConfig);
9495

@@ -119,6 +120,10 @@ export class AztecNodeService implements AztecNode {
119120
);
120121
}
121122

123+
static async createMerkleTreeDB() {
124+
return MerkleTrees.new(levelup(createMemDown()), await CircuitsWasm.get());
125+
}
126+
122127
/**
123128
* Method to determine if the node is ready to accept transactions.
124129
* @returns - Flag indicating the readiness for tx submission.
@@ -376,15 +381,38 @@ export class AztecNodeService implements AztecNode {
376381
);
377382
}
378383

384+
async printRoots() {
385+
const snapshots = await Promise.all(
386+
[
387+
MerkleTreeId.PRIVATE_DATA_TREE,
388+
MerkleTreeId.NULLIFIER_TREE,
389+
MerkleTreeId.CONTRACT_TREE,
390+
MerkleTreeId.PUBLIC_DATA_TREE,
391+
MerkleTreeId.L1_TO_L2_MESSAGES_TREE,
392+
MerkleTreeId.BLOCKS_TREE,
393+
].map(tree => this.getTreeSnapshot(tree)),
394+
);
395+
console.log(snapshots.map(snap => snap.root.toString()));
396+
}
397+
398+
async getTreeSnapshot(id: MerkleTreeId): Promise<AppendOnlyTreeSnapshot> {
399+
const db = await AztecNodeService.createMerkleTreeDB();
400+
const treeInfo = await db.getTreeInfo(id, true);
401+
return new AppendOnlyTreeSnapshot(Fr.fromBuffer(treeInfo.root), Number(treeInfo.size));
402+
}
403+
379404
/**
380405
* Simulates the public part of a transaction with the current state.
381406
* @param tx - The transaction to simulate.
382407
**/
383408
public async simulatePublicPart(tx: Tx) {
384409
this.log.info(`Simulating tx ${await tx.getTxHash()}`);
410+
await this.printRoots();
411+
// Instantiate merkle tree db so uncommited updates by this simulation are local to it.
412+
const merkleTreeDb = await AztecNodeService.createMerkleTreeDB();
385413

386414
const publicProcessorFactory = new PublicProcessorFactory(
387-
this.worldStateSynchroniser.getLatest(),
415+
merkleTreeDb.asLatest(),
388416
this.contractDataSource,
389417
this.l1ToL2MessageSource,
390418
);
@@ -398,6 +426,7 @@ export class AztecNodeService implements AztecNode {
398426
throw failedTxs[0].error;
399427
}
400428
this.log.info(`Simulated tx ${await tx.getTxHash()} succeeds`);
429+
await this.printRoots();
401430
}
402431

403432
/**

0 commit comments

Comments
 (0)