@aztec/world-state 0.0.0-test.1 → 0.0.1-commit.1142ef1

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 (63) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/instrumentation/instrumentation.d.ts +6 -4
  3. package/dest/instrumentation/instrumentation.d.ts.map +1 -1
  4. package/dest/instrumentation/instrumentation.js +19 -42
  5. package/dest/native/bench_metrics.d.ts +23 -0
  6. package/dest/native/bench_metrics.d.ts.map +1 -0
  7. package/dest/native/bench_metrics.js +81 -0
  8. package/dest/native/fork_checkpoint.d.ts +1 -1
  9. package/dest/native/fork_checkpoint.d.ts.map +1 -1
  10. package/dest/native/index.d.ts +1 -1
  11. package/dest/native/merkle_trees_facade.d.ts +19 -7
  12. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  13. package/dest/native/merkle_trees_facade.js +64 -11
  14. package/dest/native/message.d.ts +72 -51
  15. package/dest/native/message.d.ts.map +1 -1
  16. package/dest/native/message.js +61 -61
  17. package/dest/native/native_world_state.d.ts +28 -20
  18. package/dest/native/native_world_state.d.ts.map +1 -1
  19. package/dest/native/native_world_state.js +97 -36
  20. package/dest/native/native_world_state_instance.d.ts +20 -4
  21. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  22. package/dest/native/native_world_state_instance.js +42 -3
  23. package/dest/native/world_state_ops_queue.d.ts +1 -1
  24. package/dest/native/world_state_ops_queue.d.ts.map +1 -1
  25. package/dest/native/world_state_ops_queue.js +1 -1
  26. package/dest/synchronizer/config.d.ts +12 -2
  27. package/dest/synchronizer/config.d.ts.map +1 -1
  28. package/dest/synchronizer/config.js +26 -1
  29. package/dest/synchronizer/errors.d.ts +4 -0
  30. package/dest/synchronizer/errors.d.ts.map +1 -0
  31. package/dest/synchronizer/errors.js +5 -0
  32. package/dest/synchronizer/factory.d.ts +9 -2
  33. package/dest/synchronizer/factory.d.ts.map +1 -1
  34. package/dest/synchronizer/factory.js +9 -4
  35. package/dest/synchronizer/index.d.ts +1 -1
  36. package/dest/synchronizer/server_world_state_synchronizer.d.ts +21 -30
  37. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  38. package/dest/synchronizer/server_world_state_synchronizer.js +130 -78
  39. package/dest/test/index.d.ts +1 -1
  40. package/dest/test/utils.d.ts +16 -9
  41. package/dest/test/utils.d.ts.map +1 -1
  42. package/dest/test/utils.js +56 -49
  43. package/dest/testing.d.ts +3 -3
  44. package/dest/testing.d.ts.map +1 -1
  45. package/dest/testing.js +7 -11
  46. package/dest/world-state-db/index.d.ts +1 -1
  47. package/dest/world-state-db/merkle_tree_db.d.ts +14 -11
  48. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  49. package/package.json +24 -24
  50. package/src/instrumentation/instrumentation.ts +24 -44
  51. package/src/native/bench_metrics.ts +91 -0
  52. package/src/native/merkle_trees_facade.ts +73 -17
  53. package/src/native/message.ts +92 -73
  54. package/src/native/native_world_state.ts +118 -50
  55. package/src/native/native_world_state_instance.ts +59 -8
  56. package/src/native/world_state_ops_queue.ts +1 -1
  57. package/src/synchronizer/config.ts +47 -2
  58. package/src/synchronizer/errors.ts +5 -0
  59. package/src/synchronizer/factory.ts +31 -8
  60. package/src/synchronizer/server_world_state_synchronizer.ts +160 -105
  61. package/src/test/utils.ts +94 -84
  62. package/src/testing.ts +4 -8
  63. package/src/world-state-db/merkle_tree_db.ts +18 -10
@@ -1,13 +1,14 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- import type { Fr } from '@aztec/foundation/fields';
4
- import type { L2BlockSource, L2BlockStream, L2BlockStreamEvent, L2BlockStreamEventHandler, L2BlockStreamLocalDataProvider, L2Tips } from '@aztec/stdlib/block';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { type Logger } from '@aztec/foundation/log';
3
+ import { type L2BlockSource, L2BlockStream, type L2BlockStreamEvent, type L2BlockStreamEventHandler, type L2BlockStreamLocalDataProvider, type L2Tips } from '@aztec/stdlib/block';
5
4
  import { type WorldStateSynchronizer, type WorldStateSynchronizerStatus } from '@aztec/stdlib/interfaces/server';
6
5
  import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
6
+ import type { SnapshotDataKeys } from '@aztec/stdlib/snapshots';
7
7
  import { type MerkleTreeReadOperations, type MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
8
8
  import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
9
9
  import type { MerkleTreeAdminDatabase } from '../world-state-db/merkle_tree_db.js';
10
10
  import type { WorldStateConfig } from './config.js';
11
+ export type { SnapshotDataKeys };
11
12
  /**
12
13
  * Synchronizes the world state with the L2 blocks from a L2BlockSource via a block stream.
13
14
  * The synchronizer will download the L2 blocks from the L2BlockSource and update the merkle trees.
@@ -26,39 +27,36 @@ export declare class ServerWorldStateSynchronizer implements WorldStateSynchroni
26
27
  private latestBlockHashQuery;
27
28
  private syncPromise;
28
29
  protected blockStream: L2BlockStream | undefined;
29
- constructor(merkleTreeDb: MerkleTreeAdminDatabase, l2BlockSource: L2BlockSource & L1ToL2MessageSource, config: WorldStateConfig, instrumentation?: WorldStateInstrumentation, log?: import("@aztec/foundation/log").Logger);
30
+ private provenBlockNumber;
31
+ constructor(merkleTreeDb: MerkleTreeAdminDatabase, l2BlockSource: L2BlockSource & L1ToL2MessageSource, config: WorldStateConfig, instrumentation?: WorldStateInstrumentation, log?: Logger);
30
32
  getCommitted(): MerkleTreeReadOperations;
31
- getSnapshot(blockNumber: number): MerkleTreeReadOperations;
32
- fork(blockNumber?: number): Promise<MerkleTreeWriteOperations>;
33
+ getSnapshot(blockNumber: BlockNumber): MerkleTreeReadOperations;
34
+ fork(blockNumber?: BlockNumber, opts?: {
35
+ closeDelayMs?: number;
36
+ }): Promise<MerkleTreeWriteOperations>;
37
+ backupTo(dstPath: string, compact?: boolean): Promise<Record<Exclude<SnapshotDataKeys, 'archiver'>, string>>;
38
+ clear(): Promise<void>;
33
39
  start(): Promise<void | import("@aztec/foundation/promise").PromiseWithResolvers<void>>;
34
40
  protected createBlockStream(): L2BlockStream;
35
41
  stop(): Promise<void>;
36
42
  status(): Promise<WorldStateSynchronizerStatus>;
37
- getLatestBlockNumber(): Promise<number>;
43
+ getLatestBlockNumber(): Promise<BlockNumber>;
44
+ stopSync(): Promise<void>;
45
+ resumeSync(): void;
38
46
  /**
39
47
  * Forces an immediate sync.
40
- * @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it. Throws if cannot be reached.
48
+ * @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
49
+ * @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
41
50
  * @returns A promise that resolves with the block number the world state was synced to
42
51
  */
43
- syncImmediate(targetBlockNumber?: number): Promise<number>;
52
+ syncImmediate(targetBlockNumber?: BlockNumber, skipThrowIfTargetNotReached?: boolean): Promise<BlockNumber>;
44
53
  /** Returns the L2 block hash for a given number. Used by the L2BlockStream for detecting reorgs. */
45
- getL2BlockHash(number: number): Promise<string | undefined>;
54
+ getL2BlockHash(number: BlockNumber): Promise<string | undefined>;
46
55
  /** Returns the latest L2 block number for each tip of the chain (latest, proven, finalized). */
47
56
  getL2Tips(): Promise<L2Tips>;
48
57
  /** Handles an event emitted by the block stream. */
49
58
  handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void>;
50
- /**
51
- * Handles a list of L2 blocks (i.e. Inserts the new note hashes into the merkle tree).
52
- * @param l2Blocks - The L2 blocks to handle.
53
- * @returns Whether the block handled was produced by this same node.
54
- */
55
59
  private handleL2Blocks;
56
- /**
57
- * Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
58
- * @param l2Block - The L2 block to handle.
59
- * @param l1ToL2Messages - The L1 to L2 messages for the block.
60
- * @returns Whether the block handled was produced by this same node.
61
- */
62
60
  private handleL2Block;
63
61
  private handleChainFinalized;
64
62
  private handleChainProven;
@@ -68,12 +66,5 @@ export declare class ServerWorldStateSynchronizer implements WorldStateSynchroni
68
66
  * @param newState - New state value.
69
67
  */
70
68
  private setCurrentState;
71
- /**
72
- * Verifies that the L1 to L2 messages hash to the block inHash.
73
- * @param l1ToL2Messages - The L1 to L2 messages for the block.
74
- * @param inHash - The inHash of the block.
75
- * @throws If the L1 to L2 messages do not hash to the block inHash.
76
- */
77
- protected verifyMessagesHashToInHash(l1ToL2Messages: Fr[], inHash: Buffer): Promise<void>;
78
69
  }
79
- //# sourceMappingURL=server_world_state_synchronizer.d.ts.map
70
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VydmVyX3dvcmxkX3N0YXRlX3N5bmNocm9uaXplci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3N5bmNocm9uaXplci9zZXJ2ZXJfd29ybGRfc3RhdGVfc3luY2hyb25pemVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUU5RCxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFHbEUsT0FBTyxFQUlMLEtBQUssYUFBYSxFQUNsQixhQUFhLEVBQ2IsS0FBSyxrQkFBa0IsRUFDdkIsS0FBSyx5QkFBeUIsRUFDOUIsS0FBSyw4QkFBOEIsRUFDbkMsS0FBSyxNQUFNLEVBQ1osTUFBTSxxQkFBcUIsQ0FBQztBQUM3QixPQUFPLEVBR0wsS0FBSyxzQkFBc0IsRUFDM0IsS0FBSyw0QkFBNEIsRUFDbEMsTUFBTSxpQ0FBaUMsQ0FBQztBQUN6QyxPQUFPLEtBQUssRUFBRSxtQkFBbUIsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQ25FLE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLE1BQU0seUJB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UFHLE9BQU8sQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFDLENBYTVFO0lBRUQsZ0dBQWdHO0lBQ25GLFNBQVMsSUFBSSxPQUFPLENBQUMsTUFBTSxDQUFDLENBd0J4QztJQUVELG9EQUFvRDtJQUN2QyxzQkFBc0IsQ0FBQyxLQUFLLEVBQUUsa0JBQWtCLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQWU1RTtZQU9hLGNBQWM7WUF5Q2QsYUFBYTtZQWdCYixvQkFBb0I7SUFlbEMsT0FBTyxDQUFDLGlCQUFpQjtZQU1YLGlCQUFpQjtJQVEvQjs7O09BR0c7SUFDSCxPQUFPLENBQUMsZUFBZTtDQUl4QiJ9
@@ -1 +1 @@
1
- {"version":3,"file":"server_world_state_synchronizer.d.ts","sourceRoot":"","sources":["../../src/synchronizer/server_world_state_synchronizer.ts"],"names":[],"mappings":";;AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAMnD,OAAO,KAAK,EAGV,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,yBAAyB,EACzB,8BAA8B,EAC9B,MAAM,EACP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EAClC,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,OAAO,EAAgB,KAAK,wBAAwB,EAAE,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAGlH,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAElF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;GAIG;AACH,qBAAa,4BACX,YAAW,sBAAsB,EAAE,8BAA8B,EAAE,yBAAyB;IAa1F,OAAO,CAAC,QAAQ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AAoB;IAelC,OAAO,CAAC,iBAAiB;YAKX,iBAAiB;IAO/B;;;OAGG;IACH,OAAO,CAAC,eAAe;IAKvB;;;;;OAKG;cACa,0BAA0B,CAAC,cAAc,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM;CAahF"}
1
+ {"version":3,"file":"server_world_state_synchronizer.d.ts","sourceRoot":"","sources":["../../src/synchronizer/server_world_state_synchronizer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EAIL,KAAK,aAAa,EAClB,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,8BAA8B,EACnC,KAAK,MAAM,EACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EAClC,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAgB,KAAK,wBAAwB,EAAE,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAGlH,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAElF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC;;;;GAIG;AACH,qBAAa,4BACX,YAAW,sBAAsB,EAAE,8BAA8B,EAAE,yBAAyB;IAiB1F,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,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AA2B,CAAC,EAAE,OAAO,GACpC,OAAO,CAAC,WAAW,CAAC,CA6CtB;IAED,oGAAoG;IACvF,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAa5E;IAED,gGAAgG;IACnF,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAwBxC;IAED,oDAAoD;IACvC,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAe5E;YAOa,cAAc;YAyCd,aAAa;YAgBb,oBAAoB;IAelC,OAAO,CAAC,iBAAiB;YAMX,iBAAiB;IAQ/B;;;OAGG;IACH,OAAO,CAAC,eAAe;CAIxB"}
@@ -1,13 +1,14 @@
1
- import { L1_TO_L2_MSG_SUBTREE_HEIGHT } from '@aztec/constants';
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';
2
3
  import { createLogger } from '@aztec/foundation/log';
3
4
  import { promiseWithResolvers } from '@aztec/foundation/promise';
4
5
  import { elapsed } from '@aztec/foundation/timer';
5
- import { MerkleTreeCalculator } from '@aztec/foundation/trees';
6
- import { SHA256Trunc } from '@aztec/merkle-tree';
6
+ import { GENESIS_CHECKPOINT_HEADER_HASH, L2BlockStream } from '@aztec/stdlib/block';
7
7
  import { WorldStateRunningState } from '@aztec/stdlib/interfaces/server';
8
8
  import { MerkleTreeId } from '@aztec/stdlib/trees';
9
- import { TraceableL2BlockStream, getTelemetryClient } from '@aztec/telemetry-client';
9
+ import { getTelemetryClient } from '@aztec/telemetry-client';
10
10
  import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
11
+ import { WorldStateSynchronizerError } from './errors.js';
11
12
  /**
12
13
  * Synchronizes the world state with the L2 blocks from a L2BlockSource via a block stream.
13
14
  * The synchronizer will download the L2 blocks from the L2BlockSource and update the merkle trees.
@@ -25,13 +26,16 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
25
26
  latestBlockHashQuery;
26
27
  syncPromise;
27
28
  blockStream;
29
+ // WorldState doesn't track the proven block number, it only tracks the latest tips of the pending chain and the finalized chain
30
+ // store the proven block number here, in the synchronizer, so that we don't end up spamming the logs with 'chain-proved' events
31
+ provenBlockNumber;
28
32
  constructor(merkleTreeDb, l2BlockSource, config, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), log = createLogger('world_state')){
29
33
  this.merkleTreeDb = merkleTreeDb;
30
34
  this.l2BlockSource = l2BlockSource;
31
35
  this.config = config;
32
36
  this.instrumentation = instrumentation;
33
37
  this.log = log;
34
- this.latestBlockNumberAtStart = 0;
38
+ this.latestBlockNumberAtStart = BlockNumber.ZERO;
35
39
  this.currentState = WorldStateRunningState.IDLE;
36
40
  this.latestBlockHashQuery = undefined;
37
41
  this.syncPromise = promiseWithResolvers();
@@ -45,8 +49,14 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
45
49
  getSnapshot(blockNumber) {
46
50
  return this.merkleTreeDb.getSnapshot(blockNumber);
47
51
  }
48
- fork(blockNumber) {
49
- return this.merkleTreeDb.fork(blockNumber);
52
+ fork(blockNumber, opts) {
53
+ return this.merkleTreeDb.fork(blockNumber, opts);
54
+ }
55
+ backupTo(dstPath, compact) {
56
+ return this.merkleTreeDb.backupTo(dstPath, compact);
57
+ }
58
+ clear() {
59
+ return this.merkleTreeDb.clear();
50
60
  }
51
61
  async start() {
52
62
  if (this.currentState === WorldStateRunningState.STOPPED) {
@@ -56,7 +66,7 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
56
66
  return this.syncPromise;
57
67
  }
58
68
  // Get the current latest block number
59
- this.latestBlockNumberAtStart = await (this.config.worldStateProvenBlocksOnly ? this.l2BlockSource.getProvenBlockNumber() : this.l2BlockSource.getBlockNumber());
69
+ this.latestBlockNumberAtStart = BlockNumber(await (this.config.worldStateProvenBlocksOnly ? this.l2BlockSource.getProvenBlockNumber() : this.l2BlockSource.getBlockNumber()));
60
70
  const blockToDownloadFrom = await this.getLatestBlockNumber() + 1;
61
71
  if (blockToDownloadFrom <= this.latestBlockNumberAtStart) {
62
72
  // If there are blocks to be retrieved, go to a synching state
@@ -74,12 +84,12 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
74
84
  return this.syncPromise.promise;
75
85
  }
76
86
  createBlockStream() {
77
- const tracer = this.instrumentation.telemetry.getTracer('WorldStateL2BlockStream');
78
87
  const logger = createLogger('world-state:block_stream');
79
- return new TraceableL2BlockStream(this.l2BlockSource, this, this, tracer, 'WorldStateL2BlockStream', logger, {
88
+ return new L2BlockStream(this.l2BlockSource, this, this, logger, {
80
89
  proven: this.config.worldStateProvenBlocksOnly,
81
90
  pollIntervalMS: this.config.worldStateBlockCheckIntervalMS,
82
- batchSize: this.config.worldStateBlockRequestBatchSize
91
+ batchSize: this.config.worldStateBlockRequestBatchSize,
92
+ ignoreCheckpoints: true
83
93
  });
84
94
  }
85
95
  async stop() {
@@ -93,10 +103,10 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
93
103
  async status() {
94
104
  const summary = await this.merkleTreeDb.getStatusSummary();
95
105
  const status = {
96
- latestBlockNumber: Number(summary.unfinalisedBlockNumber),
97
- latestBlockHash: await this.getL2BlockHash(Number(summary.unfinalisedBlockNumber)) ?? '',
98
- finalisedBlockNumber: Number(summary.finalisedBlockNumber),
99
- oldestHistoricBlockNumber: Number(summary.oldestHistoricalBlock),
106
+ latestBlockNumber: summary.unfinalizedBlockNumber,
107
+ latestBlockHash: await this.getL2BlockHash(summary.unfinalizedBlockNumber) ?? '',
108
+ finalizedBlockNumber: summary.finalizedBlockNumber,
109
+ oldestHistoricBlockNumber: summary.oldestHistoricalBlock,
100
110
  treesAreSynched: summary.treesAreSynched
101
111
  };
102
112
  return {
@@ -105,33 +115,65 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
105
115
  };
106
116
  }
107
117
  async getLatestBlockNumber() {
108
- return (await this.getL2Tips()).latest.number;
118
+ return (await this.getL2Tips()).proposed.number;
119
+ }
120
+ async stopSync() {
121
+ this.log.debug('Stopping sync...');
122
+ await this.blockStream?.stop();
123
+ this.log.info('Stopped sync');
124
+ }
125
+ resumeSync() {
126
+ if (!this.blockStream) {
127
+ throw new Error('Cannot resume sync as block stream is not initialized');
128
+ }
129
+ this.log.debug('Resuming sync...');
130
+ this.blockStream.start();
131
+ this.log.info('Resumed sync');
109
132
  }
110
133
  /**
111
134
  * Forces an immediate sync.
112
- * @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it. Throws if cannot be reached.
135
+ * @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
136
+ * @param skipThrowIfTargetNotReached - Whether to skip throwing if the target block number is not reached.
113
137
  * @returns A promise that resolves with the block number the world state was synced to
114
- */ async syncImmediate(targetBlockNumber) {
115
- if (this.currentState !== WorldStateRunningState.RUNNING || this.blockStream === undefined) {
138
+ */ async syncImmediate(targetBlockNumber, skipThrowIfTargetNotReached) {
139
+ if (this.currentState !== WorldStateRunningState.RUNNING) {
116
140
  throw new Error(`World State is not running. Unable to perform sync.`);
117
141
  }
142
+ if (this.blockStream === undefined) {
143
+ throw new Error('Block stream is not initialized. Unable to perform sync.');
144
+ }
118
145
  // If we have been given a block number to sync to and we have reached that number then return
119
146
  const currentBlockNumber = await this.getLatestBlockNumber();
120
147
  if (targetBlockNumber !== undefined && targetBlockNumber <= currentBlockNumber) {
121
148
  return currentBlockNumber;
122
149
  }
123
150
  this.log.debug(`World State at ${currentBlockNumber} told to sync to ${targetBlockNumber ?? 'latest'}`);
151
+ // If the archiver is behind the target block, force an archiver sync
152
+ if (targetBlockNumber) {
153
+ const archiverLatestBlock = BlockNumber(await this.l2BlockSource.getBlockNumber());
154
+ if (archiverLatestBlock < targetBlockNumber) {
155
+ this.log.debug(`Archiver is at ${archiverLatestBlock} behind target block ${targetBlockNumber}.`);
156
+ await this.l2BlockSource.syncImmediate();
157
+ }
158
+ }
124
159
  // Force the block stream to sync against the archiver now
125
160
  await this.blockStream.sync();
126
161
  // If we have been given a block number to sync to and we have not reached that number then fail
127
162
  const updatedBlockNumber = await this.getLatestBlockNumber();
128
- if (targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
129
- throw new Error(`Unable to sync to block number ${targetBlockNumber} (last synced is ${updatedBlockNumber})`);
163
+ if (!skipThrowIfTargetNotReached && targetBlockNumber !== undefined && targetBlockNumber > updatedBlockNumber) {
164
+ throw new WorldStateSynchronizerError(`Unable to sync to block number ${targetBlockNumber} (last synced is ${updatedBlockNumber})`, {
165
+ cause: {
166
+ reason: 'block_not_available',
167
+ previousBlockNumber: currentBlockNumber,
168
+ updatedBlockNumber,
169
+ targetBlockNumber
170
+ }
171
+ });
130
172
  }
131
173
  return updatedBlockNumber;
132
174
  }
133
175
  /** Returns the L2 block hash for a given number. Used by the L2BlockStream for detecting reorgs. */ async getL2BlockHash(number) {
134
- if (number === 0) {
176
+ if (number === BlockNumber.ZERO) {
135
177
  return (await this.merkleTreeCommitted.getInitialHeader().hash()).toString();
136
178
  }
137
179
  if (this.latestBlockHashQuery?.hash === undefined || number !== this.latestBlockHashQuery.blockNumber) {
@@ -144,41 +186,63 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
144
186
  }
145
187
  /** Returns the latest L2 block number for each tip of the chain (latest, proven, finalized). */ async getL2Tips() {
146
188
  const status = await this.merkleTreeDb.getStatusSummary();
147
- const unfinalisedBlockHash = await this.getL2BlockHash(Number(status.unfinalisedBlockNumber));
189
+ const unfinalizedBlockHash = await this.getL2BlockHash(status.unfinalizedBlockNumber);
148
190
  const latestBlockId = {
149
- number: Number(status.unfinalisedBlockNumber),
150
- hash: unfinalisedBlockHash
191
+ number: status.unfinalizedBlockNumber,
192
+ hash: unfinalizedBlockHash
151
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();
152
198
  return {
153
- latest: latestBlockId,
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
+ }
209
+ },
154
210
  finalized: {
155
- number: Number(status.finalisedBlockNumber),
156
- hash: ''
211
+ block: {
212
+ number: status.finalizedBlockNumber,
213
+ hash: ''
214
+ },
215
+ checkpoint: {
216
+ number: INITIAL_L2_CHECKPOINT_NUM,
217
+ hash: genesisCheckpointHeaderHash
218
+ }
157
219
  },
158
220
  proven: {
159
- number: Number(status.finalisedBlockNumber),
160
- hash: ''
221
+ block: {
222
+ number: this.provenBlockNumber ?? status.finalizedBlockNumber,
223
+ hash: ''
224
+ },
225
+ checkpoint: {
226
+ number: INITIAL_L2_CHECKPOINT_NUM,
227
+ hash: genesisCheckpointHeaderHash
228
+ }
161
229
  }
162
230
  };
163
231
  }
164
232
  /** Handles an event emitted by the block stream. */ async handleBlockStreamEvent(event) {
165
- try {
166
- switch(event.type){
167
- case 'blocks-added':
168
- await this.handleL2Blocks(event.blocks);
169
- break;
170
- case 'chain-pruned':
171
- await this.handleChainPruned(event.blockNumber);
172
- break;
173
- case 'chain-proven':
174
- await this.handleChainProven(event.blockNumber);
175
- break;
176
- case 'chain-finalized':
177
- await this.handleChainFinalized(event.blockNumber);
178
- break;
179
- }
180
- } catch (err) {
181
- this.log.error('Error processing block stream', err);
233
+ switch(event.type){
234
+ case 'blocks-added':
235
+ await this.handleL2Blocks(event.blocks);
236
+ break;
237
+ case 'chain-pruned':
238
+ await this.handleChainPruned(event.block.number);
239
+ break;
240
+ case 'chain-proven':
241
+ await this.handleChainProven(event.block.number);
242
+ break;
243
+ case 'chain-finalized':
244
+ await this.handleChainFinalized(event.block.number);
245
+ break;
182
246
  }
183
247
  }
184
248
  /**
@@ -187,18 +251,22 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
187
251
  * @returns Whether the block handled was produced by this same node.
188
252
  */ async handleL2Blocks(l2Blocks) {
189
253
  this.log.trace(`Handling L2 blocks ${l2Blocks[0].number} to ${l2Blocks.at(-1).number}`);
190
- const messagePromises = l2Blocks.map((block)=>this.l2BlockSource.getL1ToL2Messages(BigInt(block.number)));
191
- const l1ToL2Messages = await Promise.all(messagePromises);
254
+ // Fetch the L1->L2 messages for the first block in a checkpoint.
255
+ const messagesForBlocks = new Map();
256
+ await Promise.all(l2Blocks.filter((b)=>b.indexWithinCheckpoint === 0).map(async (block)=>{
257
+ const l1ToL2Messages = await this.l2BlockSource.getL1ToL2Messages(block.checkpointNumber);
258
+ messagesForBlocks.set(block.number, l1ToL2Messages);
259
+ }));
192
260
  let updateStatus = undefined;
193
- for(let i = 0; i < l2Blocks.length; i++){
194
- const [duration, result] = await elapsed(()=>this.handleL2Block(l2Blocks[i], l1ToL2Messages[i]));
195
- this.log.verbose(`World state updated with L2 block ${l2Blocks[i].number}`, {
261
+ for (const block of l2Blocks){
262
+ const [duration, result] = await elapsed(()=>this.handleL2Block(block, messagesForBlocks.get(block.number) ?? []));
263
+ this.log.info(`World state updated with L2 block ${block.number}`, {
196
264
  eventName: 'l2-block-handled',
197
265
  duration,
198
- unfinalisedBlockNumber: result.summary.unfinalisedBlockNumber,
199
- finalisedBlockNumber: result.summary.finalisedBlockNumber,
200
- oldestHistoricBlock: result.summary.oldestHistoricalBlock,
201
- ...l2Blocks[i].getStats()
266
+ unfinalizedBlockNumber: BigInt(result.summary.unfinalizedBlockNumber),
267
+ finalizedBlockNumber: BigInt(result.summary.finalizedBlockNumber),
268
+ oldestHistoricBlock: BigInt(result.summary.oldestHistoricalBlock),
269
+ ...block.getStats()
202
270
  });
203
271
  updateStatus = result;
204
272
  }
@@ -213,12 +281,6 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
213
281
  * @param l1ToL2Messages - The L1 to L2 messages for the block.
214
282
  * @returns Whether the block handled was produced by this same node.
215
283
  */ async handleL2Block(l2Block, l1ToL2Messages) {
216
- // First we check that the L1 to L2 messages hash to the block inHash.
217
- // Note that we cannot optimize this check by checking the root of the subtree after inserting the messages
218
- // to the real L1_TO_L2_MESSAGE_TREE (like we do in merkleTreeDb.handleL2BlockAndMessages(...)) because that
219
- // tree uses pedersen and we don't have access to the converted root.
220
- await this.verifyMessagesHashToInHash(l1ToL2Messages, l2Block.header.contentCommitment.inHash);
221
- // If the above check succeeds, we can proceed to handle the block.
222
284
  this.log.trace(`Pushing L2 block ${l2Block.number} to merkle tree db `, {
223
285
  blockNumber: l2Block.number,
224
286
  blockHash: await l2Block.hash().then((h)=>h.toString()),
@@ -233,26 +295,28 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
233
295
  }
234
296
  async handleChainFinalized(blockNumber) {
235
297
  this.log.verbose(`Finalized chain is now at block ${blockNumber}`);
236
- const summary = await this.merkleTreeDb.setFinalised(BigInt(blockNumber));
298
+ const summary = await this.merkleTreeDb.setFinalized(blockNumber);
237
299
  if (this.historyToKeep === undefined) {
238
300
  return;
239
301
  }
240
- const newHistoricBlock = summary.finalisedBlockNumber - BigInt(this.historyToKeep) + 1n;
302
+ const newHistoricBlock = summary.finalizedBlockNumber - this.historyToKeep + 1;
241
303
  if (newHistoricBlock <= 1) {
242
304
  return;
243
305
  }
244
306
  this.log.verbose(`Pruning historic blocks to ${newHistoricBlock}`);
245
- const status = await this.merkleTreeDb.removeHistoricalBlocks(newHistoricBlock);
307
+ const status = await this.merkleTreeDb.removeHistoricalBlocks(BlockNumber(newHistoricBlock));
246
308
  this.log.debug(`World state summary `, status.summary);
247
309
  }
248
310
  handleChainProven(blockNumber) {
311
+ this.provenBlockNumber = blockNumber;
249
312
  this.log.debug(`Proven chain is now at block ${blockNumber}`);
250
313
  return Promise.resolve();
251
314
  }
252
315
  async handleChainPruned(blockNumber) {
253
316
  this.log.warn(`Chain pruned to block ${blockNumber}`);
254
- const status = await this.merkleTreeDb.unwindBlocks(BigInt(blockNumber));
317
+ const status = await this.merkleTreeDb.unwindBlocks(blockNumber);
255
318
  this.latestBlockHashQuery = undefined;
319
+ this.provenBlockNumber = undefined;
256
320
  this.instrumentation.updateWorldStateMetrics(status);
257
321
  }
258
322
  /**
@@ -262,16 +326,4 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
262
326
  this.currentState = newState;
263
327
  this.log.debug(`Moved to state ${WorldStateRunningState[this.currentState]}`);
264
328
  }
265
- /**
266
- * Verifies that the L1 to L2 messages hash to the block inHash.
267
- * @param l1ToL2Messages - The L1 to L2 messages for the block.
268
- * @param inHash - The inHash of the block.
269
- * @throws If the L1 to L2 messages do not hash to the block inHash.
270
- */ async verifyMessagesHashToInHash(l1ToL2Messages, inHash) {
271
- const treeCalculator = await MerkleTreeCalculator.create(L1_TO_L2_MSG_SUBTREE_HEIGHT, Buffer.alloc(32), (lhs, rhs)=>Promise.resolve(new SHA256Trunc().hash(lhs, rhs)));
272
- const root = await treeCalculator.computeTreeRoot(l1ToL2Messages.map((msg)=>msg.toBuffer()));
273
- if (!root.equals(inHash)) {
274
- throw new Error('Obtained L1 to L2 messages failed to be hashed to the block inHash');
275
- }
276
- }
277
329
  }
@@ -1,2 +1,2 @@
1
1
  export * from './utils.js';
2
- //# sourceMappingURL=index.d.ts.map
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsWUFBWSxDQUFDIn0=
@@ -1,19 +1,26 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { L2Block } from '@aztec/stdlib/block';
1
+ import { BlockNumber, type CheckpointNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { L2BlockNew } from '@aztec/stdlib/block';
3
4
  import type { MerkleTreeReadOperations, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
5
+ import { mockCheckpointAndMessages } from '@aztec/stdlib/testing';
4
6
  import type { NativeWorldStateService } from '../native/native_world_state.js';
5
- export declare function mockBlock(blockNum: number, size: number, fork: MerkleTreeWriteOperations): Promise<{
6
- block: L2Block;
7
+ export declare function updateBlockState(block: L2BlockNew, l1ToL2Messages: Fr[], fork: MerkleTreeWriteOperations): Promise<void>;
8
+ export declare function mockBlock(blockNum: BlockNumber, size: number, fork: MerkleTreeWriteOperations, maxEffects?: number | undefined, numL1ToL2Messages?: number, isFirstBlockInCheckpoint?: boolean): Promise<{
9
+ block: L2BlockNew;
7
10
  messages: Fr[];
8
11
  }>;
9
- export declare function mockEmptyBlock(blockNum: number, fork: MerkleTreeWriteOperations): Promise<{
10
- block: L2Block;
12
+ export declare function mockEmptyBlock(blockNum: BlockNumber, fork: MerkleTreeWriteOperations): Promise<{
13
+ block: L2BlockNew;
11
14
  messages: Fr[];
12
15
  }>;
13
- export declare function mockBlocks(from: number, count: number, numTxs: number, worldState: NativeWorldStateService): Promise<{
14
- blocks: L2Block[];
16
+ export declare function mockBlocks(from: BlockNumber, count: number, numTxs: number, worldState: NativeWorldStateService): Promise<{
17
+ blocks: L2BlockNew[];
15
18
  messages: Fr[][];
16
19
  }>;
20
+ export declare function mockCheckpoint(checkpointNumber: CheckpointNumber, fork: MerkleTreeWriteOperations, options?: Partial<Parameters<typeof mockCheckpointAndMessages>[1]>): Promise<{
21
+ checkpoint: import("../../../stdlib/dest/checkpoint/checkpoint.js").Checkpoint;
22
+ messages: Fr[];
23
+ }>;
17
24
  export declare function assertSameState(forkA: MerkleTreeReadOperations, forkB: MerkleTreeReadOperations): Promise<void>;
18
25
  export declare function compareChains(left: MerkleTreeReadOperations, right: MerkleTreeReadOperations): Promise<void>;
19
- //# sourceMappingURL=utils.d.ts.map
26
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU9BLE9BQU8sRUFBRSxXQUFXLEVBQUUsS0FBSyxnQkFBZ0IsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRXJGLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUNwRCxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDakQsT0FBTyxLQUFLLEVBRVYsd0JBQXdCLEVBQ3hCLHlCQUF5QixFQUMxQixNQUFNLGlDQUFpQyxDQUFDO0FBQ3pDLE9BQU8sRUFBRSx5QkFBeUIsRUFBc0IsTUFBTSx1QkFBdUIsQ0FBQztBQUl0RixPQUFPLEtBQUssRUFBRSx1QkFBdUIsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRS9FLHdCQUFzQixnQkFBZ0IsQ0FBQyxLQUFLLEVBQUUsVUFBVSxFQUFFLGNBQWMsRUFBRSxFQUFFLEVBQUUsRUFBRSxJQUFJLEVBQUUseUJBQXlCLGlCQThDOUc7QUFFRCx3QkFBc0IsU0FBUyxDQUM3QixRQUFRLEVBQUUsV0FBVyxFQUNyQixJQUFJLEVBQUUsTUFBTSxFQUNaLElBQUksRUFBRSx5QkFBeUIsRUFDL0IsVUFBVSxHQUFFLE1BQU0sR0FBRyxTQUFnQixFQUNyQyxpQkFBaUIsR0FBRSxNQUE0QyxFQUMvRCx3QkFBd0IsR0FBRSxPQUFjOzs7R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