@aztec/world-state 3.0.0-canary.a9708bd → 3.0.0-devnet.20251212

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.
Files changed (53) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/instrumentation/instrumentation.d.ts +1 -1
  3. package/dest/instrumentation/instrumentation.d.ts.map +1 -1
  4. package/dest/native/bench_metrics.d.ts +1 -1
  5. package/dest/native/bench_metrics.d.ts.map +1 -1
  6. package/dest/native/fork_checkpoint.d.ts +1 -1
  7. package/dest/native/fork_checkpoint.d.ts.map +1 -1
  8. package/dest/native/index.d.ts +1 -1
  9. package/dest/native/merkle_trees_facade.d.ts +7 -4
  10. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  11. package/dest/native/merkle_trees_facade.js +7 -2
  12. package/dest/native/message.d.ts +13 -17
  13. package/dest/native/message.d.ts.map +1 -1
  14. package/dest/native/message.js +14 -20
  15. package/dest/native/native_world_state.d.ts +10 -9
  16. package/dest/native/native_world_state.d.ts.map +1 -1
  17. package/dest/native/native_world_state.js +16 -9
  18. package/dest/native/native_world_state_instance.d.ts +10 -1
  19. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  20. package/dest/native/native_world_state_instance.js +21 -0
  21. package/dest/native/world_state_ops_queue.d.ts +1 -1
  22. package/dest/native/world_state_ops_queue.d.ts.map +1 -1
  23. package/dest/synchronizer/config.d.ts +2 -2
  24. package/dest/synchronizer/config.js +1 -1
  25. package/dest/synchronizer/errors.d.ts +1 -1
  26. package/dest/synchronizer/errors.d.ts.map +1 -1
  27. package/dest/synchronizer/factory.d.ts +2 -2
  28. package/dest/synchronizer/factory.js +6 -6
  29. package/dest/synchronizer/index.d.ts +1 -1
  30. package/dest/synchronizer/server_world_state_synchronizer.d.ts +7 -25
  31. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  32. package/dest/synchronizer/server_world_state_synchronizer.js +32 -48
  33. package/dest/test/index.d.ts +1 -1
  34. package/dest/test/utils.d.ts +16 -9
  35. package/dest/test/utils.d.ts.map +1 -1
  36. package/dest/test/utils.js +52 -52
  37. package/dest/testing.d.ts +2 -2
  38. package/dest/testing.d.ts.map +1 -1
  39. package/dest/testing.js +1 -1
  40. package/dest/world-state-db/index.d.ts +1 -1
  41. package/dest/world-state-db/merkle_tree_db.d.ts +8 -7
  42. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  43. package/package.json +13 -12
  44. package/src/native/merkle_trees_facade.ts +9 -4
  45. package/src/native/message.ts +24 -39
  46. package/src/native/native_world_state.ts +40 -16
  47. package/src/native/native_world_state_instance.ts +28 -0
  48. package/src/synchronizer/config.ts +2 -2
  49. package/src/synchronizer/factory.ts +7 -7
  50. package/src/synchronizer/server_world_state_synchronizer.ts +59 -73
  51. package/src/test/utils.ts +88 -94
  52. package/src/testing.ts +1 -1
  53. package/src/world-state-db/merkle_tree_db.ts +7 -6
package/dest/testing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-juice';
4
4
  import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
5
5
  import { NativeWorldStateService } from './native/index.js';
@@ -1,3 +1,3 @@
1
1
  export * from './merkle_tree_db.js';
2
2
  export type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
3
- //# sourceMappingURL=index.d.ts.map
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHFCQUFxQixDQUFDO0FBRXBDLFlBQVksRUFBRSx3QkFBd0IsRUFBRSxNQUFNLGlDQUFpQyxDQUFDIn0=
@@ -1,6 +1,7 @@
1
- import type { Fr } from '@aztec/foundation/fields';
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import type { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import type { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
3
- import type { L2Block } from '@aztec/stdlib/block';
4
+ import type { L2BlockNew } from '@aztec/stdlib/block';
4
5
  import type { ForkMerkleTreeOperations, MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
5
6
  import type { MerkleTreeId } from '@aztec/stdlib/trees';
6
7
  import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/message.js';
@@ -34,7 +35,7 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
34
35
  * @param block - The L2 block to handle.
35
36
  * @param l1ToL2Messages - The L1 to L2 messages for the block.
36
37
  */
37
- handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
38
+ handleL2BlockAndMessages(block: L2BlockNew, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
38
39
  /**
39
40
  * Gets a handle that allows reading the latest committed state
40
41
  */
@@ -44,19 +45,19 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
44
45
  * @param toBlockNumber The block number of the new oldest historical block
45
46
  * @returns The new WorldStateStatus
46
47
  */
47
- removeHistoricalBlocks(toBlockNumber: bigint): Promise<WorldStateStatusFull>;
48
+ removeHistoricalBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
48
49
  /**
49
50
  * Removes all pending blocks down to but not including the given block number
50
51
  * @param toBlockNumber The block number of the new tip of the pending chain,
51
52
  * @returns The new WorldStateStatus
52
53
  */
53
- unwindBlocks(toBlockNumber: bigint): Promise<WorldStateStatusFull>;
54
+ unwindBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
54
55
  /**
55
56
  * Advances the finalized block number to be the number provided
56
57
  * @param toBlockNumber The block number that is now the tip of the finalized chain
57
58
  * @returns The new WorldStateStatus
58
59
  */
59
- setFinalized(toBlockNumber: bigint): Promise<WorldStateStatusSummary>;
60
+ setFinalized(toBlockNumber: BlockNumber): Promise<WorldStateStatusSummary>;
60
61
  /**
61
62
  * Gets the current status summary of the database.
62
63
  * @returns The current WorldStateStatus.
@@ -67,4 +68,4 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
67
68
  /** Deletes the db. */
68
69
  clear(): Promise<void>;
69
70
  }
70
- //# sourceMappingURL=merkle_tree_db.d.ts.map
71
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVya2xlX3RyZWVfZGIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9tZXJrbGVfdHJlZV9kYi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNuRSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxtQkFBbUIsRUFBRSxZQUFZLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUM1RSxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUN0RCxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBRSx3QkFBd0IsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQzFHLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBRXhELE9BQU8sS0FBSyxFQUFFLG9CQUFvQixFQUFFLHVCQUF1QixF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O,CAAC,IAAI,CAAC,CAAC;CACxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/world-state",
3
- "version": "3.0.0-canary.a9708bd",
3
+ "version": "3.0.0-devnet.20251212",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -18,8 +18,8 @@
18
18
  "tsconfig": "./tsconfig.json"
19
19
  },
20
20
  "scripts": {
21
- "build": "yarn clean && tsc -b",
22
- "build:dev": "tsc -b --watch",
21
+ "build": "yarn clean && ../scripts/tsc.sh",
22
+ "build:dev": "../scripts/tsc.sh --watch",
23
23
  "clean": "rm -rf ./dest .tsbuildinfo",
24
24
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
25
25
  },
@@ -64,22 +64,23 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "@aztec/constants": "3.0.0-canary.a9708bd",
68
- "@aztec/foundation": "3.0.0-canary.a9708bd",
69
- "@aztec/kv-store": "3.0.0-canary.a9708bd",
70
- "@aztec/merkle-tree": "3.0.0-canary.a9708bd",
71
- "@aztec/native": "3.0.0-canary.a9708bd",
72
- "@aztec/protocol-contracts": "3.0.0-canary.a9708bd",
73
- "@aztec/stdlib": "3.0.0-canary.a9708bd",
74
- "@aztec/telemetry-client": "3.0.0-canary.a9708bd",
67
+ "@aztec/constants": "3.0.0-devnet.20251212",
68
+ "@aztec/foundation": "3.0.0-devnet.20251212",
69
+ "@aztec/kv-store": "3.0.0-devnet.20251212",
70
+ "@aztec/merkle-tree": "3.0.0-devnet.20251212",
71
+ "@aztec/native": "3.0.0-devnet.20251212",
72
+ "@aztec/protocol-contracts": "3.0.0-devnet.20251212",
73
+ "@aztec/stdlib": "3.0.0-devnet.20251212",
74
+ "@aztec/telemetry-client": "3.0.0-devnet.20251212",
75
75
  "tslib": "^2.4.0",
76
76
  "zod": "^3.23.8"
77
77
  },
78
78
  "devDependencies": {
79
- "@aztec/archiver": "3.0.0-canary.a9708bd",
79
+ "@aztec/archiver": "3.0.0-devnet.20251212",
80
80
  "@jest/globals": "^30.0.0",
81
81
  "@types/jest": "^30.0.0",
82
82
  "@types/node": "^22.15.17",
83
+ "@typescript/native-preview": "7.0.0-dev.20251126.1",
83
84
  "jest": "^30.0.0",
84
85
  "jest-mock-extended": "^4.0.0",
85
86
  "ts-node": "^10.9.1",
@@ -1,4 +1,5 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import { serializeToBuffer } from '@aztec/foundation/serialize';
3
4
  import { type IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
4
5
  import type {
@@ -18,6 +19,7 @@ import {
18
19
  PublicDataTreeLeafPreimage,
19
20
  } from '@aztec/stdlib/trees';
20
21
  import { type BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
22
+ import { type WorldStateRevision, WorldStateRevisionWithHandle } from '@aztec/stdlib/world-state';
21
23
 
22
24
  import assert from 'assert';
23
25
 
@@ -25,7 +27,6 @@ import {
25
27
  type SerializedIndexedLeaf,
26
28
  type SerializedLeafValue,
27
29
  WorldStateMessageType,
28
- type WorldStateRevision,
29
30
  blockStateReference,
30
31
  treeStateReferenceToSnapshot,
31
32
  } from './message.js';
@@ -42,6 +43,10 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
42
43
  return this.initialHeader;
43
44
  }
44
45
 
46
+ getRevision(): WorldStateRevisionWithHandle {
47
+ return WorldStateRevisionWithHandle.fromWorldStateRevision(this.revision, this.instance.getHandle());
48
+ }
49
+
45
50
  findLeafIndices(treeId: MerkleTreeId, values: MerkleTreeLeafType<MerkleTreeId>[]): Promise<(bigint | undefined)[]> {
46
51
  return this.findLeafIndicesAfter(treeId, values, 0n);
47
52
  }
@@ -187,14 +192,14 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
187
192
  async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
188
193
  treeId: ID,
189
194
  leafIndices: bigint[],
190
- ): Promise<(bigint | undefined)[]> {
195
+ ): Promise<(BlockNumber | undefined)[]> {
191
196
  const response = await this.instance.call(WorldStateMessageType.GET_BLOCK_NUMBERS_FOR_LEAF_INDICES, {
192
197
  treeId,
193
198
  revision: this.revision,
194
199
  leafIndices,
195
200
  });
196
201
 
197
- return response.blockNumbers.map(x => (x === undefined || x === null ? undefined : BigInt(x)));
202
+ return response.blockNumbers.map(x => (x === undefined || x === null ? undefined : BlockNumber(Number(x))));
198
203
  }
199
204
  }
200
205
 
@@ -1,8 +1,10 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import type { Tuple } from '@aztec/foundation/serialize';
3
4
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
4
5
  import type { StateReference } from '@aztec/stdlib/tx';
5
6
  import type { UInt32 } from '@aztec/stdlib/types';
7
+ import type { WorldStateRevision } from '@aztec/stdlib/world-state';
6
8
 
7
9
  export enum WorldStateMessageType {
8
10
  GET_TREE_INFO = 100,
@@ -55,11 +57,11 @@ interface WithTreeId {
55
57
 
56
58
  export interface WorldStateStatusSummary {
57
59
  /** Last block number that can still be unwound. */
58
- unfinalizedBlockNumber: bigint;
60
+ unfinalizedBlockNumber: BlockNumber;
59
61
  /** Last block number that is finalized and cannot be unwound. */
60
- finalizedBlockNumber: bigint;
62
+ finalizedBlockNumber: BlockNumber;
61
63
  /** Oldest block still available for historical queries and forks. */
62
- oldestHistoricalBlock: bigint;
64
+ oldestHistoricalBlock: BlockNumber;
63
65
  /** Whether the trees are in sync with each other */
64
66
  treesAreSynched: boolean;
65
67
  }
@@ -80,11 +82,11 @@ export interface TreeMeta {
80
82
  /** The tree's initial root value */
81
83
  initialRoot: Fr;
82
84
  /** The current oldest historical block number of the tree */
83
- oldestHistoricBlock: bigint;
85
+ oldestHistoricBlock: BlockNumber;
84
86
  /** The current unfinalized block number of the tree */
85
- unfinalizedBlockHeight: bigint;
87
+ unfinalizedBlockHeight: BlockNumber;
86
88
  /** The current finalized block number of the tree */
87
- finalizedBlockHeight: bigint;
89
+ finalizedBlockHeight: BlockNumber;
88
90
  }
89
91
 
90
92
  export interface DBStats {
@@ -172,9 +174,9 @@ export function buildEmptyTreeMeta() {
172
174
  depth: 0,
173
175
  size: 0n,
174
176
  committedSize: 0n,
175
- unfinalizedBlockHeight: 0n,
176
- finalizedBlockHeight: 0n,
177
- oldestHistoricBlock: 0n,
177
+ unfinalizedBlockHeight: BlockNumber.ZERO,
178
+ finalizedBlockHeight: BlockNumber.ZERO,
179
+ oldestHistoricBlock: BlockNumber.ZERO,
178
180
  root: Fr.ZERO,
179
181
  initialRoot: Fr.ZERO,
180
182
  initialSize: 0n,
@@ -203,9 +205,9 @@ export function buildEmptyWorldStateDBStats() {
203
205
 
204
206
  export function buildEmptyWorldStateSummary() {
205
207
  return {
206
- unfinalizedBlockNumber: 0n,
207
- finalizedBlockNumber: 0n,
208
- oldestHistoricalBlock: 0n,
208
+ unfinalizedBlockNumber: BlockNumber.ZERO,
209
+ finalizedBlockNumber: BlockNumber.ZERO,
210
+ oldestHistoricalBlock: BlockNumber.ZERO,
209
211
  treesAreSynched: true,
210
212
  } as WorldStateStatusSummary;
211
213
  }
@@ -219,9 +221,9 @@ export function buildEmptyWorldStateStatusFull() {
219
221
  }
220
222
 
221
223
  export function sanitizeSummary(summary: WorldStateStatusSummary) {
222
- summary.finalizedBlockNumber = BigInt(summary.finalizedBlockNumber);
223
- summary.unfinalizedBlockNumber = BigInt(summary.unfinalizedBlockNumber);
224
- summary.oldestHistoricalBlock = BigInt(summary.oldestHistoricalBlock);
224
+ summary.finalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.finalizedBlockNumber));
225
+ summary.unfinalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.unfinalizedBlockNumber));
226
+ summary.oldestHistoricalBlock = BlockNumber.fromBigInt(BigInt(summary.oldestHistoricalBlock));
225
227
  return summary;
226
228
  }
227
229
 
@@ -233,11 +235,11 @@ export function sanitizeDBStats(stats: DBStats) {
233
235
 
234
236
  export function sanitizeMeta(meta: TreeMeta) {
235
237
  meta.committedSize = BigInt(meta.committedSize);
236
- meta.finalizedBlockHeight = BigInt(meta.finalizedBlockHeight);
238
+ meta.finalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.finalizedBlockHeight));
237
239
  meta.initialSize = BigInt(meta.initialSize);
238
- meta.oldestHistoricBlock = BigInt(meta.oldestHistoricBlock);
240
+ meta.oldestHistoricBlock = BlockNumber.fromBigInt(BigInt(meta.oldestHistoricBlock));
239
241
  meta.size = BigInt(meta.size);
240
- meta.unfinalizedBlockHeight = BigInt(meta.unfinalizedBlockHeight);
242
+ meta.unfinalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.unfinalizedBlockHeight));
241
243
  return meta;
242
244
  }
243
245
 
@@ -309,7 +311,7 @@ interface WithLeafValues {
309
311
  }
310
312
 
311
313
  interface BlockShiftRequest extends WithCanonicalForkId {
312
- toBlockNumber: bigint;
314
+ toBlockNumber: BlockNumber;
313
315
  }
314
316
 
315
317
  interface WithLeaves {
@@ -408,7 +410,7 @@ interface UpdateArchiveRequest extends WithForkId {
408
410
  }
409
411
 
410
412
  interface SyncBlockRequest extends WithCanonicalForkId {
411
- blockNumber: number;
413
+ blockNumber: BlockNumber;
412
414
  blockStateRef: BlockStateReference;
413
415
  blockHeaderHash: Fr;
414
416
  paddedNoteHashes: readonly SerializedLeafValue[];
@@ -419,7 +421,7 @@ interface SyncBlockRequest extends WithCanonicalForkId {
419
421
 
420
422
  interface CreateForkRequest extends WithCanonicalForkId {
421
423
  latest: boolean;
422
- blockNumber: number;
424
+ blockNumber: BlockNumber;
423
425
  }
424
426
 
425
427
  interface CreateForkResponse {
@@ -537,23 +539,6 @@ export type WorldStateResponse = {
537
539
  [WorldStateMessageType.CLOSE]: void;
538
540
  };
539
541
 
540
- export type WorldStateRevision = {
541
- forkId: number;
542
- blockNumber: number;
543
- includeUncommitted: boolean;
544
- };
545
- export function worldStateRevision(
546
- includeUncommitted: boolean,
547
- forkId: number | undefined,
548
- blockNumber: number | undefined,
549
- ): WorldStateRevision {
550
- return {
551
- forkId: forkId ?? 0,
552
- blockNumber: blockNumber ?? 0,
553
- includeUncommitted,
554
- };
555
- }
556
-
557
542
  type TreeStateReference = readonly [Buffer, number | bigint];
558
543
  type BlockStateReference = Map<Exclude<MerkleTreeId, MerkleTreeId.ARCHIVE>, TreeStateReference>;
559
544
 
@@ -1,10 +1,11 @@
1
1
  import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
3
  import { fromEntries, padArrayEnd } from '@aztec/foundation/collection';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
5
  import { EthAddress } from '@aztec/foundation/eth-address';
4
- import { Fr } from '@aztec/foundation/fields';
5
6
  import { tryRmDir } from '@aztec/foundation/fs';
6
7
  import { type Logger, createLogger } from '@aztec/foundation/log';
7
- import type { L2Block } from '@aztec/stdlib/block';
8
+ import type { L2BlockNew } from '@aztec/stdlib/block';
8
9
  import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
9
10
  import type {
10
11
  IndexedTreeId,
@@ -14,6 +15,7 @@ import type {
14
15
  import type { SnapshotDataKeys } from '@aztec/stdlib/snapshots';
15
16
  import { MerkleTreeId, NullifierLeaf, type NullifierLeafPreimage, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
16
17
  import { BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
18
+ import { WorldStateRevision } from '@aztec/stdlib/world-state';
17
19
  import { getTelemetryClient } from '@aztec/telemetry-client';
18
20
 
19
21
  import assert from 'assert/strict';
@@ -33,7 +35,6 @@ import {
33
35
  sanitizeFullStatus,
34
36
  sanitizeSummary,
35
37
  treeStateReferenceToSnapshot,
36
- worldStateRevision,
37
38
  } from './message.js';
38
39
  import { NativeWorldState } from './native_world_state_instance.js';
39
40
 
@@ -147,32 +148,55 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
147
148
  }
148
149
 
149
150
  public getCommitted(): MerkleTreeReadOperations {
150
- return new MerkleTreesFacade(this.instance, this.initialHeader!, worldStateRevision(false, 0, 0));
151
+ return new MerkleTreesFacade(this.instance, this.initialHeader!, WorldStateRevision.empty());
151
152
  }
152
153
 
153
- public getSnapshot(blockNumber: number): MerkleTreeReadOperations {
154
- return new MerkleTreesFacade(this.instance, this.initialHeader!, worldStateRevision(false, 0, blockNumber));
154
+ public getSnapshot(blockNumber: BlockNumber): MerkleTreeReadOperations {
155
+ return new MerkleTreesFacade(
156
+ this.instance,
157
+ this.initialHeader!,
158
+ new WorldStateRevision(/*forkId=*/ 0, /* blockNumber=*/ blockNumber, /* includeUncommitted=*/ false),
159
+ );
155
160
  }
156
161
 
157
- public async fork(blockNumber?: number): Promise<MerkleTreeWriteOperations> {
162
+ public async fork(blockNumber?: BlockNumber): Promise<MerkleTreeWriteOperations> {
158
163
  const resp = await this.instance.call(WorldStateMessageType.CREATE_FORK, {
159
164
  latest: blockNumber === undefined,
160
- blockNumber: blockNumber ?? 0,
165
+ blockNumber: blockNumber ?? BlockNumber.ZERO,
161
166
  canonical: true,
162
167
  });
163
- return new MerkleTreesForkFacade(this.instance, this.initialHeader!, worldStateRevision(true, resp.forkId, 0));
168
+ return new MerkleTreesForkFacade(
169
+ this.instance,
170
+ this.initialHeader!,
171
+ new WorldStateRevision(
172
+ /*forkId=*/ resp.forkId,
173
+ /* blockNumber=*/ BlockNumber.ZERO,
174
+ /* includeUncommitted=*/ true,
175
+ ),
176
+ );
164
177
  }
165
178
 
166
179
  public getInitialHeader(): BlockHeader {
167
180
  return this.initialHeader!;
168
181
  }
169
182
 
170
- public async handleL2BlockAndMessages(l2Block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull> {
171
- // We have to pad both the values within tx effects because that's how the trees are built by circuits.
183
+ public async handleL2BlockAndMessages(l2Block: L2BlockNew, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull> {
184
+ const isFirstBlock = l2Block.indexWithinCheckpoint === 0;
185
+ if (!isFirstBlock && l1ToL2Messages.length > 0) {
186
+ throw new Error(
187
+ `L1 to L2 messages must be empty for non-first blocks, but got ${l1ToL2Messages.length} messages for block ${l2Block.number}.`,
188
+ );
189
+ }
190
+
191
+ // We have to pad the given l1 to l2 messages, and the note hashes and nullifiers within tx effects, because that's
192
+ // how the trees are built by circuits.
193
+ const paddedL1ToL2Messages = isFirstBlock
194
+ ? padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP)
195
+ : [];
196
+
172
197
  const paddedNoteHashes = l2Block.body.txEffects.flatMap(txEffect =>
173
198
  padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
174
199
  );
175
- const paddedL1ToL2Messages = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
176
200
 
177
201
  const paddedNullifiers = l2Block.body.txEffects
178
202
  .flatMap(txEffect => padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX))
@@ -192,7 +216,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
192
216
  WorldStateMessageType.SYNC_BLOCK,
193
217
  {
194
218
  blockNumber: l2Block.number,
195
- blockHeaderHash: await l2Block.header.hash(),
219
+ blockHeaderHash: await l2Block.hash(),
196
220
  paddedL1ToL2Messages: paddedL1ToL2Messages.map(serializeLeaf),
197
221
  paddedNoteHashes: paddedNoteHashes.map(serializeLeaf),
198
222
  paddedNullifiers: paddedNullifiers.map(serializeLeaf),
@@ -240,7 +264,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
240
264
  * @param toBlockNumber The block number that is now the tip of the finalized chain
241
265
  * @returns The new WorldStateStatus
242
266
  */
243
- public async setFinalized(toBlockNumber: bigint) {
267
+ public async setFinalized(toBlockNumber: BlockNumber) {
244
268
  try {
245
269
  await this.instance.call(
246
270
  WorldStateMessageType.FINALIZE_BLOCKS,
@@ -263,7 +287,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
263
287
  * @param toBlockNumber The block number of the new oldest historical block
264
288
  * @returns The new WorldStateStatus
265
289
  */
266
- public async removeHistoricalBlocks(toBlockNumber: bigint) {
290
+ public async removeHistoricalBlocks(toBlockNumber: BlockNumber) {
267
291
  try {
268
292
  return await this.instance.call(
269
293
  WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS,
@@ -285,7 +309,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
285
309
  * @param toBlockNumber The block number of the new tip of the pending chain,
286
310
  * @returns The new WorldStateStatus
287
311
  */
288
- public async unwindBlocks(toBlockNumber: bigint) {
312
+ public async unwindBlocks(toBlockNumber: BlockNumber) {
289
313
  try {
290
314
  return await this.instance.call(
291
315
  WorldStateMessageType.UNWIND_BLOCKS,
@@ -36,6 +36,8 @@ export interface NativeWorldStateInstance {
36
36
  messageType: T,
37
37
  body: WorldStateRequest[T] & WorldStateRequestCategories,
38
38
  ): Promise<WorldStateResponse[T]>;
39
+ // TODO(dbanks12): this returns any type, but we should strongly type it
40
+ getHandle(): any;
39
41
  }
40
42
 
41
43
  /**
@@ -107,6 +109,32 @@ export class NativeWorldState implements NativeWorldStateInstance {
107
109
  );
108
110
  }
109
111
 
112
+ /**
113
+ * Gets the native WorldState handle from the underlying native instance.
114
+ * We call the getHandle() method on the native WorldState to get a NAPI External
115
+ * that wraps the underlying C++ WorldState pointer.
116
+ * @returns The NAPI External handle to the native WorldState instance,since
117
+ * the NAPI external type is opaque, we return any (we could also use an opaque symbol type)
118
+ */
119
+ public getHandle(): any {
120
+ const worldStateWrapper = (this.instance as any).dest;
121
+
122
+ if (!worldStateWrapper) {
123
+ throw new Error('No WorldStateWrapper found');
124
+ }
125
+
126
+ if (typeof worldStateWrapper.getHandle !== 'function') {
127
+ throw new Error('WorldStateWrapper does not have getHandle method');
128
+ }
129
+
130
+ // Call getHandle() to get the NAPI External
131
+ try {
132
+ return worldStateWrapper.getHandle();
133
+ } catch (error) {
134
+ this.log.error('Failed to get native WorldState handle', error);
135
+ }
136
+ }
137
+
110
138
  /**
111
139
  * Sends a message to the native instance and returns the response.
112
140
  * @param messageType - The type of message to send
@@ -16,7 +16,7 @@ export interface WorldStateConfig {
16
16
  /** Size of the batch for each get-blocks request from the synchronizer to the archiver. */
17
17
  worldStateBlockRequestBatchSize?: number;
18
18
 
19
- /** The map size to be provided to LMDB for each world state tree DB, optional, will inherit from the general dataStoreMapSizeKB if not specified*/
19
+ /** The map size to be provided to LMDB for each world state tree DB, optional, will inherit from the general dataStoreMapSizeKb if not specified*/
20
20
  worldStateDbMapSizeKb?: number;
21
21
 
22
22
  /** The map size to be provided to LMDB for each world state archive tree, optional, will inherit from the general worldStateDbMapSizeKb if not specified*/
@@ -61,7 +61,7 @@ export const worldStateConfigMappings: ConfigMappingsType<WorldStateConfig> = {
61
61
  worldStateDbMapSizeKb: {
62
62
  env: 'WS_DB_MAP_SIZE_KB',
63
63
  parseEnv: (val: string | undefined) => (val ? +val : undefined),
64
- description: 'The maximum possible size of the world state DB in KB. Overwrites the general dataStoreMapSizeKB.',
64
+ description: 'The maximum possible size of the world state DB in KB. Overwrites the general dataStoreMapSizeKb.',
65
65
  },
66
66
  archiveTreeMapSizeKb: {
67
67
  env: 'ARCHIVE_TREE_MAP_SIZE_KB',
@@ -39,18 +39,18 @@ export async function createWorldState(
39
39
  | 'messageTreeMapSizeKb'
40
40
  | 'publicDataTreeMapSizeKb'
41
41
  > &
42
- Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKB' | 'l1Contracts'>,
42
+ Pick<DataStoreConfig, 'dataDirectory' | 'dataStoreMapSizeKb' | 'l1Contracts'>,
43
43
  prefilledPublicData: PublicDataTreeLeaf[] = [],
44
44
  instrumentation: WorldStateInstrumentation = new WorldStateInstrumentation(getTelemetryClient()),
45
45
  ) {
46
46
  const dataDirectory = config.worldStateDataDirectory ?? config.dataDirectory;
47
- const dataStoreMapSizeKB = config.worldStateDbMapSizeKb ?? config.dataStoreMapSizeKB;
47
+ const dataStoreMapSizeKb = config.worldStateDbMapSizeKb ?? config.dataStoreMapSizeKb;
48
48
  const wsTreeMapSizes: WorldStateTreeMapSizes = {
49
- archiveTreeMapSizeKb: config.archiveTreeMapSizeKb ?? dataStoreMapSizeKB,
50
- nullifierTreeMapSizeKb: config.nullifierTreeMapSizeKb ?? dataStoreMapSizeKB,
51
- noteHashTreeMapSizeKb: config.noteHashTreeMapSizeKb ?? dataStoreMapSizeKB,
52
- messageTreeMapSizeKb: config.messageTreeMapSizeKb ?? dataStoreMapSizeKB,
53
- publicDataTreeMapSizeKb: config.publicDataTreeMapSizeKb ?? dataStoreMapSizeKB,
49
+ archiveTreeMapSizeKb: config.archiveTreeMapSizeKb ?? dataStoreMapSizeKb,
50
+ nullifierTreeMapSizeKb: config.nullifierTreeMapSizeKb ?? dataStoreMapSizeKb,
51
+ noteHashTreeMapSizeKb: config.noteHashTreeMapSizeKb ?? dataStoreMapSizeKb,
52
+ messageTreeMapSizeKb: config.messageTreeMapSizeKb ?? dataStoreMapSizeKb,
53
+ publicDataTreeMapSizeKb: config.publicDataTreeMapSizeKb ?? dataStoreMapSizeKb,
54
54
  };
55
55
 
56
56
  if (!config.l1Contracts?.rollupAddress) {