@aztec/world-state 0.0.1-commit.86469d5 → 0.0.1-commit.8655d4a

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 (45) hide show
  1. package/dest/native/fork_checkpoint.d.ts +7 -1
  2. package/dest/native/fork_checkpoint.d.ts.map +1 -1
  3. package/dest/native/fork_checkpoint.js +15 -3
  4. package/dest/native/ipc_world_state_instance.d.ts +50 -0
  5. package/dest/native/ipc_world_state_instance.d.ts.map +1 -0
  6. package/dest/native/ipc_world_state_instance.js +628 -0
  7. package/dest/native/merkle_trees_facade.d.ts +9 -6
  8. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  9. package/dest/native/merkle_trees_facade.js +33 -13
  10. package/dest/native/message.d.ts +13 -6
  11. package/dest/native/message.d.ts.map +1 -1
  12. package/dest/native/native_world_state.d.ts +31 -5
  13. package/dest/native/native_world_state.d.ts.map +1 -1
  14. package/dest/native/native_world_state.js +80 -27
  15. package/dest/native/native_world_state_instance.d.ts +5 -4
  16. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  17. package/dest/native/native_world_state_instance.js +33 -26
  18. package/dest/native/world_state_ops_queue.js +5 -5
  19. package/dest/synchronizer/config.d.ts +3 -3
  20. package/dest/synchronizer/config.d.ts.map +1 -1
  21. package/dest/synchronizer/config.js +15 -13
  22. package/dest/synchronizer/factory.d.ts +5 -5
  23. package/dest/synchronizer/factory.d.ts.map +1 -1
  24. package/dest/synchronizer/factory.js +7 -6
  25. package/dest/synchronizer/server_world_state_synchronizer.d.ts +4 -4
  26. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  27. package/dest/synchronizer/server_world_state_synchronizer.js +90 -18
  28. package/dest/testing.d.ts +4 -3
  29. package/dest/testing.d.ts.map +1 -1
  30. package/dest/testing.js +10 -6
  31. package/dest/world-state-db/merkle_tree_db.d.ts +1 -10
  32. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  33. package/package.json +12 -11
  34. package/src/native/fork_checkpoint.ts +19 -3
  35. package/src/native/ipc_world_state_instance.ts +717 -0
  36. package/src/native/merkle_trees_facade.ts +41 -16
  37. package/src/native/message.ts +14 -5
  38. package/src/native/native_world_state.ts +98 -34
  39. package/src/native/native_world_state_instance.ts +40 -30
  40. package/src/native/world_state_ops_queue.ts +5 -5
  41. package/src/synchronizer/config.ts +21 -15
  42. package/src/synchronizer/factory.ts +13 -11
  43. package/src/synchronizer/server_world_state_synchronizer.ts +95 -20
  44. package/src/testing.ts +8 -9
  45. package/src/world-state-db/merkle_tree_db.ts +0 -10
@@ -1,5 +1,5 @@
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 { INITIAL_CHECKPOINT_NUMBER } from '@aztec/constants';
2
+ import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import { promiseWithResolvers } from '@aztec/foundation/promise';
5
5
  import { elapsed } from '@aztec/foundation/timer';
@@ -38,7 +38,7 @@ import { WorldStateSynchronizerError } from './errors.js';
38
38
  this.currentState = WorldStateRunningState.IDLE;
39
39
  this.syncPromise = promiseWithResolvers();
40
40
  this.merkleTreeCommitted = this.merkleTreeDb.getCommitted();
41
- this.historyToKeep = config.worldStateBlockHistory < 1 ? undefined : config.worldStateBlockHistory;
41
+ this.historyToKeep = config.worldStateCheckpointHistory < 1 ? undefined : config.worldStateCheckpointHistory;
42
42
  this.log.info(`Created world state synchroniser with block history of ${this.historyToKeep === undefined ? 'infinity' : this.historyToKeep}`);
43
43
  }
44
44
  getCommitted() {
@@ -130,9 +130,9 @@ import { WorldStateSynchronizerError } from './errors.js';
130
130
  /**
131
131
  * Forces an immediate sync.
132
132
  * @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
133
- * @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
133
+ * @param blockHash - If provided, verifies the block at targetBlockNumber matches this hash. On mismatch, triggers a resync (reorg detection).
134
134
  * @returns A promise that resolves with the block number the world state was synced to
135
- */ async syncImmediate(targetBlockNumber, skipThrowIfTargetNotReached) {
135
+ */ async syncImmediate(targetBlockNumber, blockHash) {
136
136
  if (this.currentState !== WorldStateRunningState.RUNNING) {
137
137
  throw new Error(`World State is not running. Unable to perform sync.`);
138
138
  }
@@ -142,7 +142,16 @@ import { WorldStateSynchronizerError } from './errors.js';
142
142
  // If we have been given a block number to sync to and we have reached that number then return
143
143
  const currentBlockNumber = await this.getLatestBlockNumber();
144
144
  if (targetBlockNumber !== undefined && targetBlockNumber <= currentBlockNumber) {
145
- return currentBlockNumber;
145
+ if (blockHash === undefined) {
146
+ return currentBlockNumber;
147
+ }
148
+ // If a block hash was provided, verify we're on the expected fork
149
+ const currentHash = await this.getL2BlockHash(targetBlockNumber);
150
+ if (currentHash === blockHash.toString()) {
151
+ return currentBlockNumber;
152
+ }
153
+ // Hash mismatch: a reorg may have occurred, fall through to trigger sync
154
+ this.log.debug(`World state block hash mismatch at ${targetBlockNumber} (expected ${blockHash}, got ${currentHash}). Triggering resync.`);
146
155
  }
147
156
  this.log.debug(`World State at ${currentBlockNumber} told to sync to ${targetBlockNumber ?? 'latest'}`);
148
157
  // If the archiver is behind the target block, force an archiver sync
@@ -157,7 +166,7 @@ import { WorldStateSynchronizerError } from './errors.js';
157
166
  await this.blockStream.sync();
158
167
  // If we have been given a block number to sync to and we have not reached that number then fail
159
168
  const updatedBlockNumber = await this.getLatestBlockNumber();
160
- if (!skipThrowIfTargetNotReached && targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
169
+ if (targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
161
170
  throw new WorldStateSynchronizerError(`Unable to sync to block number ${targetBlockNumber} (last synced is ${updatedBlockNumber})`, {
162
171
  cause: {
163
172
  reason: 'block_not_available',
@@ -167,6 +176,20 @@ import { WorldStateSynchronizerError } from './errors.js';
167
176
  }
168
177
  });
169
178
  }
179
+ // If a block hash was provided, verify we're on the expected fork after syncing, throw otherwise
180
+ if (blockHash !== undefined && targetBlockNumber !== undefined) {
181
+ const updatedHash = await this.getL2BlockHash(targetBlockNumber);
182
+ if (updatedHash !== blockHash.toString()) {
183
+ throw new WorldStateSynchronizerError(`Block hash mismatch at block ${targetBlockNumber} (expected ${blockHash} but got ${updatedHash})`, {
184
+ cause: {
185
+ reason: 'block_hash_mismatch',
186
+ targetBlockNumber,
187
+ expectedHash: blockHash.toString(),
188
+ actualHash: updatedHash
189
+ }
190
+ });
191
+ }
192
+ }
170
193
  return updatedBlockNumber;
171
194
  }
172
195
  /** Returns the L2 block hash for a given number. Used by the L2BlockStream for detecting reorgs. */ async getL2BlockHash(number) {
@@ -194,15 +217,26 @@ import { WorldStateSynchronizerError } from './errors.js';
194
217
  // but we use a block stream so we need to provide 'local' L2Tips.
195
218
  // We configure the block stream to ignore checkpoints and set checkpoint values to genesis here.
196
219
  const genesisCheckpointHeaderHash = GENESIS_CHECKPOINT_HEADER_HASH.toString();
220
+ const initialBlockHash = (await this.merkleTreeCommitted.getInitialHeader().hash()).toString();
197
221
  return {
198
222
  proposed: latestBlockId,
199
223
  checkpointed: {
200
224
  block: {
201
- number: INITIAL_L2_BLOCK_NUM,
202
- hash: GENESIS_BLOCK_HEADER_HASH.toString()
225
+ number: BlockNumber.ZERO,
226
+ hash: initialBlockHash
227
+ },
228
+ checkpoint: {
229
+ number: INITIAL_CHECKPOINT_NUMBER,
230
+ hash: genesisCheckpointHeaderHash
231
+ }
232
+ },
233
+ proposedCheckpoint: {
234
+ block: {
235
+ number: BlockNumber.ZERO,
236
+ hash: initialBlockHash
203
237
  },
204
238
  checkpoint: {
205
- number: INITIAL_L2_CHECKPOINT_NUM,
239
+ number: INITIAL_CHECKPOINT_NUMBER,
206
240
  hash: genesisCheckpointHeaderHash
207
241
  }
208
242
  },
@@ -212,7 +246,7 @@ import { WorldStateSynchronizerError } from './errors.js';
212
246
  hash: finalizedBlockHash ?? ''
213
247
  },
214
248
  checkpoint: {
215
- number: INITIAL_L2_CHECKPOINT_NUM,
249
+ number: INITIAL_CHECKPOINT_NUMBER,
216
250
  hash: genesisCheckpointHeaderHash
217
251
  }
218
252
  },
@@ -222,7 +256,7 @@ import { WorldStateSynchronizerError } from './errors.js';
222
256
  hash: provenBlockHash ?? ''
223
257
  },
224
258
  checkpoint: {
225
- number: INITIAL_L2_CHECKPOINT_NUM,
259
+ number: INITIAL_CHECKPOINT_NUMBER,
226
260
  hash: genesisCheckpointHeaderHash
227
261
  }
228
262
  }
@@ -296,16 +330,52 @@ import { WorldStateSynchronizerError } from './errors.js';
296
330
  }
297
331
  async handleChainFinalized(blockNumber) {
298
332
  this.log.verbose(`Finalized chain is now at block ${blockNumber}`);
333
+ // If the finalized block number is older than the oldest available block in world state,
334
+ // skip entirely. The finalized block number can jump backwards (e.g. when the finalization
335
+ // heuristic changes) and try to read block data that has already been pruned. When this
336
+ // happens, there is nothing useful to do — the native world state is already finalized
337
+ // past this point and pruning has already happened.
338
+ const currentSummary = await this.merkleTreeDb.getStatusSummary();
339
+ if (blockNumber < currentSummary.oldestHistoricalBlock || blockNumber < 1) {
340
+ this.log.trace(`Finalized block ${blockNumber} is older than the oldest available block ${currentSummary.oldestHistoricalBlock}. Skipping.`);
341
+ return;
342
+ }
299
343
  const summary = await this.merkleTreeDb.setFinalized(blockNumber);
300
344
  if (this.historyToKeep === undefined) {
301
345
  return;
302
346
  }
303
- const newHistoricBlock = summary.finalizedBlockNumber - this.historyToKeep + 1;
304
- if (newHistoricBlock <= 1) {
347
+ const finalisedBlockData = await this.l2BlockSource.getBlockData({
348
+ number: summary.finalizedBlockNumber
349
+ });
350
+ if (finalisedBlockData === undefined) {
351
+ this.log.warn(`Failed to retrieve checkpointed block for finalized block number: ${summary.finalizedBlockNumber}`);
352
+ return;
353
+ }
354
+ // Compute the required historic checkpoint number
355
+ const newHistoricCheckpointNumber = finalisedBlockData.checkpointNumber - this.historyToKeep + 1;
356
+ if (newHistoricCheckpointNumber <= 1) {
357
+ return;
358
+ }
359
+ // Retrieve the historic checkpoint
360
+ const historicCheckpoint = await this.l2BlockSource.getCheckpoint({
361
+ number: CheckpointNumber(newHistoricCheckpointNumber)
362
+ });
363
+ if (!historicCheckpoint) {
364
+ this.log.warn(`Failed to retrieve checkpoint number ${newHistoricCheckpointNumber} from Archiver`);
305
365
  return;
306
366
  }
307
- this.log.verbose(`Pruning historic blocks to ${newHistoricBlock}`);
308
- const status = await this.merkleTreeDb.removeHistoricalBlocks(BlockNumber(newHistoricBlock));
367
+ if (historicCheckpoint.checkpoint.blocks.length === 0 || historicCheckpoint.checkpoint.blocks[0] === undefined) {
368
+ this.log.warn(`Retrieved checkpoint number ${newHistoricCheckpointNumber} has no blocks!`);
369
+ return;
370
+ }
371
+ // Find the block at the start of the checkpoint and remove blocks up to this one
372
+ const newHistoricBlock = historicCheckpoint.checkpoint.blocks[0];
373
+ if (newHistoricBlock.number <= currentSummary.oldestHistoricalBlock) {
374
+ this.log.debug(`Historic block ${newHistoricBlock.number} is not newer than oldest available ${currentSummary.oldestHistoricalBlock}. Skipping prune.`);
375
+ return;
376
+ }
377
+ this.log.verbose(`Pruning historic blocks to ${newHistoricBlock.number}`);
378
+ const status = await this.merkleTreeDb.removeHistoricalBlocks(BlockNumber(newHistoricBlock.number));
309
379
  this.log.debug(`World state summary `, status.summary);
310
380
  }
311
381
  handleChainProven(blockNumber) {
@@ -314,9 +384,11 @@ import { WorldStateSynchronizerError } from './errors.js';
314
384
  return Promise.resolve();
315
385
  }
316
386
  async handleChainPruned(blockNumber) {
317
- this.log.warn(`Chain pruned to block ${blockNumber}`);
387
+ this.log.info(`Chain pruned to block ${blockNumber}`);
318
388
  const status = await this.merkleTreeDb.unwindBlocks(blockNumber);
319
- this.provenBlockNumber = undefined;
389
+ if (this.provenBlockNumber !== undefined && this.provenBlockNumber > blockNumber) {
390
+ this.provenBlockNumber = undefined;
391
+ }
320
392
  this.instrumentation.updateWorldStateMetrics(status);
321
393
  }
322
394
  /**
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFBZ0Isa0JBQWtCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQXlCdkUsZUFBTyxNQUFNLDZCQUE2QixJQUFxQixDQUFDO0FBRWhFLHdCQUFzQixnQkFBZ0IsQ0FDcEMsZUFBZSxFQUFFLFlBQVksRUFBRSxFQUMvQixzQkFBc0IsS0FBZ0MsRUFDdEQsaUJBQWlCLEdBQUUsa0JBQWtCLEVBQU87Ozs7R0FxQjdDIn0=
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3Rlc3RpbmcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBRXBELE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFBZ0Isa0JBQWtCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUN2RSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQXFCN0QsZUFBTyxNQUFNLDZCQUE2QixJQUFxQixDQUFDO0FBRWhFLHdCQUFzQixnQkFBZ0IsQ0FDcEMsZUFBZSxFQUFFLFlBQVksRUFBRSxFQUMvQixzQkFBc0IsS0FBZ0MsRUFDdEQsaUJBQWlCLEdBQUUsa0JBQWtCLEVBQU8sRUFDNUMsZ0JBQWdCLEdBQUUsTUFBVzs7OztHQXNCOUIifQ==
@@ -1 +1 @@
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;AAyBvE,eAAO,MAAM,6BAA6B,IAAqB,CAAC;AAEhE,wBAAsB,gBAAgB,CACpC,eAAe,EAAE,YAAY,EAAE,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;AAqB7D,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,14 @@ 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
12
  // Create a temporary world state to compute the genesis values.
13
- const ws = await NativeWorldStateService.tmp(undefined /* rollupAddress */ , true, prefilledPublicData);
13
+ const ws = await NativeWorldStateService.tmp(undefined /* rollupAddress */ , true, genesis);
14
14
  const genesisArchiveRoot = new Fr((await ws.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
15
15
  await ws.close();
16
16
  return {
@@ -18,16 +18,20 @@ async function generateGenesisValues(prefilledPublicData) {
18
18
  };
19
19
  }
20
20
  export const defaultInitialAccountFeeJuice = new Fr(10n ** 22n);
21
- export async function getGenesisValues(initialAccounts, initialAccountFeeJuice = defaultInitialAccountFeeJuice, genesisPublicData = []) {
21
+ export async function getGenesisValues(initialAccounts, initialAccountFeeJuice = defaultInitialAccountFeeJuice, genesisPublicData = [], genesisTimestamp = 0n) {
22
22
  // Top up the accounts with fee juice.
23
23
  let prefilledPublicData = await Promise.all(initialAccounts.map(async (address)=>new PublicDataTreeLeaf(await computeFeePayerBalanceLeafSlot(address), initialAccountFeeJuice)));
24
24
  // Add user-defined public data
25
25
  prefilledPublicData = prefilledPublicData.concat(genesisPublicData);
26
26
  prefilledPublicData.sort((a, b)=>b.slot.lt(a.slot) ? 1 : -1);
27
- const { genesisArchiveRoot } = await generateGenesisValues(prefilledPublicData);
27
+ const genesis = {
28
+ prefilledPublicData,
29
+ genesisTimestamp
30
+ };
31
+ const { genesisArchiveRoot } = await generateGenesisValues(genesis);
28
32
  return {
29
33
  genesisArchiveRoot,
30
- prefilledPublicData,
34
+ genesis,
31
35
  fundingNeeded: BigInt(initialAccounts.length) * initialAccountFeeJuice.toBigInt()
32
36
  };
33
37
  }
@@ -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
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,13 +20,6 @@ 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).
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVya2xlX3RyZWVfZGIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93b3JsZC1zdGF0ZS1kYi9tZXJrbGVfdHJlZV9kYi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNuRSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxtQkFBbUIsRUFBRSxZQUFZLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUM1RSxPQUFPLEtBQUssRUFBRSxPQUFPLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUNuRCxPQUFPLEtBQUssRUFDVix3QkFBd0IsRUFDeEIsd0JBQXdCLEVBQ3hCLHdCQUF3QixFQUN6QixNQUFNLGlDQUFpQyxDQUFDO0FBQ3pDLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBRXhELE9B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W,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.86469d5",
3
+ "version": "0.0.1-commit.8655d4a",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -64,19 +64,20 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "@aztec/constants": "0.0.1-commit.86469d5",
68
- "@aztec/foundation": "0.0.1-commit.86469d5",
69
- "@aztec/kv-store": "0.0.1-commit.86469d5",
70
- "@aztec/merkle-tree": "0.0.1-commit.86469d5",
71
- "@aztec/native": "0.0.1-commit.86469d5",
72
- "@aztec/protocol-contracts": "0.0.1-commit.86469d5",
73
- "@aztec/stdlib": "0.0.1-commit.86469d5",
74
- "@aztec/telemetry-client": "0.0.1-commit.86469d5",
67
+ "@aztec/bb.js": "0.0.1-commit.8655d4a",
68
+ "@aztec/constants": "0.0.1-commit.8655d4a",
69
+ "@aztec/foundation": "0.0.1-commit.8655d4a",
70
+ "@aztec/kv-store": "0.0.1-commit.8655d4a",
71
+ "@aztec/native": "0.0.1-commit.8655d4a",
72
+ "@aztec/protocol-contracts": "0.0.1-commit.8655d4a",
73
+ "@aztec/stdlib": "0.0.1-commit.8655d4a",
74
+ "@aztec/telemetry-client": "0.0.1-commit.8655d4a",
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.86469d5",
80
+ "@aztec/archiver": "0.0.1-commit.8655d4a",
80
81
  "@jest/globals": "^30.0.0",
81
82
  "@types/jest": "^30.0.0",
82
83
  "@types/node": "^22.15.17",
@@ -3,11 +3,14 @@ import type { MerkleTreeCheckpointOperations } from '@aztec/stdlib/interfaces/se
3
3
  export class ForkCheckpoint {
4
4
  private completed = false;
5
5
 
6
- private constructor(private readonly fork: MerkleTreeCheckpointOperations) {}
6
+ private constructor(
7
+ private readonly fork: MerkleTreeCheckpointOperations,
8
+ public readonly depth: number,
9
+ ) {}
7
10
 
8
11
  static async new(fork: MerkleTreeCheckpointOperations): Promise<ForkCheckpoint> {
9
- await fork.createCheckpoint();
10
- return new ForkCheckpoint(fork);
12
+ const depth = await fork.createCheckpoint();
13
+ return new ForkCheckpoint(fork, depth);
11
14
  }
12
15
 
13
16
  async commit(): Promise<void> {
@@ -27,4 +30,17 @@ export class ForkCheckpoint {
27
30
  await this.fork.revertCheckpoint();
28
31
  this.completed = true;
29
32
  }
33
+
34
+ /**
35
+ * Reverts this checkpoint and any nested checkpoints created on top of it,
36
+ * leaving the checkpoint depth at the level it was before this checkpoint was created.
37
+ */
38
+ async revertToCheckpoint(): Promise<void> {
39
+ if (this.completed) {
40
+ return;
41
+ }
42
+
43
+ await this.fork.revertAllCheckpointsTo(this.depth - 1);
44
+ this.completed = true;
45
+ }
30
46
  }