@aztec/world-state 0.0.1-commit.d431d1c → 0.0.1-commit.d58ff9d0

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 (76) hide show
  1. package/dest/index.d.ts +2 -1
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +1 -0
  4. package/dest/instrumentation/instrumentation.d.ts +4 -3
  5. package/dest/instrumentation/instrumentation.d.ts.map +1 -1
  6. package/dest/instrumentation/instrumentation.js +13 -11
  7. package/dest/native/fork_checkpoint.d.ts +7 -1
  8. package/dest/native/fork_checkpoint.d.ts.map +1 -1
  9. package/dest/native/fork_checkpoint.js +15 -3
  10. package/dest/native/index.d.ts +2 -1
  11. package/dest/native/index.d.ts.map +1 -1
  12. package/dest/native/index.js +1 -0
  13. package/dest/native/ipc_world_state_instance.d.ts +89 -0
  14. package/dest/native/ipc_world_state_instance.d.ts.map +1 -0
  15. package/dest/native/ipc_world_state_instance.js +661 -0
  16. package/dest/native/merkle_trees_facade.d.ts +12 -8
  17. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  18. package/dest/native/merkle_trees_facade.js +63 -115
  19. package/dest/native/message.d.ts +14 -221
  20. package/dest/native/message.d.ts.map +1 -1
  21. package/dest/native/message.js +0 -42
  22. package/dest/native/native_world_state.d.ts +22 -10
  23. package/dest/native/native_world_state.d.ts.map +1 -1
  24. package/dest/native/native_world_state.js +122 -59
  25. package/dest/native/native_world_state_instance.d.ts +56 -42
  26. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  27. package/dest/native/native_world_state_instance.js +1 -203
  28. package/dest/native/world_state_operation.d.ts +7 -0
  29. package/dest/native/world_state_operation.d.ts.map +1 -0
  30. package/dest/native/world_state_operation.js +5 -0
  31. package/dest/synchronizer/config.d.ts +3 -5
  32. package/dest/synchronizer/config.d.ts.map +1 -1
  33. package/dest/synchronizer/config.js +15 -18
  34. package/dest/synchronizer/errors.d.ts +8 -1
  35. package/dest/synchronizer/errors.d.ts.map +1 -1
  36. package/dest/synchronizer/errors.js +8 -1
  37. package/dest/synchronizer/factory.d.ts +6 -5
  38. package/dest/synchronizer/factory.d.ts.map +1 -1
  39. package/dest/synchronizer/factory.js +7 -6
  40. package/dest/synchronizer/index.d.ts +2 -1
  41. package/dest/synchronizer/index.d.ts.map +1 -1
  42. package/dest/synchronizer/index.js +1 -0
  43. package/dest/synchronizer/server_world_state_synchronizer.d.ts +13 -8
  44. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  45. package/dest/synchronizer/server_world_state_synchronizer.js +134 -49
  46. package/dest/test/utils.d.ts +6 -6
  47. package/dest/test/utils.d.ts.map +1 -1
  48. package/dest/test/utils.js +9 -4
  49. package/dest/testing.d.ts +4 -3
  50. package/dest/testing.d.ts.map +1 -1
  51. package/dest/testing.js +14 -7
  52. package/dest/world-state-db/merkle_tree_db.d.ts +3 -12
  53. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  54. package/package.json +13 -11
  55. package/src/index.ts +1 -0
  56. package/src/instrumentation/instrumentation.ts +15 -19
  57. package/src/native/fork_checkpoint.ts +19 -3
  58. package/src/native/index.ts +1 -0
  59. package/src/native/ipc_world_state_instance.ts +834 -0
  60. package/src/native/merkle_trees_facade.ts +89 -109
  61. package/src/native/message.ts +13 -286
  62. package/src/native/native_world_state.ts +152 -93
  63. package/src/native/native_world_state_instance.ts +94 -279
  64. package/src/native/world_state_operation.ts +33 -0
  65. package/src/synchronizer/config.ts +16 -23
  66. package/src/synchronizer/errors.ts +8 -0
  67. package/src/synchronizer/factory.ts +18 -11
  68. package/src/synchronizer/index.ts +1 -0
  69. package/src/synchronizer/server_world_state_synchronizer.ts +156 -51
  70. package/src/test/utils.ts +14 -5
  71. package/src/testing.ts +12 -10
  72. package/src/world-state-db/merkle_tree_db.ts +2 -12
  73. package/dest/native/world_state_ops_queue.d.ts +0 -19
  74. package/dest/native/world_state_ops_queue.d.ts.map +0 -1
  75. package/dest/native/world_state_ops_queue.js +0 -146
  76. package/src/native/world_state_ops_queue.ts +0 -190
@@ -1,9 +1,8 @@
1
- import { GENESIS_BLOCK_HEADER_HASH, INITIAL_L2_BLOCK_NUM, INITIAL_L2_CHECKPOINT_NUM } from '@aztec/constants';
2
- import { BlockNumber } from '@aztec/foundation/branded-types';
1
+ import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
3
2
  import { createLogger } from '@aztec/foundation/log';
4
3
  import { promiseWithResolvers } from '@aztec/foundation/promise';
5
4
  import { elapsed } from '@aztec/foundation/timer';
6
- import { GENESIS_CHECKPOINT_HEADER_HASH, L2BlockStream } from '@aztec/stdlib/block';
5
+ import { EventDrivenL2BlockStream } from '@aztec/stdlib/block';
7
6
  import { WorldStateRunningState } from '@aztec/stdlib/interfaces/server';
8
7
  import { MerkleTreeId } from '@aztec/stdlib/trees';
9
8
  import { getTelemetryClient } from '@aztec/telemetry-client';
@@ -38,7 +37,7 @@ import { WorldStateSynchronizerError } from './errors.js';
38
37
  this.currentState = WorldStateRunningState.IDLE;
39
38
  this.syncPromise = promiseWithResolvers();
40
39
  this.merkleTreeCommitted = this.merkleTreeDb.getCommitted();
41
- this.historyToKeep = config.worldStateBlockHistory < 1 ? undefined : config.worldStateBlockHistory;
40
+ this.historyToKeep = config.worldStateCheckpointHistory < 1 ? undefined : config.worldStateCheckpointHistory;
42
41
  this.log.info(`Created world state synchroniser with block history of ${this.historyToKeep === undefined ? 'infinity' : this.historyToKeep}`);
43
42
  }
44
43
  getCommitted() {
@@ -47,6 +46,39 @@ import { WorldStateSynchronizerError } from './errors.js';
47
46
  getSnapshot(blockNumber) {
48
47
  return this.merkleTreeDb.getSnapshot(blockNumber);
49
48
  }
49
+ async getVerifiedSnapshot(blockNumber, blockHash) {
50
+ const snapshot = this.merkleTreeDb.getSnapshot(blockNumber);
51
+ // Block 0's snapshot is the pre-genesis archive view (size 0), so archive leaf 0 is not visible from it;
52
+ // verify against the initial header hash instead. For later blocks, read archive leaf `blockNumber` from the
53
+ // snapshot's own view so the exact handle we return is validated against the requested fork.
54
+ const actualHash = blockNumber === BlockNumber.ZERO ? (await this.merkleTreeCommitted.getInitialHeader().hash()).toString() : (await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber)))?.toString();
55
+ if (actualHash === undefined) {
56
+ // A missing archive leaf means either the block's history has been pruned away (permanent: the block predates
57
+ // the oldest historical block kept by world state) or a reorg flipped the fork between the sync and this read
58
+ // (transient). Only the latter is worth retrying, so it alone surfaces as WorldStateSynchronizerError.
59
+ const { oldestHistoricalBlock } = await this.merkleTreeDb.getStatusSummary();
60
+ if (blockNumber < oldestHistoricalBlock) {
61
+ throw new Error(`Unable to find leaf for block ${blockNumber} in the archive tree: world state history has been pruned to block ${oldestHistoricalBlock}`);
62
+ }
63
+ throw new WorldStateSynchronizerError(`Unable to read block hash at block ${blockNumber} to verify snapshot`, {
64
+ cause: {
65
+ reason: 'block_not_available',
66
+ targetBlockNumber: blockNumber
67
+ }
68
+ });
69
+ }
70
+ if (actualHash !== blockHash.toString()) {
71
+ throw new WorldStateSynchronizerError(`Block hash mismatch at block ${blockNumber} (expected ${blockHash} but got ${actualHash})`, {
72
+ cause: {
73
+ reason: 'block_hash_mismatch',
74
+ targetBlockNumber: blockNumber,
75
+ expectedHash: blockHash.toString(),
76
+ actualHash
77
+ }
78
+ });
79
+ }
80
+ return snapshot;
81
+ }
50
82
  fork(blockNumber, opts) {
51
83
  return this.merkleTreeDb.fork(blockNumber, opts);
52
84
  }
@@ -64,7 +96,7 @@ import { WorldStateSynchronizerError } from './errors.js';
64
96
  return this.syncPromise;
65
97
  }
66
98
  // Get the current latest block number
67
- this.latestBlockNumberAtStart = BlockNumber(await (this.config.worldStateProvenBlocksOnly ? this.l2BlockSource.getProvenBlockNumber() : this.l2BlockSource.getBlockNumber()));
99
+ this.latestBlockNumberAtStart = BlockNumber(await this.l2BlockSource.getBlockNumber());
68
100
  const blockToDownloadFrom = await this.getLatestBlockNumber() + 1;
69
101
  if (blockToDownloadFrom <= this.latestBlockNumberAtStart) {
70
102
  // If there are blocks to be retrieved, go to a synching state
@@ -83,8 +115,7 @@ import { WorldStateSynchronizerError } from './errors.js';
83
115
  }
84
116
  createBlockStream() {
85
117
  const logger = createLogger('world-state:block_stream');
86
- return new L2BlockStream(this.l2BlockSource, this, this, logger, {
87
- proven: this.config.worldStateProvenBlocksOnly,
118
+ return new EventDrivenL2BlockStream(this.l2BlockSource, this, this, logger, {
88
119
  pollIntervalMS: this.config.worldStateBlockCheckIntervalMS,
89
120
  batchSize: this.config.worldStateBlockRequestBatchSize,
90
121
  ignoreCheckpoints: true
@@ -131,9 +162,9 @@ import { WorldStateSynchronizerError } from './errors.js';
131
162
  /**
132
163
  * Forces an immediate sync.
133
164
  * @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
134
- * @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
165
+ * @param blockHash - If provided, verifies the block at targetBlockNumber matches this hash. On mismatch, triggers a resync (reorg detection).
135
166
  * @returns A promise that resolves with the block number the world state was synced to
136
- */ async syncImmediate(targetBlockNumber, skipThrowIfTargetNotReached) {
167
+ */ async syncImmediate(targetBlockNumber, blockHash) {
137
168
  if (this.currentState !== WorldStateRunningState.RUNNING) {
138
169
  throw new Error(`World State is not running. Unable to perform sync.`);
139
170
  }
@@ -143,7 +174,16 @@ import { WorldStateSynchronizerError } from './errors.js';
143
174
  // If we have been given a block number to sync to and we have reached that number then return
144
175
  const currentBlockNumber = await this.getLatestBlockNumber();
145
176
  if (targetBlockNumber !== undefined && targetBlockNumber <= currentBlockNumber) {
146
- return currentBlockNumber;
177
+ if (blockHash === undefined) {
178
+ return currentBlockNumber;
179
+ }
180
+ // If a block hash was provided, verify we're on the expected fork
181
+ const currentHash = await this.getL2BlockHash(targetBlockNumber);
182
+ if (currentHash === blockHash.toString()) {
183
+ return currentBlockNumber;
184
+ }
185
+ // Hash mismatch: a reorg may have occurred, fall through to trigger sync
186
+ this.log.debug(`World state block hash mismatch at ${targetBlockNumber} (expected ${blockHash}, got ${currentHash}). Triggering resync.`);
147
187
  }
148
188
  this.log.debug(`World State at ${currentBlockNumber} told to sync to ${targetBlockNumber ?? 'latest'}`);
149
189
  // If the archiver is behind the target block, force an archiver sync
@@ -158,7 +198,7 @@ import { WorldStateSynchronizerError } from './errors.js';
158
198
  await this.blockStream.sync();
159
199
  // If we have been given a block number to sync to and we have not reached that number then fail
160
200
  const updatedBlockNumber = await this.getLatestBlockNumber();
161
- if (!skipThrowIfTargetNotReached && targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
201
+ if (targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
162
202
  throw new WorldStateSynchronizerError(`Unable to sync to block number ${targetBlockNumber} (last synced is ${updatedBlockNumber})`, {
163
203
  cause: {
164
204
  reason: 'block_not_available',
@@ -168,6 +208,20 @@ import { WorldStateSynchronizerError } from './errors.js';
168
208
  }
169
209
  });
170
210
  }
211
+ // If a block hash was provided, verify we're on the expected fork after syncing, throw otherwise
212
+ if (blockHash !== undefined && targetBlockNumber !== undefined) {
213
+ const updatedHash = await this.getL2BlockHash(targetBlockNumber);
214
+ if (updatedHash !== blockHash.toString()) {
215
+ throw new WorldStateSynchronizerError(`Block hash mismatch at block ${targetBlockNumber} (expected ${blockHash} but got ${updatedHash})`, {
216
+ cause: {
217
+ reason: 'block_hash_mismatch',
218
+ targetBlockNumber,
219
+ expectedHash: blockHash.toString(),
220
+ actualHash: updatedHash
221
+ }
222
+ });
223
+ }
224
+ }
171
225
  return updatedBlockNumber;
172
226
  }
173
227
  /** Returns the L2 block hash for a given number. Used by the L2BlockStream for detecting reorgs. */ async getL2BlockHash(number) {
@@ -176,7 +230,11 @@ import { WorldStateSynchronizerError } from './errors.js';
176
230
  }
177
231
  return this.merkleTreeCommitted.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(number)).then((leaf)=>leaf?.toString());
178
232
  }
179
- /** Returns the latest L2 block number for each tip of the chain (latest, proven, finalized). */ async getL2Tips() {
233
+ /**
234
+ * Returns the proposed, proven, and finalized block tips of the chain. World state drives its block stream with
235
+ * `ignoreCheckpoints`, so it does not track checkpointed blocks or checkpoints and omits `checkpointed` from the tips
236
+ * it reports.
237
+ */ async getL2Tips() {
180
238
  const status = await this.merkleTreeDb.getStatusSummary();
181
239
  const unfinalizedBlockHashPromise = this.getL2BlockHash(status.unfinalizedBlockNumber);
182
240
  const finalizedBlockHashPromise = this.getL2BlockHash(status.finalizedBlockNumber);
@@ -187,44 +245,21 @@ import { WorldStateSynchronizerError } from './errors.js';
187
245
  finalizedBlockHashPromise,
188
246
  provenBlockHashPromise
189
247
  ]);
190
- const latestBlockId = {
191
- number: status.unfinalizedBlockNumber,
192
- hash: unfinalizedBlockHash
193
- };
194
- // World state doesn't track checkpointed blocks or checkpoints themselves.
195
- // but we use a block stream so we need to provide 'local' L2Tips.
196
- // We configure the block stream to ignore checkpoints and set checkpoint values to genesis here.
197
- const genesisCheckpointHeaderHash = GENESIS_CHECKPOINT_HEADER_HASH.toString();
198
248
  return {
199
- proposed: latestBlockId,
200
- checkpointed: {
201
- block: {
202
- number: INITIAL_L2_BLOCK_NUM,
203
- hash: GENESIS_BLOCK_HEADER_HASH.toString()
204
- },
205
- checkpoint: {
206
- number: INITIAL_L2_CHECKPOINT_NUM,
207
- hash: genesisCheckpointHeaderHash
208
- }
249
+ proposed: {
250
+ number: status.unfinalizedBlockNumber,
251
+ hash: unfinalizedBlockHash
209
252
  },
210
253
  finalized: {
211
254
  block: {
212
255
  number: status.finalizedBlockNumber,
213
- hash: finalizedBlockHash ?? ''
214
- },
215
- checkpoint: {
216
- number: INITIAL_L2_CHECKPOINT_NUM,
217
- hash: genesisCheckpointHeaderHash
256
+ hash: finalizedBlockHash
218
257
  }
219
258
  },
220
259
  proven: {
221
260
  block: {
222
261
  number: provenBlockNumber,
223
- hash: provenBlockHash ?? ''
224
- },
225
- checkpoint: {
226
- number: INITIAL_L2_CHECKPOINT_NUM,
227
- hash: genesisCheckpointHeaderHash
262
+ hash: provenBlockHash
228
263
  }
229
264
  }
230
265
  };
@@ -243,6 +278,16 @@ import { WorldStateSynchronizerError } from './errors.js';
243
278
  case 'chain-finalized':
244
279
  await this.handleChainFinalized(event.block.number);
245
280
  break;
281
+ // World state runs in block mode with ignoreCheckpoints: it tracks tips via blocks-added/pruned/proven/finalized
282
+ // and ignores the thin tip events (it never anchors on them).
283
+ case 'chain-proposed':
284
+ case 'chain-checkpointed':
285
+ break;
286
+ default:
287
+ {
288
+ const _ = event;
289
+ break;
290
+ }
246
291
  }
247
292
  }
248
293
  /**
@@ -250,7 +295,7 @@ import { WorldStateSynchronizerError } from './errors.js';
250
295
  * @param l2Blocks - The L2 blocks to handle.
251
296
  * @returns Whether the block handled was produced by this same node.
252
297
  */ async handleL2Blocks(l2Blocks) {
253
- this.log.trace(`Handling L2 blocks ${l2Blocks[0].number} to ${l2Blocks.at(-1).number}`);
298
+ this.log.debug(`Handling L2 blocks ${l2Blocks[0].number} to ${l2Blocks.at(-1).number}`);
254
299
  // Fetch the L1->L2 messages for the first block in a checkpoint.
255
300
  const messagesForBlocks = new Map();
256
301
  await Promise.all(l2Blocks.filter((b)=>b.indexWithinCheckpoint === 0).map(async (block)=>{
@@ -281,10 +326,12 @@ import { WorldStateSynchronizerError } from './errors.js';
281
326
  * @param l1ToL2Messages - The L1 to L2 messages for the block.
282
327
  * @returns Whether the block handled was produced by this same node.
283
328
  */ async handleL2Block(l2Block, l1ToL2Messages) {
284
- this.log.trace(`Pushing L2 block ${l2Block.number} to merkle tree db `, {
329
+ this.log.debug(`Pushing L2 block ${l2Block.number} to merkle tree db `, {
285
330
  blockNumber: l2Block.number,
286
331
  blockHash: await l2Block.hash().then((h)=>h.toString()),
287
- l1ToL2Messages: l1ToL2Messages.map((msg)=>msg.toString())
332
+ l1ToL2Messages: l1ToL2Messages.map((msg)=>msg.toString()),
333
+ blockHeader: l2Block.header.toInspect(),
334
+ blockStats: l2Block.getStats()
288
335
  });
289
336
  const result = await this.merkleTreeDb.handleL2BlockAndMessages(l2Block, l1ToL2Messages);
290
337
  if (this.currentState === WorldStateRunningState.SYNCHING && l2Block.number >= this.latestBlockNumberAtStart) {
@@ -295,16 +342,52 @@ import { WorldStateSynchronizerError } from './errors.js';
295
342
  }
296
343
  async handleChainFinalized(blockNumber) {
297
344
  this.log.verbose(`Finalized chain is now at block ${blockNumber}`);
345
+ // If the finalized block number is older than the oldest available block in world state,
346
+ // skip entirely. The finalized block number can jump backwards (e.g. when the finalization
347
+ // heuristic changes) and try to read block data that has already been pruned. When this
348
+ // happens, there is nothing useful to do — the native world state is already finalized
349
+ // past this point and pruning has already happened.
350
+ const currentSummary = await this.merkleTreeDb.getStatusSummary();
351
+ if (blockNumber < currentSummary.oldestHistoricalBlock || blockNumber < 1) {
352
+ this.log.trace(`Finalized block ${blockNumber} is older than the oldest available block ${currentSummary.oldestHistoricalBlock}. Skipping.`);
353
+ return;
354
+ }
298
355
  const summary = await this.merkleTreeDb.setFinalized(blockNumber);
299
356
  if (this.historyToKeep === undefined) {
300
357
  return;
301
358
  }
302
- const newHistoricBlock = summary.finalizedBlockNumber - this.historyToKeep + 1;
303
- if (newHistoricBlock <= 1) {
359
+ const finalisedBlockData = await this.l2BlockSource.getBlockData({
360
+ number: summary.finalizedBlockNumber
361
+ });
362
+ if (finalisedBlockData === undefined) {
363
+ this.log.warn(`Failed to retrieve checkpointed block for finalized block number: ${summary.finalizedBlockNumber}`);
364
+ return;
365
+ }
366
+ // Compute the required historic checkpoint number
367
+ const newHistoricCheckpointNumber = finalisedBlockData.checkpointNumber - this.historyToKeep + 1;
368
+ if (newHistoricCheckpointNumber <= 1) {
304
369
  return;
305
370
  }
306
- this.log.verbose(`Pruning historic blocks to ${newHistoricBlock}`);
307
- const status = await this.merkleTreeDb.removeHistoricalBlocks(BlockNumber(newHistoricBlock));
371
+ // Retrieve the historic checkpoint
372
+ const historicCheckpoint = await this.l2BlockSource.getCheckpoint({
373
+ number: CheckpointNumber(newHistoricCheckpointNumber)
374
+ });
375
+ if (!historicCheckpoint) {
376
+ this.log.warn(`Failed to retrieve checkpoint number ${newHistoricCheckpointNumber} from Archiver`);
377
+ return;
378
+ }
379
+ if (historicCheckpoint.checkpoint.blocks.length === 0 || historicCheckpoint.checkpoint.blocks[0] === undefined) {
380
+ this.log.warn(`Retrieved checkpoint number ${newHistoricCheckpointNumber} has no blocks!`);
381
+ return;
382
+ }
383
+ // Find the block at the start of the checkpoint and remove blocks up to this one
384
+ const newHistoricBlock = historicCheckpoint.checkpoint.blocks[0];
385
+ if (newHistoricBlock.number <= currentSummary.oldestHistoricalBlock) {
386
+ this.log.debug(`Historic block ${newHistoricBlock.number} is not newer than oldest available ${currentSummary.oldestHistoricalBlock}. Skipping prune.`);
387
+ return;
388
+ }
389
+ this.log.verbose(`Pruning historic blocks to ${newHistoricBlock.number}`);
390
+ const status = await this.merkleTreeDb.removeHistoricalBlocks(BlockNumber(newHistoricBlock.number));
308
391
  this.log.debug(`World state summary `, status.summary);
309
392
  }
310
393
  handleChainProven(blockNumber) {
@@ -313,9 +396,11 @@ import { WorldStateSynchronizerError } from './errors.js';
313
396
  return Promise.resolve();
314
397
  }
315
398
  async handleChainPruned(blockNumber) {
316
- this.log.warn(`Chain pruned to block ${blockNumber}`);
399
+ this.log.info(`Chain pruned to block ${blockNumber}`);
317
400
  const status = await this.merkleTreeDb.unwindBlocks(blockNumber);
318
- this.provenBlockNumber = undefined;
401
+ if (this.provenBlockNumber !== undefined && this.provenBlockNumber > blockNumber) {
402
+ this.provenBlockNumber = undefined;
403
+ }
319
404
  this.instrumentation.updateWorldStateMetrics(status);
320
405
  }
321
406
  /**
@@ -1,20 +1,20 @@
1
1
  import { BlockNumber, type CheckpointNumber } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { L2BlockNew } from '@aztec/stdlib/block';
3
+ import { L2Block } from '@aztec/stdlib/block';
4
4
  import type { MerkleTreeReadOperations, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
5
5
  import { mockCheckpointAndMessages } from '@aztec/stdlib/testing';
6
6
  import type { NativeWorldStateService } from '../native/native_world_state.js';
7
- export declare function updateBlockState(block: L2BlockNew, l1ToL2Messages: Fr[], fork: MerkleTreeWriteOperations): Promise<void>;
7
+ export declare function updateBlockState(block: L2Block, l1ToL2Messages: Fr[], fork: MerkleTreeWriteOperations): Promise<void>;
8
8
  export declare function mockBlock(blockNum: BlockNumber, size: number, fork: MerkleTreeWriteOperations, maxEffects?: number | undefined, numL1ToL2Messages?: number, isFirstBlockInCheckpoint?: boolean): Promise<{
9
- block: L2BlockNew;
9
+ block: L2Block;
10
10
  messages: Fr[];
11
11
  }>;
12
12
  export declare function mockEmptyBlock(blockNum: BlockNumber, fork: MerkleTreeWriteOperations): Promise<{
13
- block: L2BlockNew;
13
+ block: L2Block;
14
14
  messages: Fr[];
15
15
  }>;
16
16
  export declare function mockBlocks(from: BlockNumber, count: number, numTxs: number, worldState: NativeWorldStateService): Promise<{
17
- blocks: L2BlockNew[];
17
+ blocks: L2Block[];
18
18
  messages: Fr[][];
19
19
  }>;
20
20
  export declare function mockCheckpoint(checkpointNumber: CheckpointNumber, fork: MerkleTreeWriteOperations, options?: Partial<Parameters<typeof mockCheckpointAndMessages>[1]>): Promise<{
@@ -23,4 +23,4 @@ export declare function mockCheckpoint(checkpointNumber: CheckpointNumber, fork:
23
23
  }>;
24
24
  export declare function assertSameState(forkA: MerkleTreeReadOperations, forkB: MerkleTreeReadOperations): Promise<void>;
25
25
  export declare function compareChains(left: MerkleTreeReadOperations, right: MerkleTreeReadOperations): Promise<void>;
26
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L3V0aWxzLnRzIl0sIm5hbWVzIjpb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aztec/foundation/branded-types';
4
4
  import { padArrayEnd } from '@aztec/foundation/collection';
5
5
  import { Fr } from '@aztec/foundation/curves/bn254';
6
- import { L2BlockNew } from '@aztec/stdlib/block';
6
+ import { L2Block } from '@aztec/stdlib/block';
7
7
  import { mockCheckpointAndMessages, mockL1ToL2Messages } from '@aztec/stdlib/testing';
8
8
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
9
9
  import { BlockHeader } from '@aztec/stdlib/tx';
@@ -26,16 +26,21 @@ export async function updateBlockState(block, l1ToL2Messages, fork) {
26
26
  messageInsert
27
27
  ]);
28
28
  const state = await fork.getStateReference();
29
+ // Capture the archive root *before* appending this block so the header's lastArchive chains off the previous block.
30
+ // sync_block now verifies lastArchive against the committed archive root, so a block carrying an unchained value
31
+ // (e.g. the random lastArchive from L2Block.random) would be rejected as a divergence from the canonical chain.
32
+ const previousArchive = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
29
33
  block.header = BlockHeader.from({
30
34
  ...block.header,
31
- state
35
+ state,
36
+ lastArchive: new AppendOnlyTreeSnapshot(Fr.fromBuffer(previousArchive.root), Number(previousArchive.size))
32
37
  });
33
38
  await fork.updateArchive(block.header);
34
39
  const archiveState = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
35
40
  block.archive = new AppendOnlyTreeSnapshot(Fr.fromBuffer(archiveState.root), Number(archiveState.size));
36
41
  }
37
42
  export async function mockBlock(blockNum, size, fork, maxEffects = 1000, numL1ToL2Messages = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, isFirstBlockInCheckpoint = true) {
38
- const block = await L2BlockNew.random(blockNum, {
43
+ const block = await L2Block.random(blockNum, {
39
44
  indexWithinCheckpoint: isFirstBlockInCheckpoint ? IndexWithinCheckpoint(0) : IndexWithinCheckpoint(1),
40
45
  txsPerBlock: size,
41
46
  txOptions: {
@@ -50,7 +55,7 @@ export async function mockBlock(blockNum, size, fork, maxEffects = 1000, numL1To
50
55
  };
51
56
  }
52
57
  export async function mockEmptyBlock(blockNum, fork) {
53
- const l2Block = L2BlockNew.empty();
58
+ const l2Block = L2Block.empty();
54
59
  const l1ToL2Messages = Array(16).fill(0).map(Fr.zero);
55
60
  l2Block.header.globalVariables.blockNumber = blockNum;
56
61
  await updateBlockState(l2Block, l1ToL2Messages, fork);
package/dest/testing.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
  import { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
4
+ import type { GenesisData } from '@aztec/stdlib/world-state';
4
5
  export declare const defaultInitialAccountFeeJuice: Fr;
5
- export declare function getGenesisValues(initialAccounts: AztecAddress[], initialAccountFeeJuice?: Fr, genesisPublicData?: PublicDataTreeLeaf[]): Promise<{
6
+ export declare function getGenesisValues(initialAccounts: AztecAddress[], initialAccountFeeJuice?: Fr, genesisPublicData?: PublicDataTreeLeaf[], genesisTimestamp?: bigint): Promise<{
6
7
  genesisArchiveRoot: Fr;
7
- prefilledPublicData: PublicDataTreeLeaf[];
8
+ genesis: GenesisData;
8
9
  fundingNeeded: bigint;
9
10
  }>;
10
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFBZ0Isa0JBQWtCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQXlCdkUsZUFBTyxNQUFNLDZCQUE2QixJQUFxQixDQUFDO0FBRWhFLHdCQUFzQixnQk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AE,EAC/B,sBAAsB,KAAgC,EACtD,iBAAiB,GAAE,kBAAkB,EAAO;;;;GAqB7C"}
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAgB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAwB7D,eAAO,MAAM,6BAA6B,IAAqB,CAAC;AAEhE,wBAAsB,gBAAgB,CACpC,eAAe,EAAE,YAAY,EAAE,EAC/B,sBAAsB,KAAgC,EACtD,iBAAiB,GAAE,kBAAkB,EAAO,EAC5C,gBAAgB,GAAE,MAAW;;;;GAsB9B"}
package/dest/testing.js CHANGED
@@ -3,14 +3,17 @@ 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';
6
- async function generateGenesisValues(prefilledPublicData) {
7
- if (!prefilledPublicData.length) {
6
+ async function generateGenesisValues(genesis) {
7
+ if (!genesis.prefilledPublicData.length && genesis.genesisTimestamp === 0n) {
8
8
  return {
9
9
  genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT)
10
10
  };
11
11
  }
12
- // Create a temporary world state to compute the genesis values.
13
- const ws = await NativeWorldStateService.tmp(undefined /* rollupAddress */ , true, prefilledPublicData);
12
+ // Compute the genesis values on a throwaway world state. The archive root derives only from the
13
+ // prefilled public data and the genesis timestamp, so the fsync-off ephemeral store (no version
14
+ // manager, no crash-recoverability) produces an identical root while skipping the fsync overhead
15
+ // that `tmp` pays. close() removes the tmpdir.
16
+ const ws = await NativeWorldStateService.ephemeral(genesis);
14
17
  const genesisArchiveRoot = new Fr((await ws.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
15
18
  await ws.close();
16
19
  return {
@@ -18,16 +21,20 @@ async function generateGenesisValues(prefilledPublicData) {
18
21
  };
19
22
  }
20
23
  export const defaultInitialAccountFeeJuice = new Fr(10n ** 22n);
21
- export async function getGenesisValues(initialAccounts, initialAccountFeeJuice = defaultInitialAccountFeeJuice, genesisPublicData = []) {
24
+ export async function getGenesisValues(initialAccounts, initialAccountFeeJuice = defaultInitialAccountFeeJuice, genesisPublicData = [], genesisTimestamp = 0n) {
22
25
  // Top up the accounts with fee juice.
23
26
  let prefilledPublicData = await Promise.all(initialAccounts.map(async (address)=>new PublicDataTreeLeaf(await computeFeePayerBalanceLeafSlot(address), initialAccountFeeJuice)));
24
27
  // Add user-defined public data
25
28
  prefilledPublicData = prefilledPublicData.concat(genesisPublicData);
26
29
  prefilledPublicData.sort((a, b)=>b.slot.lt(a.slot) ? 1 : -1);
27
- const { genesisArchiveRoot } = await generateGenesisValues(prefilledPublicData);
30
+ const genesis = {
31
+ prefilledPublicData,
32
+ genesisTimestamp
33
+ };
34
+ const { genesisArchiveRoot } = await generateGenesisValues(genesis);
28
35
  return {
29
36
  genesisArchiveRoot,
30
- prefilledPublicData,
37
+ genesis,
31
38
  fundingNeeded: BigInt(initialAccounts.length) * initialAccountFeeJuice.toBigInt()
32
39
  };
33
40
  }
@@ -1,9 +1,7 @@
1
1
  import type { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import type { Fr } from '@aztec/foundation/curves/bn254';
3
- import type { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
4
- import type { L2BlockNew } from '@aztec/stdlib/block';
3
+ import type { L2Block } from '@aztec/stdlib/block';
5
4
  import type { ForkMerkleTreeOperations, MerkleTreeReadOperations, ReadonlyWorldStateAccess } from '@aztec/stdlib/interfaces/server';
6
- import type { MerkleTreeId } from '@aztec/stdlib/trees';
7
5
  import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/message.js';
8
6
  /**
9
7
  *
@@ -22,20 +20,13 @@ import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/me
22
20
  */
23
21
  export declare const INITIAL_NULLIFIER_TREE_SIZE: number;
24
22
  export declare const INITIAL_PUBLIC_DATA_TREE_SIZE: number;
25
- export type TreeSnapshots = {
26
- [MerkleTreeId.NULLIFIER_TREE]: IndexedTreeSnapshot;
27
- [MerkleTreeId.NOTE_HASH_TREE]: TreeSnapshot<Fr>;
28
- [MerkleTreeId.PUBLIC_DATA_TREE]: IndexedTreeSnapshot;
29
- [MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: TreeSnapshot<Fr>;
30
- [MerkleTreeId.ARCHIVE]: TreeSnapshot<Fr>;
31
- };
32
23
  export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations, ReadonlyWorldStateAccess {
33
24
  /**
34
25
  * Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
35
26
  * @param block - The L2 block to handle.
36
27
  * @param l1ToL2Messages - The L1 to L2 messages for the block.
37
28
  */
38
- handleL2BlockAndMessages(block: L2BlockNew, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
29
+ handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
39
30
  /**
40
31
  * Gets a handle that allows reading the latest committed state
41
32
  */
@@ -68,4 +59,4 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations, Reado
68
59
  /** Deletes the db. */
69
60
  clear(): Promise<void>;
70
61
  }
71
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVya2xlX3RyZWVfZGIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9tZXJrbGVfdHJlZV9kYi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIj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AACH,eAAO,MAAM,2BAA2B,QAA4B,CAAC;AAErE,eAAO,MAAM,6BAA6B,QAAmD,CAAC;AAE9F,MAAM,WAAW,uBAAwB,SAAQ,wBAAwB,EAAE,wBAAwB;IACjG;;;;OAIG;IACH,wBAAwB,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAE9F;;OAEG;IACH,YAAY,IAAI,wBAAwB,CAAC;IAEzC;;;;OAIG;IACH,sBAAsB,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAElF;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAExE;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAE3E;;;OAGG;IACH,gBAAgB,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAErD,yBAAyB;IACzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,sBAAsB;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/world-state",
3
- "version": "0.0.1-commit.d431d1c",
3
+ "version": "0.0.1-commit.d58ff9d0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -64,19 +64,21 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "@aztec/constants": "0.0.1-commit.d431d1c",
68
- "@aztec/foundation": "0.0.1-commit.d431d1c",
69
- "@aztec/kv-store": "0.0.1-commit.d431d1c",
70
- "@aztec/merkle-tree": "0.0.1-commit.d431d1c",
71
- "@aztec/native": "0.0.1-commit.d431d1c",
72
- "@aztec/protocol-contracts": "0.0.1-commit.d431d1c",
73
- "@aztec/stdlib": "0.0.1-commit.d431d1c",
74
- "@aztec/telemetry-client": "0.0.1-commit.d431d1c",
67
+ "@aztec/bb.js": "0.0.1-commit.d58ff9d0",
68
+ "@aztec/constants": "0.0.1-commit.d58ff9d0",
69
+ "@aztec/foundation": "0.0.1-commit.d58ff9d0",
70
+ "@aztec/kv-store": "0.0.1-commit.d58ff9d0",
71
+ "@aztec/protocol-contracts": "0.0.1-commit.d58ff9d0",
72
+ "@aztec/stdlib": "0.0.1-commit.d58ff9d0",
73
+ "@aztec/telemetry-client": "0.0.1-commit.d58ff9d0",
74
+ "@aztec/wsdb": "0.0.1-commit.d58ff9d0",
75
+ "msgpackr": "^1.11.2",
75
76
  "tslib": "^2.4.0",
76
- "zod": "^3.23.8"
77
+ "zod": "^4"
77
78
  },
78
79
  "devDependencies": {
79
- "@aztec/archiver": "0.0.1-commit.d431d1c",
80
+ "@aztec/archiver": "0.0.1-commit.d58ff9d0",
81
+ "@aztec/ipc-runtime": "0.0.1-commit.d58ff9d0",
80
82
  "@jest/globals": "^30.0.0",
81
83
  "@types/jest": "^30.0.0",
82
84
  "@types/node": "^22.15.17",
package/src/index.ts CHANGED
@@ -2,3 +2,4 @@ export * from './synchronizer/index.js';
2
2
  export * from './world-state-db/index.js';
3
3
  export * from './synchronizer/config.js';
4
4
  export * from './native/index.js';
5
+ export { WorldStateInstrumentation } from './instrumentation/instrumentation.js';
@@ -7,26 +7,15 @@ import {
7
7
  Metrics,
8
8
  type TelemetryClient,
9
9
  type UpDownCounter,
10
+ createUpDownCounterWithDefault,
10
11
  } from '@aztec/telemetry-client';
11
12
 
12
- import {
13
- type DBStats,
14
- type TreeDBStats,
15
- type TreeMeta,
16
- WorldStateMessageType,
17
- type WorldStateStatusFull,
18
- } from '../native/message.js';
13
+ import type { DBStats, TreeDBStats, TreeMeta, WorldStateStatusFull } from '../native/message.js';
14
+ import type { WorldStateOperationName } from '../native/world_state_operation.js';
19
15
 
20
16
  type DBTypeString = 'leaf_preimage' | 'leaf_indices' | 'nodes' | 'blocks' | 'block_indices';
21
17
 
22
- const durationTrackDenylist = new Set<WorldStateMessageType>([
23
- WorldStateMessageType.GET_INITIAL_STATE_REFERENCE,
24
- WorldStateMessageType.CLOSE,
25
-
26
- // these aren't used anymore, should be removed from the API
27
- WorldStateMessageType.COMMIT,
28
- WorldStateMessageType.ROLLBACK,
29
- ]);
18
+ const durationTrackDenylist = new Set<WorldStateOperationName>(['getInitialStateReference']);
30
19
 
31
20
  export class WorldStateInstrumentation {
32
21
  private dbMapSize: Gauge;
@@ -63,7 +52,14 @@ export class WorldStateInstrumentation {
63
52
 
64
53
  this.requestHistogram = meter.createHistogram(Metrics.WORLD_STATE_REQUEST_TIME);
65
54
 
66
- this.criticalErrors = meter.createUpDownCounter(Metrics.WORLD_STATE_CRITICAL_ERROR_COUNT);
55
+ this.criticalErrors = createUpDownCounterWithDefault(meter, Metrics.WORLD_STATE_CRITICAL_ERROR_COUNT, {
56
+ [Attributes.ERROR_TYPE]: [
57
+ 'synch_pending_block',
58
+ 'finalize_block',
59
+ 'prune_pending_block',
60
+ 'prune_historical_block',
61
+ ],
62
+ });
67
63
  }
68
64
 
69
65
  private updateTreeStats(treeDbStats: TreeDBStats, treeMeta: TreeMeta, tree: MerkleTreeId) {
@@ -136,10 +132,10 @@ export class WorldStateInstrumentation {
136
132
  );
137
133
  }
138
134
 
139
- public recordRoundTrip(timeUs: number, request: WorldStateMessageType) {
140
- if (!durationTrackDenylist.has(request)) {
135
+ public recordRoundTrip(timeUs: number, operation: WorldStateOperationName) {
136
+ if (!durationTrackDenylist.has(operation)) {
141
137
  this.requestHistogram.record(Math.ceil(timeUs), {
142
- [Attributes.WORLD_STATE_REQUEST_TYPE]: WorldStateMessageType[request],
138
+ [Attributes.WORLD_STATE_REQUEST_TYPE]: operation,
143
139
  });
144
140
  }
145
141
  }