@aztec/world-state 0.71.0 → 0.73.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -170,7 +170,7 @@ export class ServerWorldStateSynchronizer
170
170
  /** Returns the L2 block hash for a given number. Used by the L2BlockStream for detecting reorgs. */
171
171
  public async getL2BlockHash(number: number): Promise<string | undefined> {
172
172
  if (number === 0) {
173
- return Promise.resolve(this.merkleTreeCommitted.getInitialHeader().hash().toString());
173
+ return (await this.merkleTreeCommitted.getInitialHeader().hash()).toString();
174
174
  }
175
175
  if (this.latestBlockHashQuery?.hash === undefined || number !== this.latestBlockHashQuery.blockNumber) {
176
176
  this.latestBlockHashQuery = {
@@ -257,7 +257,7 @@ export class ServerWorldStateSynchronizer
257
257
  // Note that we cannot optimize this check by checking the root of the subtree after inserting the messages
258
258
  // to the real L1_TO_L2_MESSAGE_TREE (like we do in merkleTreeDb.handleL2BlockAndMessages(...)) because that
259
259
  // tree uses pedersen and we don't have access to the converted root.
260
- this.verifyMessagesHashToInHash(l1ToL2Messages, l2Block.header.contentCommitment.inHash);
260
+ await this.verifyMessagesHashToInHash(l1ToL2Messages, l2Block.header.contentCommitment.inHash);
261
261
 
262
262
  // If the above check succeeds, we can proceed to handle the block.
263
263
  const result = await this.merkleTreeDb.handleL2BlockAndMessages(l2Block, l1ToL2Messages);
@@ -311,14 +311,14 @@ export class ServerWorldStateSynchronizer
311
311
  * @param inHash - The inHash of the block.
312
312
  * @throws If the L1 to L2 messages do not hash to the block inHash.
313
313
  */
314
- protected verifyMessagesHashToInHash(l1ToL2Messages: Fr[], inHash: Buffer) {
315
- const treeCalculator = new MerkleTreeCalculator(
314
+ protected async verifyMessagesHashToInHash(l1ToL2Messages: Fr[], inHash: Buffer) {
315
+ const treeCalculator = await MerkleTreeCalculator.create(
316
316
  L1_TO_L2_MSG_SUBTREE_HEIGHT,
317
317
  Buffer.alloc(32),
318
- new SHA256Trunc().hash,
318
+ (lhs, rhs) => Promise.resolve(new SHA256Trunc().hash(lhs, rhs)),
319
319
  );
320
320
 
321
- const root = treeCalculator.computeTreeRoot(l1ToL2Messages.map(msg => msg.toBuffer()));
321
+ const root = await treeCalculator.computeTreeRoot(l1ToL2Messages.map(msg => msg.toBuffer()));
322
322
 
323
323
  if (!root.equals(inHash)) {
324
324
  throw new Error('Obtained L1 to L2 messages failed to be hashed to the block inHash');
package/src/test/utils.ts CHANGED
@@ -17,7 +17,7 @@ import { padArrayEnd } from '@aztec/foundation/collection';
17
17
  import { type NativeWorldStateService } from '../native/native_world_state.js';
18
18
 
19
19
  export async function mockBlock(blockNum: number, size: number, fork: MerkleTreeWriteOperations) {
20
- const l2Block = L2Block.random(blockNum, size);
20
+ const l2Block = await L2Block.random(blockNum, size);
21
21
  const l1ToL2Messages = Array(16).fill(0).map(Fr.random);
22
22
 
23
23
  // Sync the append only trees
@@ -531,7 +531,7 @@ export class MerkleTrees implements MerkleTreeAdminDatabase {
531
531
  throw new Error('State in header does not match current state');
532
532
  }
533
533
 
534
- const blockHash = header.hash();
534
+ const blockHash = await header.hash();
535
535
  await this.#appendLeaves(MerkleTreeId.ARCHIVE, [blockHash]);
536
536
  }
537
537
 
@@ -709,7 +709,7 @@ export class MerkleTrees implements MerkleTreeAdminDatabase {
709
709
  }
710
710
  await this.#snapshot(l2Block.number);
711
711
 
712
- this.metrics.recordDbSize(this.store.estimateSize().actualSize);
712
+ this.metrics.recordDbSize((await this.store.estimateSize()).actualSize);
713
713
  this.metrics.recordSyncDuration('commit', timer);
714
714
  return buildEmptyWorldStateStatusFull();
715
715
  }