1
1
import { Archiver } from '@aztec/archiver' ;
2
2
import {
3
+ AppendOnlyTreeSnapshot ,
3
4
CONTRACT_TREE_HEIGHT ,
4
5
CircuitsWasm ,
5
6
EthAddress ,
@@ -88,7 +89,7 @@ export class AztecNodeService implements AztecNode {
88
89
const p2pClient = await createP2PClient ( config , new InMemoryTxPool ( ) , archiver ) ;
89
90
90
91
// 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 ( ) ;
92
93
const worldStateConfig : WorldStateConfig = getWorldStateConfig ( ) ;
93
94
const worldStateSynchroniser = new ServerWorldStateSynchroniser ( merkleTreeDB , archiver , worldStateConfig ) ;
94
95
@@ -119,6 +120,10 @@ export class AztecNodeService implements AztecNode {
119
120
) ;
120
121
}
121
122
123
+ static async createMerkleTreeDB ( ) {
124
+ return MerkleTrees . new ( levelup ( createMemDown ( ) ) , await CircuitsWasm . get ( ) ) ;
125
+ }
126
+
122
127
/**
123
128
* Method to determine if the node is ready to accept transactions.
124
129
* @returns - Flag indicating the readiness for tx submission.
@@ -376,15 +381,38 @@ export class AztecNodeService implements AztecNode {
376
381
) ;
377
382
}
378
383
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
+
379
404
/**
380
405
* Simulates the public part of a transaction with the current state.
381
406
* @param tx - The transaction to simulate.
382
407
**/
383
408
public async simulatePublicPart ( tx : Tx ) {
384
409
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 ( ) ;
385
413
386
414
const publicProcessorFactory = new PublicProcessorFactory (
387
- this . worldStateSynchroniser . getLatest ( ) ,
415
+ merkleTreeDb . asLatest ( ) ,
388
416
this . contractDataSource ,
389
417
this . l1ToL2MessageSource ,
390
418
) ;
@@ -398,6 +426,7 @@ export class AztecNodeService implements AztecNode {
398
426
throw failedTxs [ 0 ] . error ;
399
427
}
400
428
this . log . info ( `Simulated tx ${ await tx . getTxHash ( ) } succeeds` ) ;
429
+ await this . printRoots ( ) ;
401
430
}
402
431
403
432
/**
0 commit comments